diff --git a/api.php b/api.php index 9b9ef3b7..fa77ac9a 100644 --- a/api.php +++ b/api.php @@ -8,5 +8,9 @@ require(__DIR__ . '/vendor/autoload.php'); if (!class_exists('\\sammo\\RootDB')) { Json::dieWithReason('No DB'); } +$eParams = $_GET; +if(key_exists('path', $eParams)){ + unset($eParams['path']); +} -APIHelper::launch(dirname(__FILE__), $_GET['path']??null); \ No newline at end of file +APIHelper::launch(dirname(__FILE__), $_GET['path']??'', $eParams, true); \ No newline at end of file diff --git a/hwe/api.php b/hwe/api.php index 7f91b80a..8410876c 100644 --- a/hwe/api.php +++ b/hwe/api.php @@ -5,4 +5,9 @@ namespace sammo; include "lib.php"; include "func.php"; -APIHelper::launch(dirname(__FILE__), $_GET['path']??null); \ No newline at end of file +$eParams = $_GET; +if(key_exists('path', $eParams)){ + unset($eParams['path']); +} + +APIHelper::launch(dirname(__FILE__), $_GET['path']??'', $eParams, true); \ No newline at end of file diff --git a/hwe/ts/SammoAPI.ts b/hwe/ts/SammoAPI.ts index b14eda74..e607952c 100644 --- a/hwe/ts/SammoAPI.ts +++ b/hwe/ts/SammoAPI.ts @@ -1,65 +1,71 @@ -import type { InvalidResponse, ReserveBulkCommandResponse } from "./defs"; +import type { BettingDetailResponse, ReserveBulkCommandResponse } from "./defs"; import type { Args } from "./processing/args"; -import { callSammoAPI, done, type CallbackT, type RawArgType, type ValidResponse } from "./util/callSammoAPI"; +import { callSammoAPI, extractHttpMethod, GET, PATCH, POST, PUT, type APITail, type APICallT, type RawArgType, type ValidResponse, type InvalidResponse } from "./util/callSammoAPI"; export type { ValidResponse, InvalidResponse }; -import { APIPathGen } from "./util/APIPathGen.js"; +import { APIPathGen, NumVar } from "./util/APIPathGen.js"; const apiRealPath = { Betting: { - Bet: done, - GetBettingDetail: done, - GetBettingList: done, + Bet: PUT, + GetBettingDetail: NumVar('betting_id', + GET as APICallT + ), + GetBettingList: GET, }, Command: { - GetReservedCommand: done, - PushCommand: done, - RepeatCommand: done, - ReserveCommand: done, - ReserveBulkCommand: done as CallbackT<{ + GetReservedCommand: GET as APICallT, + PushCommand: PATCH, + RepeatCommand: PATCH, + ReserveCommand: PUT, + ReserveBulkCommand: PUT as APICallT<{ turnList: number[], action: string, arg: Args }[], ReserveBulkCommandResponse>, }, General: { - Join: done, + Join: POST, }, InheritAction: { - BuyHiddenBuff: done, - BuyRandomUnique: done, - BuySpecificUnique: done, - ResetSpecialWar: done, - ResetTurnTime: done, - SetNextSpecialWar: done, + BuyHiddenBuff: PUT, + BuyRandomUnique: PUT, + BuySpecificUnique: PUT, + ResetSpecialWar: PUT, + ResetTurnTime: PUT, + SetNextSpecialWar: PUT, }, - Misc: { UploadImage: done }, + Misc: { UploadImage: POST }, NationCommand: { - GetReservedCommand: done, - PushCommand: done, - RepeatCommand: done, - ReserveCommand: done, - ReserveBulkCommand: done as CallbackT<{ + GetReservedCommand: GET, + PushCommand: PATCH, + RepeatCommand: PATCH, + ReserveCommand: PUT, + ReserveBulkCommand: PUT as APICallT<{ turnList: number[], action: string, arg: Args }[], ReserveBulkCommandResponse>, }, Nation: { - SetNotice: done, - SetScoutMsg: done, - SetBill: done, - SetRate: done, - SetSecretLimit: done, - SetBlockWar: done, - SetBlockScout: done, + SetNotice: PUT, + SetScoutMsg: PUT, + SetBill: PUT, + SetRate: PUT, + SetSecretLimit: PUT, + SetBlockWar: PUT, + SetBlockScout: PUT, }, + Test: NumVar('id', { + SetThis: PUT, + }) } as const; -export const SammoAPI = APIPathGen(apiRealPath, (path: string[]) => { +export const SammoAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => { + const method = extractHttpMethod(tail); return (args?: RawArgType, returnError?: boolean) => { if (returnError) { - return callSammoAPI(path.join('/'), args, true); + return callSammoAPI(method, path.join('/'), args, pathParam, true); } - return callSammoAPI(path.join('/'), args); + return callSammoAPI(method, path.join('/'), args, pathParam); }; }); \ No newline at end of file diff --git a/hwe/ts/SammoRootAPI.ts b/hwe/ts/SammoRootAPI.ts index 4d5db970..000296f2 100644 --- a/hwe/ts/SammoRootAPI.ts +++ b/hwe/ts/SammoRootAPI.ts @@ -1,21 +1,25 @@ -import type { InvalidResponse } from "./defs"; +import type { AutoLoginFailed, AutoLoginNonceResponse, AutoLoginResponse } from "./defs/API/Login"; import { APIPathGen } from "./util/APIPathGen"; -import { callSammoAPI, done, type ValidResponse } from "./util/callSammoAPI"; +import { callSammoAPI, extractHttpMethod, GET, POST, type APICallT, type APITail, type InvalidResponse, type RawArgType, type ValidResponse } from "./util/callSammoAPI"; export type { ValidResponse, InvalidResponse }; const apiRealPath = { Login: { - LoginByID: done, - LoginByToken: done, - ReqNonce: done, + LoginByID: POST, + LoginByToken: POST as APICallT<{ + hashedToken: string, + token_id: number, + }, AutoLoginResponse, AutoLoginFailed>, + ReqNonce: GET as APICallT }, } as const; -export const SammoRootAPI = APIPathGen(apiRealPath, (path: string[]) => { - return (args?: Record, returnError?: boolean) => { +export const SammoRootAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => { + const method = extractHttpMethod(tail); + return (args?: RawArgType, returnError?: boolean) => { if (returnError) { - return callSammoAPI(path.join('/'), args, true); + return callSammoAPI(method, path.join('/'), args, pathParam, true); } - return callSammoAPI(path.join('/'), args); + return callSammoAPI(method, path.join('/'), args, pathParam); }; -}) as typeof apiRealPath; \ No newline at end of file +}); \ No newline at end of file diff --git a/hwe/ts/components/BettingDetail.vue b/hwe/ts/components/BettingDetail.vue index 8ea27d92..3af21fe8 100644 --- a/hwe/ts/components/BettingDetail.vue +++ b/hwe/ts/components/BettingDetail.vue @@ -129,21 +129,13 @@