feat: api.php 호출에서 path를 경로로 지정하는 방식 추가
This commit is contained in:
@@ -9,4 +9,4 @@ if (!class_exists('\\sammo\\RootDB')) {
|
|||||||
Json::dieWithReason('No DB');
|
Json::dieWithReason('No DB');
|
||||||
}
|
}
|
||||||
|
|
||||||
APIHelper::launch(dirname(__FILE__));
|
APIHelper::launch(dirname(__FILE__), $_GET['path']??null);
|
||||||
+1
-1
@@ -5,4 +5,4 @@ namespace sammo;
|
|||||||
include "lib.php";
|
include "lib.php";
|
||||||
include "func.php";
|
include "func.php";
|
||||||
|
|
||||||
APIHelper::launch(dirname(__FILE__));
|
APIHelper::launch(dirname(__FILE__), $_GET['path']??null);
|
||||||
@@ -16,13 +16,10 @@ export async function callSammoAPI<ResultType extends ValidResponse, ErrorType e
|
|||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios({
|
const response = await axios({
|
||||||
url: "api.php",
|
url: `api.php?path=${path}`,
|
||||||
method: "post",
|
method: "post",
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
data: {
|
data: args
|
||||||
path,
|
|
||||||
args,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const result: ErrorType | ResultType = response.data;
|
const result: ErrorType | ResultType = response.data;
|
||||||
if (!result.result) {
|
if (!result.result) {
|
||||||
|
|||||||
+25
-10
@@ -9,7 +9,7 @@ class APIHelper
|
|||||||
//static only
|
//static only
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function launch(string $rootPath)
|
public static function launch(string $rootPath, ?string $actionPath = null)
|
||||||
{
|
{
|
||||||
//TODO: path를 php://input에서 받는게 아니라 api.php?~~~~~ 로 받아오는것이 etag 캐시 측면에서 훨씬 나을 듯!
|
//TODO: path를 php://input에서 받는게 아니라 api.php?~~~~~ 로 받아오는것이 etag 캐시 측면에서 훨씬 나을 듯!
|
||||||
try {
|
try {
|
||||||
@@ -19,20 +19,35 @@ class APIHelper
|
|||||||
Json::dieWithReason($e->getMessage());
|
Json::dieWithReason($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$input){
|
if($actionPath !== null){
|
||||||
Json::dieWithReason("input이 비어있습니다. {$rawInput}");
|
if ($input && !is_array($input)) {
|
||||||
|
Json::dieWithReason('args가 array가 아닙니다.' . gettype($input));
|
||||||
|
}
|
||||||
|
if(!$input){
|
||||||
|
$input = [];
|
||||||
|
}
|
||||||
|
$actionArgs = $input;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(!$input){
|
||||||
|
Json::dieWithReason("input이 비어있습니다. {$rawInput}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!key_exists('path', $input)) {
|
||||||
|
Json::dieWithReason('path가 지정되지 않았습니다.');
|
||||||
|
}
|
||||||
|
$actionPath = $input['path'];
|
||||||
|
|
||||||
|
if (key_exists('args', $input) && !is_array($input['args'])) {
|
||||||
|
Json::dieWithReason('args가 array가 아닙니다.' . gettype($input['args']));
|
||||||
|
}
|
||||||
|
$actionArgs = $input['args'] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!key_exists('path', $input)) {
|
|
||||||
Json::dieWithReason('path가 지정되지 않았습니다.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key_exists('args', $input) && !is_array($input['args'])) {
|
|
||||||
Json::dieWithReason('args가 array가 아닙니다.' . gettype($input['args']));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$obj = buildAPIExecutorClass($input['path'], $rootPath, $input['args'] ?? []);
|
$obj = buildAPIExecutorClass($actionPath, $rootPath, $actionArgs);
|
||||||
$validateResult = $obj->validateArgs();
|
$validateResult = $obj->validateArgs();
|
||||||
if ($validateResult !== null) {
|
if ($validateResult !== null) {
|
||||||
Json::dieWithReason($validateResult);
|
Json::dieWithReason($validateResult);
|
||||||
|
|||||||
Reference in New Issue
Block a user