57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import type { BigFishSessionResponse } from '../../../packages/shared/src/contracts/bigFish';
|
|
import type { BigFishWorksResponse } from '../../../packages/shared/src/contracts/bigFishWorkSummary';
|
|
import { ApiClientError, type ApiRetryOptions, requestJson } from '../apiClient';
|
|
|
|
const BIG_FISH_GALLERY_API_BASE = '/api/runtime/big-fish/gallery';
|
|
const BIG_FISH_GALLERY_READ_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 120,
|
|
maxDelayMs: 360,
|
|
};
|
|
|
|
/**
|
|
* 读取大鱼吃小鱼公开广场列表。
|
|
*/
|
|
export async function listBigFishGallery() {
|
|
try {
|
|
return await requestJson<BigFishWorksResponse>(
|
|
BIG_FISH_GALLERY_API_BASE,
|
|
{
|
|
method: 'GET',
|
|
},
|
|
'读取大鱼吃小鱼广场失败',
|
|
{
|
|
retry: BIG_FISH_GALLERY_READ_RETRY,
|
|
skipAuth: true,
|
|
skipRefresh: true,
|
|
},
|
|
);
|
|
} catch (error) {
|
|
if (
|
|
error instanceof ApiClientError &&
|
|
(error.status === 400 || error.status === 404)
|
|
) {
|
|
return { items: [] };
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 将公开大鱼吃小鱼作品复制为当前用户草稿。
|
|
*/
|
|
export async function remixBigFishGalleryWork(sessionId: string) {
|
|
return requestJson<BigFishSessionResponse>(
|
|
`${BIG_FISH_GALLERY_API_BASE}/${encodeURIComponent(sessionId)}/remix`,
|
|
{
|
|
method: 'POST',
|
|
},
|
|
'Remix 大鱼吃小鱼作品失败',
|
|
);
|
|
}
|
|
|
|
export const bigFishGalleryClient = {
|
|
list: listBigFishGallery,
|
|
remix: remixBigFishGalleryWork,
|
|
};
|