1
This commit is contained in:
72
src/services/hyper3dModelGenerationService.ts
Normal file
72
src/services/hyper3dModelGenerationService.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import type {
|
||||
Hyper3dDownloadRequest,
|
||||
Hyper3dDownloadResponse,
|
||||
Hyper3dImageToModelRequest,
|
||||
Hyper3dTaskStatusRequest,
|
||||
Hyper3dTaskStatusResponse,
|
||||
Hyper3dTaskSubmitResponse,
|
||||
Hyper3dTextToModelRequest,
|
||||
} from '../../packages/shared/src/contracts/hyper3d';
|
||||
|
||||
import { requestJson } from './apiClient';
|
||||
|
||||
const HYPER3D_API_BASE = '/api/assets/hyper3d';
|
||||
const GENERATION_REQUEST_TIMEOUT_MS = 180_000;
|
||||
|
||||
function postHyper3dJson<TResponse>(
|
||||
path: string,
|
||||
payload: unknown,
|
||||
fallbackMessage: string,
|
||||
timeoutMs = GENERATION_REQUEST_TIMEOUT_MS,
|
||||
) {
|
||||
return requestJson<TResponse>(
|
||||
`${HYPER3D_API_BASE}${path}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
fallbackMessage,
|
||||
{
|
||||
timeoutMs,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function submitHyper3dTextToModel(
|
||||
payload: Hyper3dTextToModelRequest,
|
||||
) {
|
||||
return postHyper3dJson<Hyper3dTaskSubmitResponse>(
|
||||
'/text-to-model',
|
||||
payload,
|
||||
'提交文生 3D 模型任务失败',
|
||||
);
|
||||
}
|
||||
|
||||
export function submitHyper3dImageToModel(
|
||||
payload: Hyper3dImageToModelRequest,
|
||||
) {
|
||||
return postHyper3dJson<Hyper3dTaskSubmitResponse>(
|
||||
'/image-to-model',
|
||||
payload,
|
||||
'提交图生 3D 模型任务失败',
|
||||
);
|
||||
}
|
||||
|
||||
export function getHyper3dTaskStatus(payload: Hyper3dTaskStatusRequest) {
|
||||
return postHyper3dJson<Hyper3dTaskStatusResponse>(
|
||||
'/status',
|
||||
payload,
|
||||
'查询 3D 模型任务状态失败',
|
||||
60_000,
|
||||
);
|
||||
}
|
||||
|
||||
export function getHyper3dDownloads(payload: Hyper3dDownloadRequest) {
|
||||
return postHyper3dJson<Hyper3dDownloadResponse>(
|
||||
'/download',
|
||||
payload,
|
||||
'获取 3D 模型下载列表失败',
|
||||
60_000,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user