86 lines
2.0 KiB
TypeScript
86 lines
2.0 KiB
TypeScript
import type {
|
|
PuzzleAgentSessionSnapshot,
|
|
} from '../../../packages/shared/src/contracts/puzzleAgentSession';
|
|
import type {
|
|
PuzzleGalleryResponse,
|
|
PuzzleWorksResponse,
|
|
PuzzleWorkSummary,
|
|
} from '../../../packages/shared/src/contracts/puzzleWorkSummary';
|
|
import { type ApiRetryOptions, requestJson } from '../apiClient';
|
|
|
|
const PUZZLE_GALLERY_API_BASE = '/api/runtime/puzzle/gallery';
|
|
const PUZZLE_GALLERY_READ_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
};
|
|
|
|
/**
|
|
* 读取拼图广场列表。
|
|
*/
|
|
export async function listPuzzleGallery() {
|
|
return requestJson<PuzzleGalleryResponse>(
|
|
PUZZLE_GALLERY_API_BASE,
|
|
{
|
|
method: 'GET',
|
|
},
|
|
'读取拼图广场失败',
|
|
{
|
|
retry: PUZZLE_GALLERY_READ_RETRY,
|
|
skipAuth: true,
|
|
skipRefresh: true,
|
|
},
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 读取拼图广场详情。
|
|
*/
|
|
export async function getPuzzleGalleryDetail(profileId: string) {
|
|
return requestJson<{ item: PuzzleWorkSummary }>(
|
|
`${PUZZLE_GALLERY_API_BASE}/${encodeURIComponent(profileId)}`,
|
|
{
|
|
method: 'GET',
|
|
},
|
|
'读取拼图广场详情失败',
|
|
{
|
|
retry: PUZZLE_GALLERY_READ_RETRY,
|
|
skipAuth: true,
|
|
skipRefresh: true,
|
|
},
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 点赞公开拼图作品,后端按当前登录用户做幂等计数。
|
|
*/
|
|
export async function likePuzzleGalleryWork(profileId: string) {
|
|
return requestJson<{ item: PuzzleWorkSummary }>(
|
|
`${PUZZLE_GALLERY_API_BASE}/${encodeURIComponent(profileId)}/like`,
|
|
{
|
|
method: 'POST',
|
|
},
|
|
'点赞拼图作品失败',
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 将公开拼图作品复制为当前用户的草稿。
|
|
*/
|
|
export async function remixPuzzleGalleryWork(profileId: string) {
|
|
return requestJson<{ session: PuzzleAgentSessionSnapshot }>(
|
|
`${PUZZLE_GALLERY_API_BASE}/${encodeURIComponent(profileId)}/remix`,
|
|
{
|
|
method: 'POST',
|
|
},
|
|
'Remix 拼图作品失败',
|
|
);
|
|
}
|
|
|
|
export const puzzleGalleryClient = {
|
|
getDetail: getPuzzleGalleryDetail,
|
|
like: likePuzzleGalleryWork,
|
|
list: listPuzzleGallery,
|
|
remix: remixPuzzleGalleryWork,
|
|
};
|