Files
Genarrative/src/services/customWorldCoverAssetService.ts
kdletters cbc27bad4a
Some checks failed
CI / verify (push) Has been cancelled
init with react+axum+spacetimedb
2026-04-26 18:06:23 +08:00

59 lines
1.5 KiB
TypeScript

import { requestJson } from './apiClient';
import type { CustomWorldCoverCropRect, CustomWorldProfile } from '../types';
const CUSTOM_WORLD_COVER_API_BASE = '/api/runtime/custom-world';
export interface CustomWorldCoverAssetResult {
imageSrc: string;
assetId: string;
sourceType: 'uploaded' | 'generated';
model?: string;
size?: string;
taskId?: string;
prompt?: string;
actualPrompt?: string;
}
export interface GenerateCustomWorldCoverImageRequest {
profile: CustomWorldProfile;
userPrompt?: string;
referenceImageSrc?: string;
characterRoleIds?: string[];
size?: string;
}
export interface UploadCustomWorldCoverImageRequest {
profileId: string;
worldName: string;
imageDataUrl: string;
cropRect: CustomWorldCoverCropRect;
}
export async function generateCustomWorldCoverImage(
payload: GenerateCustomWorldCoverImageRequest,
) {
return requestJson<CustomWorldCoverAssetResult>(
`${CUSTOM_WORLD_COVER_API_BASE}/cover-image`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
},
'生成作品封面失败',
);
}
export async function uploadCustomWorldCoverImage(
payload: UploadCustomWorldCoverImageRequest,
) {
return requestJson<CustomWorldCoverAssetResult>(
`${CUSTOM_WORLD_COVER_API_BASE}/cover-upload`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
},
'上传作品封面失败',
);
}