This commit is contained in:
113
src/services/match3d-works/match3dWorksClient.ts
Normal file
113
src/services/match3d-works/match3dWorksClient.ts
Normal file
@@ -0,0 +1,113 @@
|
||||
import type {
|
||||
Match3DWorkDetailResponse,
|
||||
Match3DWorkMutationResponse,
|
||||
Match3DWorksResponse,
|
||||
PutMatch3DWorkRequest,
|
||||
} from '../../../packages/shared/src/contracts/match3dWorks';
|
||||
import { type ApiRetryOptions, requestJson } from '../apiClient';
|
||||
|
||||
const MATCH3D_WORKS_API_BASE = '/api/creation/match3d/works';
|
||||
const MATCH3D_GALLERY_API_BASE = '/api/runtime/match3d/gallery';
|
||||
const MATCH3D_WORKS_READ_RETRY: ApiRetryOptions = {
|
||||
maxRetries: 1,
|
||||
baseDelayMs: 120,
|
||||
maxDelayMs: 360,
|
||||
};
|
||||
const MATCH3D_WORKS_WRITE_RETRY: ApiRetryOptions = {
|
||||
maxRetries: 1,
|
||||
baseDelayMs: 120,
|
||||
maxDelayMs: 360,
|
||||
retryUnsafeMethods: true,
|
||||
};
|
||||
|
||||
/**
|
||||
* 读取当前用户的抓大鹅作品列表。
|
||||
*/
|
||||
export function listMatch3DWorks() {
|
||||
return requestJson<Match3DWorksResponse>(
|
||||
MATCH3D_WORKS_API_BASE,
|
||||
{ method: 'GET' },
|
||||
'读取抓大鹅作品列表失败',
|
||||
{ retry: MATCH3D_WORKS_READ_RETRY },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取公开抓大鹅作品列表。
|
||||
*/
|
||||
export function listMatch3DGallery() {
|
||||
return requestJson<Match3DWorksResponse>(
|
||||
MATCH3D_GALLERY_API_BASE,
|
||||
{ method: 'GET' },
|
||||
'读取抓大鹅广场失败',
|
||||
{
|
||||
retry: MATCH3D_WORKS_READ_RETRY,
|
||||
skipAuth: true,
|
||||
skipRefresh: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取抓大鹅作品详情。
|
||||
*/
|
||||
export function getMatch3DWorkDetail(profileId: string) {
|
||||
return requestJson<Match3DWorkDetailResponse>(
|
||||
`${MATCH3D_WORKS_API_BASE}/${encodeURIComponent(profileId)}`,
|
||||
{ method: 'GET' },
|
||||
'读取抓大鹅作品详情失败',
|
||||
{ retry: MATCH3D_WORKS_READ_RETRY },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存结果页可编辑字段。
|
||||
*/
|
||||
export function updateMatch3DWork(
|
||||
profileId: string,
|
||||
payload: PutMatch3DWorkRequest,
|
||||
) {
|
||||
return requestJson<Match3DWorkMutationResponse>(
|
||||
`${MATCH3D_WORKS_API_BASE}/${encodeURIComponent(profileId)}`,
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
'更新抓大鹅作品失败',
|
||||
{ retry: MATCH3D_WORKS_WRITE_RETRY },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布抓大鹅作品。发布门槛由后端最终确认。
|
||||
*/
|
||||
export function publishMatch3DWork(profileId: string) {
|
||||
return requestJson<Match3DWorkMutationResponse>(
|
||||
`${MATCH3D_WORKS_API_BASE}/${encodeURIComponent(profileId)}/publish`,
|
||||
{ method: 'POST' },
|
||||
'发布抓大鹅作品失败',
|
||||
{ retry: MATCH3D_WORKS_WRITE_RETRY },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除当前用户的抓大鹅作品,并返回删除后的列表。
|
||||
*/
|
||||
export function deleteMatch3DWork(profileId: string) {
|
||||
return requestJson<Match3DWorksResponse>(
|
||||
`${MATCH3D_WORKS_API_BASE}/${encodeURIComponent(profileId)}`,
|
||||
{ method: 'DELETE' },
|
||||
'删除抓大鹅作品失败',
|
||||
{ retry: MATCH3D_WORKS_WRITE_RETRY },
|
||||
);
|
||||
}
|
||||
|
||||
export const match3dWorksClient = {
|
||||
delete: deleteMatch3DWork,
|
||||
getDetail: getMatch3DWorkDetail,
|
||||
listGallery: listMatch3DGallery,
|
||||
list: listMatch3DWorks,
|
||||
publish: publishMatch3DWork,
|
||||
update: updateMatch3DWork,
|
||||
};
|
||||
Reference in New Issue
Block a user