98 lines
2.5 KiB
TypeScript
98 lines
2.5 KiB
TypeScript
/**
|
|
* 素材相关 API
|
|
*/
|
|
import apiClient from './client';
|
|
|
|
export interface AssetItem {
|
|
id: string;
|
|
workspace_id: string;
|
|
project_id: string;
|
|
library_id: string;
|
|
name: string;
|
|
storage_key: string;
|
|
mime_type: string;
|
|
metadata: Record<string, unknown>;
|
|
}
|
|
|
|
export interface AssetLibraryItem {
|
|
id: string;
|
|
workspace_id: string;
|
|
project_id: string;
|
|
name: string;
|
|
kind: 'video' | 'voice';
|
|
}
|
|
|
|
export interface IngestJob {
|
|
id: string;
|
|
workspace_id: string;
|
|
project_id: string;
|
|
library_id: string;
|
|
storage_key: string;
|
|
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
error_message: string;
|
|
result_asset_id: string;
|
|
}
|
|
|
|
export interface ClassificationJob {
|
|
id: string;
|
|
workspace_id: string;
|
|
project_id: string;
|
|
asset_id: string;
|
|
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
classification: string;
|
|
confidence: number;
|
|
error_message: string;
|
|
}
|
|
|
|
export const getAssetLibraries = async (projectId: string): Promise<AssetLibraryItem[]> => {
|
|
const response = await apiClient.get('/asset-libraries', {
|
|
params: { project_id: projectId },
|
|
});
|
|
return response.data.items;
|
|
};
|
|
|
|
export const createAssetLibrary = async (data: {
|
|
workspace_id: string;
|
|
project_id: string;
|
|
name: string;
|
|
kind: 'video' | 'voice';
|
|
}): Promise<AssetLibraryItem> => {
|
|
const response = await apiClient.post('/asset-libraries', data);
|
|
return response.data;
|
|
};
|
|
|
|
export const getAssets = async (libraryId: string): Promise<AssetItem[]> => {
|
|
const response = await apiClient.get('/assets', {
|
|
params: { library_id: libraryId },
|
|
});
|
|
return response.data.items;
|
|
};
|
|
|
|
export const uploadAsset = async (
|
|
formData: FormData
|
|
): Promise<{ storage_key: string; ingest_job_id: string; url: string }> => {
|
|
const response = await apiClient.post('/upload', formData, {
|
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
});
|
|
return response.data;
|
|
};
|
|
|
|
export const getIngestJob = async (jobId: string): Promise<IngestJob> => {
|
|
const response = await apiClient.get(`/ingest-jobs/${jobId}`);
|
|
return response.data;
|
|
};
|
|
|
|
export const submitClassificationJob = async (data: {
|
|
workspace_id: string;
|
|
project_id: string;
|
|
asset_id: string;
|
|
}): Promise<ClassificationJob> => {
|
|
const response = await apiClient.post('/classification-jobs', data);
|
|
return response.data;
|
|
};
|
|
|
|
export const getClassificationJob = async (jobId: string): Promise<ClassificationJob> => {
|
|
const response = await apiClient.get(`/classification-jobs/${jobId}`);
|
|
return response.data;
|
|
};
|