mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-09-01 15:34:05 +08:00
fix(auth-files): prevent concurrent uploads
This commit is contained in:
@@ -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 = '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user