fix(file-manager): correlate upload acknowledgments
Build and publish Docker image / build-and-publish (push) Successful in 13s
Build and publish Docker image / build-and-publish (push) Successful in 13s
This commit is contained in:
1 parent
473ee8f9e5
commit
8e3a6d3446
1 file changed
+24
-9
@@ -28,6 +28,20 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
|||||||
const activeUploadsRef = useRef({}); // Changed to object to track multiple uploads
|
const activeUploadsRef = useRef({}); // Changed to object to track multiple uploads
|
||||||
const resumeAttemptedRef = useRef(new Set()); // Track which uploads we've attempted to resume
|
const resumeAttemptedRef = useRef(new Set()); // Track which uploads we've attempted to resume
|
||||||
|
|
||||||
|
const findActiveUploadKey = (filePath) => {
|
||||||
|
if (activeUploadsRef.current[filePath]) return filePath;
|
||||||
|
const keys = Object.keys(activeUploadsRef.current);
|
||||||
|
const serverPathMatch = keys.find(
|
||||||
|
(key) => activeUploadsRef.current[key]?.serverFilePath === filePath
|
||||||
|
);
|
||||||
|
if (serverPathMatch) return serverPathMatch;
|
||||||
|
|
||||||
|
const fileName = filePath?.split('/').pop();
|
||||||
|
if (!fileName) return undefined;
|
||||||
|
const fileNameMatches = keys.filter((key) => key.split('/').pop() === fileName);
|
||||||
|
return fileNameMatches.length === 1 ? fileNameMatches[0] : undefined;
|
||||||
|
};
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
handleWebSocketMessage
|
handleWebSocketMessage
|
||||||
}));
|
}));
|
||||||
@@ -68,7 +82,7 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
|||||||
sendMessage({
|
sendMessage({
|
||||||
type: 'upload_file_chunk',
|
type: 'upload_file_chunk',
|
||||||
serverId: serverId,
|
serverId: serverId,
|
||||||
filePath: filePath,
|
filePath: uploadInfo.serverFilePath || filePath,
|
||||||
chunkIndex: uploadInfo.currentChunkIndex,
|
chunkIndex: uploadInfo.currentChunkIndex,
|
||||||
chunkData: uploadInfo.chunks[uploadInfo.currentChunkIndex],
|
chunkData: uploadInfo.chunks[uploadInfo.currentChunkIndex],
|
||||||
totalChunks: uploadInfo.chunks.length
|
totalChunks: uploadInfo.chunks.length
|
||||||
@@ -249,7 +263,7 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
|||||||
loadFiles(currentPath);
|
loadFiles(currentPath);
|
||||||
break;
|
break;
|
||||||
case 'file_uploaded':
|
case 'file_uploaded':
|
||||||
const uploadedFilePath = data.filePath;
|
const uploadedFilePath = findActiveUploadKey(data.filePath) || data.filePath;
|
||||||
// Remove this upload from tracking
|
// Remove this upload from tracking
|
||||||
const newProgress = { ...uploadProgress };
|
const newProgress = { ...uploadProgress };
|
||||||
delete newProgress[uploadedFilePath];
|
delete newProgress[uploadedFilePath];
|
||||||
@@ -268,8 +282,8 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
|||||||
break;
|
break;
|
||||||
case 'upload_chunk_received':
|
case 'upload_chunk_received':
|
||||||
// Handle chunk acknowledgment and send next chunk
|
// Handle chunk acknowledgment and send next chunk
|
||||||
const chunkFilePath = data.filePath;
|
const chunkFilePath = findActiveUploadKey(data.filePath);
|
||||||
if (activeUploadsRef.current[chunkFilePath]) {
|
if (chunkFilePath) {
|
||||||
const uploadInfo = activeUploadsRef.current[chunkFilePath];
|
const uploadInfo = activeUploadsRef.current[chunkFilePath];
|
||||||
const { chunks, currentChunkIndex } = uploadInfo;
|
const { chunks, currentChunkIndex } = uploadInfo;
|
||||||
|
|
||||||
@@ -278,7 +292,7 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
|||||||
sendMessage({
|
sendMessage({
|
||||||
type: 'upload_file_chunk',
|
type: 'upload_file_chunk',
|
||||||
serverId: serverId,
|
serverId: serverId,
|
||||||
filePath: chunkFilePath,
|
filePath: uploadInfo.serverFilePath || data.filePath,
|
||||||
chunkIndex: currentChunkIndex,
|
chunkIndex: currentChunkIndex,
|
||||||
chunkData: chunks[currentChunkIndex],
|
chunkData: chunks[currentChunkIndex],
|
||||||
totalChunks: chunks.length
|
totalChunks: chunks.length
|
||||||
@@ -302,11 +316,12 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
|||||||
break;
|
break;
|
||||||
case 'upload_started':
|
case 'upload_started':
|
||||||
// Upload started, begin sending chunks
|
// Upload started, begin sending chunks
|
||||||
const startedFilePath = data.filePath;
|
const startedFilePath = findActiveUploadKey(data.clientFilePath || data.filePath);
|
||||||
const uploadId = data.uploadId;
|
const uploadId = data.uploadId;
|
||||||
if (activeUploadsRef.current[startedFilePath]) {
|
if (startedFilePath && activeUploadsRef.current[startedFilePath]) {
|
||||||
const uploadInfo = activeUploadsRef.current[startedFilePath];
|
const uploadInfo = activeUploadsRef.current[startedFilePath];
|
||||||
const { chunks } = uploadInfo;
|
const { chunks } = uploadInfo;
|
||||||
|
uploadInfo.serverFilePath = data.filePath;
|
||||||
// Store uploadId for resume capability
|
// Store uploadId for resume capability
|
||||||
uploadInfo.uploadId = uploadId;
|
uploadInfo.uploadId = uploadId;
|
||||||
// Clear resume attempt flag since upload has started successfully
|
// Clear resume attempt flag since upload has started successfully
|
||||||
@@ -318,7 +333,7 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
|||||||
sendMessage({
|
sendMessage({
|
||||||
type: 'upload_file_chunk',
|
type: 'upload_file_chunk',
|
||||||
serverId: serverId,
|
serverId: serverId,
|
||||||
filePath: startedFilePath,
|
filePath: uploadInfo.serverFilePath,
|
||||||
chunkIndex: 0,
|
chunkIndex: 0,
|
||||||
chunkData: chunks[0],
|
chunkData: chunks[0],
|
||||||
totalChunks: chunks.length
|
totalChunks: chunks.length
|
||||||
@@ -340,7 +355,7 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'upload_error':
|
case 'upload_error':
|
||||||
const errorFilePath = data.filePath || Object.keys(activeUploadsRef.current)[0];
|
const errorFilePath = findActiveUploadKey(data.filePath) || data.filePath || Object.keys(activeUploadsRef.current)[0];
|
||||||
const errorProgress = { ...uploadProgress };
|
const errorProgress = { ...uploadProgress };
|
||||||
delete errorProgress[errorFilePath];
|
delete errorProgress[errorFilePath];
|
||||||
setUploadProgress(errorProgress);
|
setUploadProgress(errorProgress);
|
||||||
|
|||||||
Reference in new issue
Block a user