- Route recommended runtime launches through shared runtime guest token handling - Extend recommend-page anonymous play beyond jump-hop - Add regression coverage for runtime guest launch clients - Update docs to reflect the full anonymous-play matrix
102 lines
2.7 KiB
TypeScript
102 lines
2.7 KiB
TypeScript
import type {
|
|
BigFishRunResponse,
|
|
RecordBigFishPlayRequest,
|
|
SubmitBigFishInputRequest,
|
|
} from '../../../packages/shared/src/contracts/bigFish';
|
|
import type { BigFishWorksResponse } from '../../../packages/shared/src/contracts/bigFishWorkSummary';
|
|
import {
|
|
type ApiRetryOptions,
|
|
requestJson,
|
|
} from '../apiClient';
|
|
import {
|
|
buildRuntimeGuestAuthOptions,
|
|
buildRuntimeGuestHeaders,
|
|
type RuntimeGuestRequestOptions,
|
|
} from '../runtimeGuestAuth';
|
|
|
|
const BIG_FISH_RUNTIME_WRITE_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
retryUnsafeMethods: true,
|
|
};
|
|
type BigFishRuntimeRequestOptions = RuntimeGuestRequestOptions;
|
|
|
|
/**
|
|
* 上报大鱼吃小鱼正式游玩。elapsedMs 为 0 时仅标记玩过作品。
|
|
*/
|
|
export function recordBigFishPlay(
|
|
sessionId: string,
|
|
payload: RecordBigFishPlayRequest,
|
|
options: BigFishRuntimeRequestOptions = {},
|
|
) {
|
|
const requestOptions = buildRuntimeGuestAuthOptions(options);
|
|
return requestJson<BigFishWorksResponse>(
|
|
`/api/runtime/big-fish/sessions/${encodeURIComponent(sessionId)}/play`,
|
|
{
|
|
method: 'POST',
|
|
headers: buildRuntimeGuestHeaders(options, {
|
|
'Content-Type': 'application/json',
|
|
}),
|
|
body: JSON.stringify(payload),
|
|
},
|
|
'记录大鱼吃小鱼游玩失败',
|
|
{
|
|
retry: BIG_FISH_RUNTIME_WRITE_RETRY,
|
|
...requestOptions,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function startBigFishRun(
|
|
sessionId: string,
|
|
options: BigFishRuntimeRequestOptions = {},
|
|
) {
|
|
const requestOptions = buildRuntimeGuestAuthOptions(options);
|
|
return requestJson<BigFishRunResponse>(
|
|
`/api/runtime/big-fish/sessions/${encodeURIComponent(sessionId)}/runs`,
|
|
{
|
|
method: 'POST',
|
|
headers: buildRuntimeGuestHeaders(options),
|
|
},
|
|
'启动大鱼吃小鱼玩法失败',
|
|
{
|
|
retry: BIG_FISH_RUNTIME_WRITE_RETRY,
|
|
...requestOptions,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function getBigFishRun(runId: string) {
|
|
return requestJson<BigFishRunResponse>(
|
|
`/api/runtime/big-fish/runs/${encodeURIComponent(runId)}`,
|
|
{
|
|
method: 'GET',
|
|
},
|
|
'读取大鱼吃小鱼玩法失败',
|
|
);
|
|
}
|
|
|
|
export function submitBigFishInput(
|
|
runId: string,
|
|
payload: SubmitBigFishInputRequest,
|
|
options: BigFishRuntimeRequestOptions = {},
|
|
) {
|
|
const requestOptions = buildRuntimeGuestAuthOptions(options);
|
|
return requestJson<BigFishRunResponse>(
|
|
`/api/runtime/big-fish/runs/${encodeURIComponent(runId)}/input`,
|
|
{
|
|
method: 'POST',
|
|
headers: buildRuntimeGuestHeaders(options, {
|
|
'Content-Type': 'application/json',
|
|
}),
|
|
body: JSON.stringify(payload),
|
|
},
|
|
'同步大鱼吃小鱼输入失败',
|
|
{
|
|
retry: BIG_FISH_RUNTIME_WRITE_RETRY,
|
|
...requestOptions,
|
|
},
|
|
);
|
|
}
|