Skip to content
Snippets Groups Projects
Commit 54172bc2 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Fix: Same Download Methods

parent 0228e0ab
Branches dependabot/cargo/crossbeam-utils-0.8.12
Tags
2 merge requests!308Chore: 2.5.7,!298Fix: Same Download Methods
Pipeline #1158424 passed with warnings
......@@ -169,7 +169,6 @@ import useResourceStore from "../../store";
import useProjectStore from "@/modules/project/store";
import FilesViewHeader from "./FilesViewHeader.vue";
import MetadataManagerUtil from "../../utils/MetadataManagerUtil";
import fileSaver from "file-saver";
import { FileUtil } from "../../utils/FileUtil";
import { v4 as uuidv4 } from "uuid";
import { parseRDFDefinition } from "../../utils/linkedData";
......@@ -684,27 +683,12 @@ export default defineComponent({
async openFile(file: FileInformation) {
if (this.project?.id && this.resource?.id) {
// Download the file as a blob (binary data)
const asBlob = true;
// Fetch the blob content of the file
const response = await this.resourceStore.getBlob(
await this.resourceStore.download(
this.project.id,
this.resource.id,
file.path,
asBlob,
file.name,
);
if (response) {
// Trigger file download
fileSaver.saveAs(
new Blob([response.data], {
type: response.headers["content-type"],
}),
file.name,
);
// TODO: Consider adding a visual indicator that the file is being downloaded
}
}
},
......
......@@ -127,7 +127,6 @@ import useResourceStore from "../../store";
import useProjectStore from "@/modules/project/store";
import useUserStore from "@/modules/user/store";
import useNotificationStore from "@/store/notification";
import fileSaver from "file-saver";
import MetadataManagerUtil from "../../utils/MetadataManagerUtil";
import MetadataManagerHeader from "./metadata/MetadataManagerHeader.vue";
import MetadataManagerTable from "./metadata/MetadataManagerTable.vue";
......@@ -810,19 +809,12 @@ export default defineComponent({
async download() {
if (this.showDetail && this.project?.id && this.resource?.id) {
for (const editableFile of this.shownFiles) {
const response = await this.resourceStore.getBlob(
await this.resourceStore.download(
this.project.id,
this.resource.id,
editableFile.path,
editableFile.name,
);
if (response !== null) {
fileSaver.saveAs(
new Blob([response.data], {
type: response.headers["content-type"],
}),
editableFile.name,
);
}
}
}
},
......
......@@ -25,6 +25,7 @@ import useNotificationStore from "@/store/notification";
import { useLocalStorage } from "@vueuse/core";
import { parseRDFDefinition, resolveImports } from "./utils/linkedData";
import factory from "rdf-ext";
import fileSaver from "file-saver";
import type {
RdfFormat,
ApplicationProfileDto,
......@@ -661,6 +662,37 @@ export const useResourceStore = defineStore({
}
},
async download(
projectId: string,
resourceId: string,
path: string,
name: string,
) {
const notificationStore = useNotificationStore();
try {
const response = await this.getBlob(projectId, resourceId, path, true);
if (response !== null) {
// Trigger file download
fileSaver.saveAs(
new Blob([response.data], {
type: response.headers["content-type"],
}),
name,
);
} else {
// Handle other Status Codes
notificationStore.postGeneralApiWarningNotification(
"No Download Response",
);
return null;
}
} catch (error) {
// Handle other Status Codes
notificationStore.postApiErrorNotification(error as AxiosError);
return null;
}
},
async getBlob(
projectId: string,
resourceId: string,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment