86 lines
2.0 KiB
TypeScript
86 lines
2.0 KiB
TypeScript
import type {
|
|
PuzzleWorkDetailResponse,
|
|
PuzzleWorkMutationResponse,
|
|
PuzzleWorksResponse,
|
|
} from '../../../packages/shared/src/contracts/puzzleWorkSummary';
|
|
import { type ApiRetryOptions, requestJson } from '../apiClient';
|
|
|
|
const PUZZLE_WORKS_API_BASE = '/api/runtime/puzzle/works';
|
|
const PUZZLE_WORKS_READ_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
};
|
|
const PUZZLE_WORKS_WRITE_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
retryUnsafeMethods: true,
|
|
};
|
|
|
|
/**
|
|
* 读取当前用户的拼图作品列表。
|
|
*/
|
|
export async function listPuzzleWorks() {
|
|
return requestJson<PuzzleWorksResponse>(
|
|
PUZZLE_WORKS_API_BASE,
|
|
{
|
|
method: 'GET',
|
|
},
|
|
'读取拼图作品列表失败',
|
|
{
|
|
retry: PUZZLE_WORKS_READ_RETRY,
|
|
},
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 读取拼图作品详情。
|
|
*/
|
|
export async function getPuzzleWorkDetail(profileId: string) {
|
|
return requestJson<PuzzleWorkDetailResponse>(
|
|
`${PUZZLE_WORKS_API_BASE}/${encodeURIComponent(profileId)}`,
|
|
{
|
|
method: 'GET',
|
|
},
|
|
'读取拼图作品详情失败',
|
|
{
|
|
retry: PUZZLE_WORKS_READ_RETRY,
|
|
},
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 更新已发布或草稿态拼图作品的轻量字段。
|
|
* 只覆盖结果页约定的标题、摘要、标签与正式图。
|
|
*/
|
|
export async function updatePuzzleWork(
|
|
profileId: string,
|
|
payload: {
|
|
levelName: string;
|
|
summary: string;
|
|
themeTags: string[];
|
|
coverImageSrc?: string | null;
|
|
coverAssetId?: string | null;
|
|
},
|
|
) {
|
|
return requestJson<PuzzleWorkMutationResponse>(
|
|
`${PUZZLE_WORKS_API_BASE}/${encodeURIComponent(profileId)}`,
|
|
{
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload),
|
|
},
|
|
'更新拼图作品失败',
|
|
{
|
|
retry: PUZZLE_WORKS_WRITE_RETRY,
|
|
},
|
|
);
|
|
}
|
|
|
|
export const puzzleWorksClient = {
|
|
getDetail: getPuzzleWorkDetail,
|
|
list: listPuzzleWorks,
|
|
update: updatePuzzleWork,
|
|
};
|