fix(auth-files): prevent concurrent uploads

This commit is contained in:
Supra4E8C
2026-07-30 03:55:16 +08:00
parent b76037ac7c
commit c9636a3c54
2 changed files with 13 additions and 1 deletions
+5 -1
View File
@@ -690,7 +690,11 @@ export function AuthFilesPage() {
description={t('auth_files.empty_desc')}
action={
<div className={styles.emptyActions}>
<Button size="sm" onClick={handleUploadClick} disabled={disableControls}>
<Button
size="sm"
onClick={handleUploadClick}
disabled={disableControls || uploading}
>
{t('auth_files.upload_button')}
</Button>
<Button variant="ghost" size="sm" onClick={() => navigate('/oauth')}>
@@ -85,6 +85,7 @@ export function useAuthFilesData(options?: UseAuthFilesDataOptions): UseAuthFile
const [selectedFiles, setSelectedFiles] = useState<Set<string>>(new Set());
const fileInputRef = useRef<HTMLInputElement | null>(null);
const uploadPendingRef = useRef(false);
const manualRefreshPendingRef = useRef<Set<string>>(new Set());
const batchStatusPendingRef = useRef(false);
/** 列表请求代号:变更操作会使在途响应过期,防止旧轮询复活已删/已改文件。 */
@@ -218,6 +219,7 @@ export function useAuthFilesData(options?: UseAuthFilesDataOptions): UseAuthFile
);
const handleUploadClick = useCallback(() => {
if (uploadPendingRef.current) return;
fileInputRef.current?.click();
}, []);
@@ -257,7 +259,12 @@ export function useAuthFilesData(options?: UseAuthFilesDataOptions): UseAuthFile
event.target.value = '';
return;
}
if (uploadPendingRef.current) {
event.target.value = '';
return;
}
uploadPendingRef.current = true;
setUploading(true);
try {
const result = await authFilesApi.uploadFiles(validFiles);
@@ -282,6 +289,7 @@ export function useAuthFilesData(options?: UseAuthFilesDataOptions): UseAuthFile
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
showNotification(`${t('notification.upload_failed')}: ${errorMessage}`, 'error');
} finally {
uploadPendingRef.current = false;
setUploading(false);
event.target.value = '';
}