Files
core/hwe/ts/SammoAPI.ts
T
Hide_D 5879661267 refac, feat: API 호출 구조 재작성
- api.php에서 param path 강제
- api.php에서 GET param 허용
- SammoAPI 호출자를 axios에서 fetch 기반(ky)로 변경
- SammoAPI에서 단순 POST대신 REST에 따라 지정 가능하도록 재구성
- SammoAPI에서 NumVar, StrVar를 PathParam으로 변경하도록 변경
- API CallType들을 def/API로 분리 시작
  - 일부 API를 시험삼아 변경(login)
2022-04-02 23:31:05 +09:00

71 lines
2.2 KiB
TypeScript

import type { BettingDetailResponse, ReserveBulkCommandResponse } from "./defs";
import type { Args } from "./processing/args";
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, NumVar } from "./util/APIPathGen.js";
const apiRealPath = {
Betting: {
Bet: PUT,
GetBettingDetail: NumVar('betting_id',
GET as APICallT<undefined, BettingDetailResponse>
),
GetBettingList: GET,
},
Command: {
GetReservedCommand: GET as APICallT<undefined>,
PushCommand: PATCH,
RepeatCommand: PATCH,
ReserveCommand: PUT,
ReserveBulkCommand: PUT as APICallT<{
turnList: number[],
action: string,
arg: Args
}[], ReserveBulkCommandResponse>,
},
General: {
Join: POST,
},
InheritAction: {
BuyHiddenBuff: PUT,
BuyRandomUnique: PUT,
BuySpecificUnique: PUT,
ResetSpecialWar: PUT,
ResetTurnTime: PUT,
SetNextSpecialWar: PUT,
},
Misc: { UploadImage: POST },
NationCommand: {
GetReservedCommand: GET,
PushCommand: PATCH,
RepeatCommand: PATCH,
ReserveCommand: PUT,
ReserveBulkCommand: PUT as APICallT<{
turnList: number[],
action: string,
arg: Args
}[], ReserveBulkCommandResponse>,
},
Nation: {
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[], tail: APITail, pathParam) => {
const method = extractHttpMethod(tail);
return (args?: RawArgType, returnError?: boolean) => {
if (returnError) {
return callSammoAPI(method, path.join('/'), args, pathParam, true);
}
return callSammoAPI(method, path.join('/'), args, pathParam);
};
});