Files
core/hwe/ts/SammoAPI.ts
T
Hide_D 5eaafaeee6 fix: NPC 빙의 장수 목록 안보이는 버그 수정
- API/Global/GeneralList를 WithToken과 분리
2022-04-20 22:33:46 +09:00

136 lines
4.7 KiB
TypeScript

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, StrVar } from "./util/APIPathGen.js";
import type { BettingDetailResponse, BettingListResponse } from "./defs/API/Betting";
import type { ReserveBulkCommandResponse, ReserveCommandResponse, ReservedCommandResponse } from "./defs/API/Command";
import type { ChiefResponse } from "./defs/API/NationCommand";
import type { inheritBuffType } from "./defs/API/InheritAction";
import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListResponse } from "./defs/API/Nation";
import type { UploadImageResponse } from "./defs/API/Misc";
import type { JoinArgs } from "./defs/API/General";
import type { GetConstResponse, GetCurrentHistoryResponse, GetHistoryResponse } from "./defs/API/Global";
import type { GeneralListResponse } from "./defs";
const apiRealPath = {
Betting: {
Bet: PUT as APICallT<{
bettingID: number,
bettingType: number[],
amount: number,
}>,
GetBettingDetail: NumVar('betting_id',
GET as APICallT<undefined, BettingDetailResponse>
),
GetBettingList: GET as APICallT<undefined, BettingListResponse>,
},
Command: {
GetReservedCommand: GET as APICallT<undefined, ReservedCommandResponse>,
PushCommand: PUT as APICallT<{
amount: number
}>,
RepeatCommand: PUT as APICallT<{
amount: number
}>,
ReserveCommand: PUT as APICallT<{
turnList: number[],
action: string,
arg?: Args
}, ReserveCommandResponse>,
ReserveBulkCommand: PUT as APICallT<{
turnList: number[],
action: string,
arg?: Args
}[], ReserveBulkCommandResponse>,
},
General: {
Join: POST as APICallT<JoinArgs>,
},
Global: {
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
GeneralListWithToken: GET as APICallT<undefined, GeneralListResponse>,
GetConst: GET as APICallT<undefined, GetConstResponse>,
GetHistory: StrVar('serverID')(
NumVar('year',
NumVar('month', GET as APICallT<undefined, GetHistoryResponse>
))),
GetCurrentHistory: GET as APICallT<undefined, GetCurrentHistoryResponse>
},
InheritAction: {
BuyHiddenBuff: PUT as APICallT<{
type: inheritBuffType,
level: number
}>,
BuyRandomUnique: PUT as APICallT<undefined>,
BuySpecificUnique: PUT as APICallT<{
item: string,
amount: number,
}>,
ResetSpecialWar: PUT as APICallT<undefined>,
ResetTurnTime: PUT as APICallT<undefined>,
SetNextSpecialWar: PUT as APICallT<{
type: string,
}>,
},
Misc: {
UploadImage: POST as APICallT<{
imageData: string,
}, UploadImageResponse>
},
NationCommand: {
GetReservedCommand: GET as APICallT<undefined, ChiefResponse>,
PushCommand: PUT as APICallT<{
amount: number
}>,
RepeatCommand: PUT as APICallT<{
amount: number
}>,
ReserveCommand: PUT as APICallT<{
turnList: number[],
action: string,
arg?: Args
}, ReserveCommandResponse>,
ReserveBulkCommand: PUT as APICallT<{
turnList: number[],
action: string,
arg?: Args
}[], ReserveBulkCommandResponse>,
},
Nation: {
GeneralList: GET as APICallT<undefined, NationGeneralListResponse>,
SetNotice: PUT as APICallT<{
msg: string,
}>,
SetScoutMsg: PUT as APICallT<{
msg: string,
}>,
SetBill: PATCH as APICallT<{
amount: number,
}>,
SetRate: PATCH as APICallT<{
amount: number,
}>,
SetSecretLimit: PATCH as APICallT<{
amount: number,
}>,
SetBlockWar: PATCH as APICallT<{
value: boolean,
}, SetBlockWarResponse>,
SetBlockScout: PATCH as APICallT<{
value: boolean,
}>,
},
} 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);
};
});