Skip to content

Commit 4896268

Browse files
authored
Fix/filemanager download (#228)
This pull request updates the application version to 1.5.0 and improves the file download functionality in the file manager. The most important changes are: Version update: * Bumped the application version from 1.4.0 to 1.5.0 in both `package.json` and `src/version.js` to keep versioning consistent. [[1]](diffhunk://#diff-da6498268e99511d9ba0df3c13e439d10556a812881c9d03955b2ef7c6c1c655L3-R3) [[2]](diffhunk://#diff-d3ccf8195e0a16ec5e975768c8b2ef7132d7e5ffb2bd8806204d7b3c6030bb2eL5-R5) File download improvements: * Refactored the `downloadFile` function in `downloadFileAPI.js` to download each file individually, cleaned up file paths to avoid double slashes, set the `download` attribute to preserve file names, and added a small delay between downloads to improve reliability. Also added better error logging.
1 parent 501da4e commit 4896268

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "microscope-app",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"private": true,
55
"homepage": "/imswitch/ui",
66
"dependencies": {
Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
import { api } from "./api";
22

33
export const downloadFile = async (files, hostname, port) => {
4-
if (files.length === 0) return;
4+
if (files.length === 0) return { success: [], failed: [] };
55

6-
try {
7-
// build url based on api
8-
const fileQuery = files.map((file) => `${file.path}`).join("&");
9-
const url = `${hostname}:${port}/api/FileManager/download/${fileQuery}`; // TODO: Make part of axios instance
6+
const result = { success: [], failed: [] };
107

11-
const link = document.createElement("a");
12-
link.href = url;
8+
for (const file of files) {
9+
try {
10+
// Remove leading slash if present to avoid double slashes
11+
const cleanPath = file.path.startsWith("/")
12+
? file.path.slice(1)
13+
: file.path;
14+
const url = `${hostname}:${port}/imswitch/api/FileManager/download/${cleanPath}`;
1315

14-
document.body.appendChild(link);
15-
link.click();
16-
document.body.removeChild(link);
17-
} catch (error) {
18-
return error;
16+
const link = document.createElement("a");
17+
link.href = url;
18+
link.setAttribute("download", file.name);
19+
20+
document.body.appendChild(link);
21+
link.click();
22+
document.body.removeChild(link);
23+
24+
result.success.push(file.name);
25+
26+
// Small delay between downloads
27+
await new Promise((resolve) => setTimeout(resolve, 100));
28+
} catch (error) {
29+
console.error(`Download failed for file "${file.name}":`, error);
30+
result.failed.push({ name: file.name, error: error.message });
31+
}
1932
}
33+
34+
// Log summary
35+
if (result.failed.length > 0) {
36+
console.warn(
37+
`Download completed with errors: ${result.success.length} succeeded, ${result.failed.length} failed`,
38+
result.failed,
39+
);
40+
} else if (result.success.length > 0) {
41+
console.log(`All ${result.success.length} file(s) downloaded successfully`);
42+
}
43+
44+
return result;
2045
};

frontend/src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
* Application version - manually synchronized with package.json
33
* Update this when bumping version in package.json
44
*/
5-
export const APP_VERSION = "1.4.0";
5+
export const APP_VERSION = "1.5.0";

0 commit comments

Comments
 (0)