fix(web): allow batch asset uploads
This commit is contained in:
@@ -90,7 +90,7 @@ const ProjectAssets: React.FC = () => {
|
||||
const workspaceId = routedWorkspaceId || storedWorkspaceId || resolvedWorkspaceId;
|
||||
const [libraryId, setLibraryId] = useState<string>('');
|
||||
const [createLibraryOpen, setCreateLibraryOpen] = useState(false);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [activeUploadCount, setActiveUploadCount] = useState(0);
|
||||
const [ingestJobId, setIngestJobId] = useState<string>('');
|
||||
const [classificationJobId, setClassificationJobId] = useState<string>('');
|
||||
const [classifyingAssetId, setClassifyingAssetId] = useState<string>('');
|
||||
@@ -102,6 +102,7 @@ const ProjectAssets: React.FC = () => {
|
||||
const [batchJobIds, setBatchJobIds] = useState<string[]>([]);
|
||||
const [batchFailedIds, setBatchFailedIds] = useState<string[]>([]);
|
||||
const [form] = Form.useForm();
|
||||
const uploading = activeUploadCount > 0;
|
||||
|
||||
useEffect(() => {
|
||||
if (projectId && routedWorkspaceId) {
|
||||
@@ -172,12 +173,10 @@ const ProjectAssets: React.FC = () => {
|
||||
useEffect(() => {
|
||||
const status = ingestJobQuery.data?.status;
|
||||
if (status === 'completed') {
|
||||
setUploading(false);
|
||||
assetsQuery.refetch();
|
||||
message.success('素材导入完成,已自动发起分类');
|
||||
}
|
||||
if (status === 'failed') {
|
||||
setUploading(false);
|
||||
message.error(ingestJobQuery.data?.error_message || '素材导入失败');
|
||||
}
|
||||
}, [ingestJobQuery.data?.status, assetsQuery]);
|
||||
@@ -413,25 +412,33 @@ const ProjectAssets: React.FC = () => {
|
||||
|
||||
const customUpload = async (options: any) => {
|
||||
const { file, onSuccess, onError } = options;
|
||||
if (!libraryId) {
|
||||
message.warning('请先选择或创建素材库');
|
||||
const uploadFile = file as File;
|
||||
if (!workspaceId) {
|
||||
message.warning('正在恢复工作空间上下文,请稍后再上传');
|
||||
onError(new Error('Missing workspace context'));
|
||||
return;
|
||||
}
|
||||
if (!libraryId) {
|
||||
message.warning('请先选择或创建素材库');
|
||||
onError(new Error('Missing asset library'));
|
||||
return;
|
||||
}
|
||||
setActiveUploadCount((count) => count + 1);
|
||||
try {
|
||||
setUploading(true);
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('file', uploadFile);
|
||||
formData.append('workspace_id', workspaceId);
|
||||
formData.append('project_id', projectId);
|
||||
formData.append('library_id', libraryId);
|
||||
const result = await uploadAsset(formData);
|
||||
setIngestJobId(result.ingest_job_id);
|
||||
onSuccess(result);
|
||||
message.info('文件已上传,正在导入处理中');
|
||||
message.info(`${uploadFile.name} 已上传,正在导入处理中`);
|
||||
} catch (error) {
|
||||
setUploading(false);
|
||||
onError(error);
|
||||
message.error((error as any).response?.data?.detail || '上传失败');
|
||||
message.error((error as any).response?.data?.detail || `${uploadFile.name} 上传失败`);
|
||||
} finally {
|
||||
setActiveUploadCount((count) => Math.max(0, count - 1));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -527,10 +534,12 @@ const ProjectAssets: React.FC = () => {
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Dragger name="file" multiple={false} customRequest={customUpload} showUploadList={false} disabled={uploading || !workspaceId} style={{ marginBottom: 24 }}>
|
||||
<Dragger name="file" multiple customRequest={customUpload} showUploadList={false} disabled={!workspaceId || !libraryId} style={{ marginBottom: 24 }}>
|
||||
<p className="ant-upload-drag-icon"><InboxOutlined /></p>
|
||||
<p className="ant-upload-text">点击或拖拽文件到这里上传素材</p>
|
||||
<p className="ant-upload-hint">支持视频、音频、图片文件;上传后自动进入导入任务</p>
|
||||
<p className="ant-upload-text">点击或拖拽文件到这里批量上传素材</p>
|
||||
<p className="ant-upload-hint">
|
||||
支持一次选择多个视频、音频、图片文件;上传中 {uploading ? `(${activeUploadCount} 个文件处理中)` : '自动进入导入任务'}
|
||||
</p>
|
||||
</Dragger>
|
||||
|
||||
{filteredAssets.length ? (
|
||||
|
||||
Reference in New Issue
Block a user