122 lines
3.3 KiB
TypeScript
122 lines
3.3 KiB
TypeScript
import type {
|
|
BarkBattleFinishResponse,
|
|
BarkBattleRunFinishRequest,
|
|
BarkBattleRunStartRequest,
|
|
BarkBattleRunStartResponse,
|
|
BarkBattleRuntimeConfig,
|
|
} from '../../../packages/shared/src/contracts/barkBattle';
|
|
import {
|
|
type ApiRequestOptions,
|
|
type ApiRetryOptions,
|
|
requestJson,
|
|
} from '../apiClient';
|
|
|
|
const BARK_BATTLE_RUNTIME_READ_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
};
|
|
|
|
const BARK_BATTLE_RUNTIME_WRITE_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
retryUnsafeMethods: true,
|
|
};
|
|
|
|
export type BarkBattleRuntimeRequestOptions = Pick<
|
|
ApiRequestOptions,
|
|
| 'authImpact'
|
|
| 'skipRefresh'
|
|
| 'notifyAuthStateChange'
|
|
| 'clearAuthOnUnauthorized'
|
|
>;
|
|
|
|
export function getBarkBattleRuntimeConfig(
|
|
workId: string,
|
|
options: BarkBattleRuntimeRequestOptions = {},
|
|
) {
|
|
return requestJson<BarkBattleRuntimeConfig>(
|
|
`/api/runtime/bark-battle/works/${encodeURIComponent(workId)}/config`,
|
|
{ method: 'GET' },
|
|
'读取汪汪声浪大作战配置失败',
|
|
{
|
|
retry: BARK_BATTLE_RUNTIME_READ_RETRY,
|
|
authImpact: options.authImpact,
|
|
skipRefresh: options.skipRefresh,
|
|
notifyAuthStateChange: options.notifyAuthStateChange,
|
|
clearAuthOnUnauthorized: options.clearAuthOnUnauthorized,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function startBarkBattleRun(
|
|
workId: string,
|
|
payload: Partial<BarkBattleRunStartRequest> = {},
|
|
options: BarkBattleRuntimeRequestOptions = {},
|
|
) {
|
|
return requestJson<BarkBattleRunStartResponse>(
|
|
`/api/runtime/bark-battle/works/${encodeURIComponent(workId)}/runs`,
|
|
{
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
...payload,
|
|
workId: payload.workId ?? workId,
|
|
}),
|
|
},
|
|
'启动汪汪声浪大作战正式局失败',
|
|
{
|
|
retry: BARK_BATTLE_RUNTIME_WRITE_RETRY,
|
|
authImpact: options.authImpact,
|
|
skipRefresh: options.skipRefresh,
|
|
notifyAuthStateChange: options.notifyAuthStateChange,
|
|
clearAuthOnUnauthorized: options.clearAuthOnUnauthorized,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function getBarkBattleRun(
|
|
runId: string,
|
|
options: BarkBattleRuntimeRequestOptions = {},
|
|
) {
|
|
return requestJson<unknown>(
|
|
`/api/runtime/bark-battle/runs/${encodeURIComponent(runId)}`,
|
|
{ method: 'GET' },
|
|
'读取汪汪声浪大作战单局失败',
|
|
{
|
|
retry: BARK_BATTLE_RUNTIME_READ_RETRY,
|
|
authImpact: options.authImpact,
|
|
skipRefresh: options.skipRefresh,
|
|
notifyAuthStateChange: options.notifyAuthStateChange,
|
|
clearAuthOnUnauthorized: options.clearAuthOnUnauthorized,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function finishBarkBattleRun(
|
|
runId: string,
|
|
payload: BarkBattleRunFinishRequest,
|
|
options: BarkBattleRuntimeRequestOptions = {},
|
|
) {
|
|
return requestJson<BarkBattleFinishResponse>(
|
|
`/api/runtime/bark-battle/runs/${encodeURIComponent(runId)}/finish`,
|
|
{
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
...payload,
|
|
runId: payload.runId ?? runId,
|
|
}),
|
|
},
|
|
'提交汪汪声浪大作战成绩失败',
|
|
{
|
|
retry: BARK_BATTLE_RUNTIME_WRITE_RETRY,
|
|
authImpact: options.authImpact,
|
|
skipRefresh: options.skipRefresh,
|
|
notifyAuthStateChange: options.notifyAuthStateChange,
|
|
clearAuthOnUnauthorized: options.clearAuthOnUnauthorized,
|
|
},
|
|
);
|
|
}
|