上传素材管控-历史素材success
This commit is contained in:
+169
-12
@@ -116,20 +116,30 @@ export async function optimizePrompt(
|
||||
});
|
||||
}
|
||||
|
||||
export async function uploadAudio(file: File): Promise<{ url: string; filename: string }> {
|
||||
export interface UploadResourceResult {
|
||||
url: string;
|
||||
filename: string;
|
||||
type?: string;
|
||||
module?: string;
|
||||
resource_id?: string;
|
||||
file_size_bytes?: number;
|
||||
duration_seconds?: number | null;
|
||||
}
|
||||
|
||||
export async function uploadAudio(file: File, durationSeconds?: number): Promise<UploadResourceResult> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/generation-records/upload-audio`, {
|
||||
const query = typeof durationSeconds === 'number' && durationSeconds > 0 ? `?duration_seconds=${encodeURIComponent(String(durationSeconds))}` : '';
|
||||
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/generation-records/upload-audio${query}`, {
|
||||
method: 'POST',
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
body: form,
|
||||
});
|
||||
if (!res.ok) throw new Error('图片上传失败');
|
||||
const data = await res.json();
|
||||
return { url: data.url, filename: data.filename };
|
||||
if (!res.ok) throw new Error('音频上传失败');
|
||||
return await res.json();
|
||||
}
|
||||
export async function uploadImage(file: File): Promise<{ url: string; filename: string }> {
|
||||
export async function uploadImage(file: File): Promise<UploadResourceResult> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const token = localStorage.getItem('auth_token');
|
||||
@@ -139,21 +149,74 @@ export async function uploadImage(file: File): Promise<{ url: string; filename:
|
||||
body: form,
|
||||
});
|
||||
if (!res.ok) throw new Error('图片上传失败');
|
||||
const data = await res.json();
|
||||
return { url: data.url, filename: data.filename };
|
||||
return await res.json();
|
||||
}
|
||||
export async function uploadVideo(file: File): Promise<{ url: string; filename: string }> {
|
||||
export async function uploadVideo(file: File, durationSeconds?: number): Promise<UploadResourceResult> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/generation-records/upload-video`, {
|
||||
const query = typeof durationSeconds === 'number' && durationSeconds > 0 ? `?duration_seconds=${encodeURIComponent(String(durationSeconds))}` : '';
|
||||
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/generation-records/upload-video${query}`, {
|
||||
method: 'POST',
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
body: form,
|
||||
});
|
||||
if (!res.ok) throw new Error('视频上传失败');
|
||||
const data = await res.json();
|
||||
return { url: data.url, filename: data.filename };
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
export async function uploadHotOpeningImage(file: File): Promise<UploadResourceResult> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/hot-opening-replications/upload-image`, {
|
||||
method: 'POST',
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
body: form,
|
||||
});
|
||||
if (!res.ok) throw new Error('图片上传失败');
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
export async function uploadHotOpeningVideo(file: File, durationSeconds?: number): Promise<UploadResourceResult> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const query = typeof durationSeconds === 'number' && durationSeconds > 0 ? `?duration_seconds=${encodeURIComponent(String(durationSeconds))}` : '';
|
||||
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/hot-opening-replications/upload-video${query}`, {
|
||||
method: 'POST',
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
body: form,
|
||||
});
|
||||
if (!res.ok) throw new Error('视频上传失败');
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
export async function uploadShotReplicateImage(file: File): Promise<UploadResourceResult> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/shot-replications/upload-image`, {
|
||||
method: 'POST',
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
body: form,
|
||||
});
|
||||
if (!res.ok) throw new Error('图片上传失败');
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
export async function uploadShotReplicateVideo(file: File, durationSeconds?: number): Promise<UploadResourceResult> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const query = typeof durationSeconds === 'number' && durationSeconds > 0 ? `?duration_seconds=${encodeURIComponent(String(durationSeconds))}` : '';
|
||||
const res = await fetch(`${import.meta.env.VITE_API_BASE || 'http://localhost:8000'}/api/shot-replications/upload-video${query}`, {
|
||||
method: 'POST',
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
body: form,
|
||||
});
|
||||
if (!res.ok) throw new Error('视频上传失败');
|
||||
return await res.json();
|
||||
}
|
||||
export async function deleteUpload(url: string): Promise<void> {
|
||||
await api.post(`/generation-records/delete-file?url=${encodeURIComponent(url)}`);
|
||||
@@ -741,6 +804,100 @@ export async function deleteResourcesMaterial(params:any): Promise<any> {
|
||||
return api.delete(`/generation-ai/history/batch`, params);
|
||||
}
|
||||
|
||||
// ── UploadResource History ───────────────────────────────
|
||||
export interface UploadResourceMediaReferenceOut {
|
||||
name?: string | null;
|
||||
type: 'image' | 'video' | 'audio';
|
||||
url: string;
|
||||
label?: string | null;
|
||||
duration?: number | null;
|
||||
source: 'upload_resource';
|
||||
uploadResourceId: string;
|
||||
}
|
||||
|
||||
export interface UploadResourceHistoryItemOut {
|
||||
id: string;
|
||||
sourceType: 'upload_resource';
|
||||
historySource: 'upload_resource';
|
||||
historySourceLabel: string;
|
||||
module: string;
|
||||
moduleLabel: string;
|
||||
resourceType: 'image' | 'video' | 'audio';
|
||||
resourceTypeLabel: string;
|
||||
resourceUrl: string;
|
||||
displayUrl: string;
|
||||
previewUrl: string;
|
||||
imageUrl?: string | null;
|
||||
videoUrl?: string | null;
|
||||
audioUrl?: string | null;
|
||||
fileName?: string | null;
|
||||
fileExt?: string | null;
|
||||
mimeType?: string | null;
|
||||
fileSizeBytes: number;
|
||||
durationSeconds?: number | null;
|
||||
width?: number | null;
|
||||
height?: number | null;
|
||||
bindStatus: string;
|
||||
deletePolicy: string;
|
||||
deletable: boolean;
|
||||
mediaReference: UploadResourceMediaReferenceOut;
|
||||
createdAt?: string | null;
|
||||
updatedAt?: string | null;
|
||||
}
|
||||
|
||||
export interface UploadResourceHistoryDayGroupOut {
|
||||
generatedDate: string;
|
||||
total: number;
|
||||
page: number;
|
||||
items: UploadResourceHistoryItemOut[];
|
||||
}
|
||||
|
||||
export interface UploadResourceHistoryGroupedOut {
|
||||
totalDays: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
groups: UploadResourceHistoryDayGroupOut[];
|
||||
}
|
||||
|
||||
export interface UploadResourceHistoryDayItemsOut {
|
||||
generatedDate: string;
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
items: UploadResourceHistoryItemOut[];
|
||||
}
|
||||
|
||||
export interface UploadResourceHistoryQueryParams {
|
||||
resourceType?: 'image' | 'video' | 'audio' | '';
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
keyword?: string;
|
||||
scene?: 'record' | 'picker' | string;
|
||||
}
|
||||
|
||||
function buildUploadResourceHistoryQuery(params: UploadResourceHistoryQueryParams = {}): string {
|
||||
const query = new URLSearchParams();
|
||||
if (params.resourceType) query.set('resource_type', params.resourceType);
|
||||
if (params.page) query.set('page', String(params.page));
|
||||
if (params.pageSize) query.set('page_size', String(params.pageSize));
|
||||
if (params.keyword) query.set('keyword', params.keyword);
|
||||
if (params.scene) query.set('scene', params.scene);
|
||||
const qs = query.toString();
|
||||
return qs ? `?${qs}` : '';
|
||||
}
|
||||
|
||||
export async function getUploadResourceHistory(params: UploadResourceHistoryQueryParams = {}): Promise<UploadResourceHistoryGroupedOut> {
|
||||
return api.get<UploadResourceHistoryGroupedOut>(`/upload-resources/history${buildUploadResourceHistoryQuery(params)}`);
|
||||
}
|
||||
|
||||
export async function getUploadResourceHistoryItems(generatedDate: string, params: UploadResourceHistoryQueryParams = {}): Promise<UploadResourceHistoryDayItemsOut> {
|
||||
return api.get<UploadResourceHistoryDayItemsOut>(`/upload-resources/history/${generatedDate}${buildUploadResourceHistoryQuery(params)}`);
|
||||
}
|
||||
|
||||
export async function deleteUploadResourceHistoryBatch(resourceIds: string[]): Promise<any> {
|
||||
return api.delete('/upload-resources/history/batch', { resource_ids: resourceIds });
|
||||
}
|
||||
|
||||
|
||||
export async function getPrivatePortraitConfig(): Promise<PrivatePortraitConfig> {
|
||||
return api.get<PrivatePortraitConfig>('/private-portrait/config');
|
||||
|
||||
Reference in New Issue
Block a user