108 lines
2.8 KiB
TypeScript
108 lines
2.8 KiB
TypeScript
import type {
|
|
UpdateVisualNovelWorkRequest,
|
|
VisualNovelWorkResponse,
|
|
VisualNovelWorksResponse,
|
|
} from '../../../packages/shared/src/contracts/visualNovel';
|
|
import {
|
|
type ApiRequestOptions,
|
|
type ApiRetryOptions,
|
|
requestJson,
|
|
} from '../apiClient';
|
|
|
|
const VISUAL_NOVEL_WORKS_API_BASE = '/api/creation/visual-novel/works';
|
|
const VISUAL_NOVEL_WORKS_READ_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 160,
|
|
maxDelayMs: 420,
|
|
};
|
|
const VISUAL_NOVEL_WORKS_WRITE_RETRY: ApiRetryOptions = {
|
|
maxRetries: 1,
|
|
baseDelayMs: 220,
|
|
maxDelayMs: 620,
|
|
retryUnsafeMethods: true,
|
|
};
|
|
type VisualNovelWorksRequestOptions = Pick<
|
|
ApiRequestOptions,
|
|
| 'authImpact'
|
|
| 'skipRefresh'
|
|
| 'notifyAuthStateChange'
|
|
| 'clearAuthOnUnauthorized'
|
|
>;
|
|
|
|
export function listVisualNovelWorks() {
|
|
return requestJson<VisualNovelWorksResponse>(
|
|
VISUAL_NOVEL_WORKS_API_BASE,
|
|
{ method: 'GET' },
|
|
'读取视觉小说作品列表失败',
|
|
{
|
|
retry: VISUAL_NOVEL_WORKS_READ_RETRY,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function getVisualNovelWorkDetail(
|
|
profileId: string,
|
|
options: VisualNovelWorksRequestOptions = {},
|
|
) {
|
|
return requestJson<VisualNovelWorkResponse>(
|
|
`${VISUAL_NOVEL_WORKS_API_BASE}/${encodeURIComponent(profileId)}`,
|
|
{ method: 'GET' },
|
|
'读取视觉小说作品详情失败',
|
|
{
|
|
retry: VISUAL_NOVEL_WORKS_READ_RETRY,
|
|
authImpact: options.authImpact,
|
|
skipRefresh: options.skipRefresh,
|
|
notifyAuthStateChange: options.notifyAuthStateChange,
|
|
clearAuthOnUnauthorized: options.clearAuthOnUnauthorized,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function updateVisualNovelWork(
|
|
profileId: string,
|
|
payload: UpdateVisualNovelWorkRequest,
|
|
) {
|
|
return requestJson<VisualNovelWorkResponse>(
|
|
`${VISUAL_NOVEL_WORKS_API_BASE}/${encodeURIComponent(profileId)}`,
|
|
{
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload),
|
|
},
|
|
'更新视觉小说作品失败',
|
|
{
|
|
retry: VISUAL_NOVEL_WORKS_WRITE_RETRY,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function deleteVisualNovelWork(profileId: string) {
|
|
return requestJson<VisualNovelWorksResponse>(
|
|
`${VISUAL_NOVEL_WORKS_API_BASE}/${encodeURIComponent(profileId)}`,
|
|
{ method: 'DELETE' },
|
|
'删除视觉小说作品失败',
|
|
{
|
|
retry: VISUAL_NOVEL_WORKS_WRITE_RETRY,
|
|
},
|
|
);
|
|
}
|
|
|
|
export function publishVisualNovelWork(profileId: string) {
|
|
return requestJson<VisualNovelWorkResponse>(
|
|
`${VISUAL_NOVEL_WORKS_API_BASE}/${encodeURIComponent(profileId)}/publish`,
|
|
{ method: 'POST' },
|
|
'发布视觉小说作品失败',
|
|
{
|
|
retry: VISUAL_NOVEL_WORKS_WRITE_RETRY,
|
|
},
|
|
);
|
|
}
|
|
|
|
export const visualNovelWorksClient = {
|
|
delete: deleteVisualNovelWork,
|
|
getDetail: getVisualNovelWorkDetail,
|
|
list: listVisualNovelWorks,
|
|
publish: publishVisualNovelWork,
|
|
update: updateVisualNovelWork,
|
|
};
|