From 587966126786407ce5aaade2650123418c29bcac Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 2 Apr 2022 23:31:05 +0900 Subject: [PATCH] =?UTF-8?q?refac,=20feat:=20API=20=ED=98=B8=EC=B6=9C=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EC=9E=AC=EC=9E=91=EC=84=B1=20-=20api.php?= =?UTF-8?q?=EC=97=90=EC=84=9C=20param=20path=20=EA=B0=95=EC=A0=9C=20-=20ap?= =?UTF-8?q?i.php=EC=97=90=EC=84=9C=20GET=20param=20=ED=97=88=EC=9A=A9=20-?= =?UTF-8?q?=20SammoAPI=20=ED=98=B8=EC=B6=9C=EC=9E=90=EB=A5=BC=20axios?= =?UTF-8?q?=EC=97=90=EC=84=9C=20fetch=20=EA=B8=B0=EB=B0=98(ky)=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20-=20SammoAPI=EC=97=90=EC=84=9C=20=EB=8B=A8?= =?UTF-8?q?=EC=88=9C=20POST=EB=8C=80=EC=8B=A0=20REST=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20=EC=A7=80=EC=A0=95=20=EA=B0=80=EB=8A=A5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=9E=AC=EA=B5=AC=EC=84=B1=20-=20SammoAPI?= =?UTF-8?q?=EC=97=90=EC=84=9C=20NumVar,=20StrVar=EB=A5=BC=20PathParam?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20-=20API=20CallType=EB=93=A4?= =?UTF-8?q?=EC=9D=84=20def/API=EB=A1=9C=20=EB=B6=84=EB=A6=AC=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91=20=20=20-=20=EC=9D=BC=EB=B6=80=20API=EB=A5=BC=20?= =?UTF-8?q?=EC=8B=9C=ED=97=98=EC=82=BC=EC=95=84=20=EB=B3=80=EA=B2=BD(login?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.php | 6 +- hwe/api.php | 7 +- hwe/ts/SammoAPI.ts | 74 +++++++++--------- hwe/ts/SammoRootAPI.ts | 24 +++--- hwe/ts/components/BettingDetail.vue | 16 +--- hwe/ts/defs/API/Login.ts | 40 ++++++++++ hwe/ts/{defs.ts => defs/index.ts} | 21 ++++-- hwe/ts/gateway/login.ts | 47 +----------- hwe/ts/util/APIPathGen.d.ts | 14 ++-- hwe/ts/util/APIPathGen.js | 23 ++++-- hwe/ts/util/callSammoAPI.ts | 112 ++++++++++++++++++++++------ package-lock.json | 17 +++++ package.json | 1 + src/sammo/APIHelper.php | 52 ++++++------- 14 files changed, 282 insertions(+), 172 deletions(-) create mode 100644 hwe/ts/defs/API/Login.ts rename hwe/ts/{defs.ts => defs/index.ts} (93%) 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 @@