feat(dashboard): clarify server navigation and refresh gallery
Build and publish Docker image / build-and-publish (push) Successful in 40s
Build and publish Docker image / build-and-publish (push) Successful in 40s
This commit is contained in:
1 parent
ad5bf1d015
commit
3523a2e141
8 files changed
+103
-63
No files matched your search
@@ -628,12 +628,53 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
const filePath = getFullPath(file.name);
|
||||
const CHUNK_SIZE = 512 * 1024; // 512KB chunks (reduced to prevent WebSocket frame size issues)
|
||||
const fileSize = file.size;
|
||||
const totalChunks = Math.ceil(fileSize / CHUNK_SIZE);
|
||||
const totalChunks = Math.max(1, Math.ceil(fileSize / CHUNK_SIZE));
|
||||
|
||||
// Always use chunked upload for better progress tracking and binary file support
|
||||
const chunks = [];
|
||||
let chunkIndex = 0;
|
||||
const reader = new FileReader();
|
||||
|
||||
const queueUpload = () => {
|
||||
activeUploadsRef.current[filePath] = {
|
||||
chunks,
|
||||
currentChunkIndex: 0,
|
||||
filePath,
|
||||
fileName: file.name,
|
||||
totalSize: fileSize
|
||||
};
|
||||
|
||||
setUploadProgress(prev => ({
|
||||
...prev,
|
||||
[filePath]: {
|
||||
uploaded: 0,
|
||||
total: totalChunks,
|
||||
percentage: 0,
|
||||
fileName: file.name,
|
||||
totalSize: fileSize
|
||||
}
|
||||
}));
|
||||
|
||||
if (connectionStatus === 'connected') {
|
||||
sendMessage({
|
||||
type: 'start_chunked_upload',
|
||||
serverId,
|
||||
filePath,
|
||||
fileName: file.name,
|
||||
totalSize: fileSize,
|
||||
totalChunks,
|
||||
chunkSize: CHUNK_SIZE
|
||||
});
|
||||
} else {
|
||||
delete activeUploadsRef.current[filePath];
|
||||
setUploadProgress(prev => {
|
||||
const next = { ...prev };
|
||||
delete next[filePath];
|
||||
return next;
|
||||
});
|
||||
showAlert('Upload Blocked', 'WebSocket connection not available. Please wait for connection to be restored.', 'warning');
|
||||
}
|
||||
};
|
||||
|
||||
reader.onload = (e) => {
|
||||
const chunk = e.target.result;
|
||||
@@ -651,46 +692,7 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
const end = Math.min(start + CHUNK_SIZE, fileSize);
|
||||
reader.readAsArrayBuffer(file.slice(start, end));
|
||||
} else {
|
||||
// All chunks read, start upload
|
||||
activeUploadsRef.current[filePath] = {
|
||||
chunks,
|
||||
currentChunkIndex: 0,
|
||||
filePath,
|
||||
fileName: file.name,
|
||||
totalSize: fileSize
|
||||
};
|
||||
|
||||
setUploadProgress(prev => ({
|
||||
...prev,
|
||||
[filePath]: {
|
||||
uploaded: 0,
|
||||
total: totalChunks,
|
||||
percentage: 0,
|
||||
fileName: file.name,
|
||||
totalSize: fileSize
|
||||
}
|
||||
}));
|
||||
|
||||
// Initiate chunked upload only if connection is ready
|
||||
if (connectionStatus === 'connected') {
|
||||
sendMessage({
|
||||
type: 'start_chunked_upload',
|
||||
serverId: serverId,
|
||||
filePath: filePath,
|
||||
fileName: file.name,
|
||||
totalSize: fileSize,
|
||||
totalChunks: totalChunks,
|
||||
chunkSize: CHUNK_SIZE
|
||||
});
|
||||
} else {
|
||||
console.warn('Cannot start upload - WebSocket not connected. Status:', connectionStatus);
|
||||
// Remove from active uploads if connection not ready
|
||||
delete activeUploadsRef.current[filePath];
|
||||
const errorProgress = { ...uploadProgress };
|
||||
delete errorProgress[filePath];
|
||||
setUploadProgress(errorProgress);
|
||||
showAlert('Upload Blocked', 'WebSocket connection not available. Please wait for connection to be restored.', 'warning');
|
||||
}
|
||||
queueUpload();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -704,8 +706,13 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
activeUploadsRef.current = errorActiveUploads;
|
||||
};
|
||||
|
||||
// Start reading first chunk
|
||||
reader.readAsArrayBuffer(file.slice(0, Math.min(CHUNK_SIZE, fileSize)));
|
||||
// Empty files still use one empty chunk so the upload protocol can create them.
|
||||
if (fileSize === 0) {
|
||||
chunks.push('');
|
||||
queueUpload();
|
||||
} else {
|
||||
reader.readAsArrayBuffer(file.slice(0, Math.min(CHUNK_SIZE, fileSize)));
|
||||
}
|
||||
});
|
||||
|
||||
// Reset file input
|
||||
@@ -770,6 +777,9 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-semibold text-lg" style={{ color: colors.brightWhite }}>File Manager & SFTP</h3>
|
||||
<p className="text-xs" role="status" style={{ color: connectionStatus === 'connected' ? colors.brightGreen : colors.yellow }}>
|
||||
{connectionStatus === 'connected' ? 'Server connected' : 'Reconnect to manage files'}
|
||||
</p>
|
||||
{!initialized && (
|
||||
<div className="flex items-center space-x-2 text-sm" style={{ color: colors.yellow }}>
|
||||
<RefreshCw className="w-3 h-3 animate-spin" />
|
||||
@@ -780,11 +790,14 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
</div>
|
||||
<div className="flex items-center space-x-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setInitialized(false);
|
||||
detectWorkingDirectory();
|
||||
}}
|
||||
className="p-3 rounded-xl transition-all duration-200 hover:scale-105 border"
|
||||
disabled={connectionStatus !== 'connected'}
|
||||
aria-label="Refresh file list and detect path"
|
||||
className="p-3 rounded-xl transition-all duration-200 hover:scale-105 border disabled:cursor-not-allowed disabled:opacity-40"
|
||||
style={{
|
||||
backgroundColor: colors.brightBlack,
|
||||
color: colors.foreground,
|
||||
@@ -802,8 +815,10 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div className="flex items-center space-x-3 text-sm">
|
||||
<button
|
||||
type="button"
|
||||
onClick={goToParent}
|
||||
disabled={currentPath === '/' || currentPath === getBasePath()}
|
||||
aria-label="Go to parent folder"
|
||||
className="p-2 rounded-xl transition-all duration-200 hover:scale-105 disabled:opacity-50 border"
|
||||
style={{
|
||||
backgroundColor: colors.brightBlack,
|
||||
@@ -863,6 +878,8 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
disabled={connectionStatus !== 'connected'}
|
||||
onClick={() => {
|
||||
const zipName = currentPath === getBasePath() ? 'archive.zip' : `${currentPath.split('/').filter(Boolean).pop()}.zip`;
|
||||
const zipPath = getFullPath(zipName);
|
||||
@@ -873,7 +890,7 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
zipPath: zipPath
|
||||
});
|
||||
}}
|
||||
className="flex items-center space-x-2 px-3 py-2 rounded-xl text-sm transition-all duration-200 hover:scale-105 border"
|
||||
className="flex items-center space-x-2 px-3 py-2 rounded-xl text-sm transition-all duration-200 hover:scale-105 border disabled:cursor-not-allowed disabled:opacity-40"
|
||||
style={{
|
||||
backgroundColor: `${colors.green}20`,
|
||||
borderColor: colors.green,
|
||||
@@ -891,8 +908,10 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
{selectedFiles.size === 0 && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
disabled={connectionStatus !== 'connected'}
|
||||
onClick={() => setCreateFolderModalOpen(true)}
|
||||
className="flex items-center space-x-2 px-3 py-2 rounded-xl text-sm transition-all duration-200 hover:scale-105 border"
|
||||
className="flex items-center space-x-2 px-3 py-2 rounded-xl text-sm transition-all duration-200 hover:scale-105 border disabled:cursor-not-allowed disabled:opacity-40"
|
||||
style={{
|
||||
backgroundColor: `${colors.green}20`,
|
||||
borderColor: colors.green,
|
||||
@@ -904,8 +923,10 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
disabled={connectionStatus !== 'connected'}
|
||||
onClick={() => setUploadModalOpen(true)}
|
||||
className="flex items-center space-x-2 px-3 py-2 rounded-xl text-sm transition-all duration-200 hover:scale-105 border"
|
||||
className="flex items-center space-x-2 px-3 py-2 rounded-xl text-sm transition-all duration-200 hover:scale-105 border disabled:cursor-not-allowed disabled:opacity-40"
|
||||
style={{
|
||||
backgroundColor: `${colors.blue}20`,
|
||||
borderColor: colors.blue,
|
||||
@@ -972,8 +993,10 @@ const FileManager = forwardRef(({ serverId, serverImage, sendMessage, isActive,
|
||||
|
||||
{clipboard && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={connectionStatus !== 'connected'}
|
||||
onClick={pasteFiles}
|
||||
className="flex items-center space-x-2 px-3 py-2 rounded-xl text-sm transition-all duration-200 hover:scale-105 border animate-pulse"
|
||||
className="flex items-center space-x-2 px-3 py-2 rounded-xl text-sm transition-all duration-200 hover:scale-105 border disabled:cursor-not-allowed disabled:opacity-40"
|
||||
style={{ backgroundColor: `${colors.green}20`, borderColor: colors.green, color: colors.brightGreen }}
|
||||
>
|
||||
<Upload className="w-4 h-4 rotate-180" />
|
||||
|
||||
Reference in new issue
Block a user