From c47ebe421a6203792986177612fd1a392b17c317 Mon Sep 17 00:00:00 2001
From: Benedikt Heinrichs <heinrichs@itc.rwth-aachen.de>
Date: Wed, 22 May 2024 09:30:55 +0200
Subject: [PATCH] Update: Use download action

---
 src/mapping/tree.ts                           |  1 +
 .../components/resource-page/FilesView.vue    |  1 +
 .../resource-page/MetadataManager.vue         |  1 +
 src/modules/resource/store.ts                 | 39 ++++++++++++-------
 src/modules/resource/types.ts                 |  2 +
 5 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/mapping/tree.ts b/src/mapping/tree.ts
index c2935cc1..724a5c3b 100644
--- a/src/mapping/tree.ts
+++ b/src/mapping/tree.ts
@@ -37,6 +37,7 @@ const configuration = new MapperConfiguration((cfg) => {
         return { [version]: factory.dataset() as unknown as Dataset };
       }), // Set outside of the mapper
     versions: (opt) => opt.mapFrom((_) => [version]),
+    actions: (opt) => opt.mapFrom((dto) => dto.actions),
   });
 
   cfg.createMap(TreeDto2FolderInformation, {
diff --git a/src/modules/resource/components/resource-page/FilesView.vue b/src/modules/resource/components/resource-page/FilesView.vue
index b06ac4e1..6a3c89f7 100644
--- a/src/modules/resource/components/resource-page/FilesView.vue
+++ b/src/modules/resource/components/resource-page/FilesView.vue
@@ -732,6 +732,7 @@ export default defineComponent({
           this.resource.id,
           file.path,
           file.name,
+          file.actions,
         );
       }
     },
diff --git a/src/modules/resource/components/resource-page/MetadataManager.vue b/src/modules/resource/components/resource-page/MetadataManager.vue
index d6642cb8..5746b04c 100644
--- a/src/modules/resource/components/resource-page/MetadataManager.vue
+++ b/src/modules/resource/components/resource-page/MetadataManager.vue
@@ -996,6 +996,7 @@ export default defineComponent({
             this.resource.id,
             editableFile.path,
             editableFile.name,
+            editableFile.actions,
           );
         }
       }
diff --git a/src/modules/resource/store.ts b/src/modules/resource/store.ts
index 61f66b2d..81f17c43 100644
--- a/src/modules/resource/store.ts
+++ b/src/modules/resource/store.ts
@@ -34,6 +34,7 @@ import {
 import factory from "rdf-ext";
 import fileSaver from "file-saver";
 import type {
+  FileActionsDto,
   RdfFormat,
   GitlabBranchDto,
   GitlabProjectDto,
@@ -49,6 +50,7 @@ import type {
 } from "@coscine/api-client/dist/types/Coscine.Api";
 import { wrapListRequest } from "@/util/wrapListRequest";
 import i18n from "@/plugins/vue-i18n";
+
 /*  
   Store variable name is "this.<id>Store"
     id: "resource" --> this.resourceStore
@@ -836,24 +838,35 @@ export const useResourceStore = defineStore({
       resourceId: string,
       path: string,
       name: string,
+      actions?: FileActionsDto,
     ) {
       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,
-          );
+        // Easiest case: Use the provided download URL
+        if (actions?.download?.url) {
+          window.open(actions.download.url, "_blank");
         } else {
-          // Handle other Status Codes
-          notificationStore.postGeneralApiWarningNotification(
-            "No Download Response",
+          const response = await this.getBlob(
+            projectId,
+            resourceId,
+            path,
+            true,
           );
-          return null;
+          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
diff --git a/src/modules/resource/types.ts b/src/modules/resource/types.ts
index 04dca8da..918c0dcc 100644
--- a/src/modules/resource/types.ts
+++ b/src/modules/resource/types.ts
@@ -4,6 +4,7 @@ import {
 } from "@coscine/api-client/dist/types/Coscine.Api";
 import type {
   ApplicationProfileDto,
+  FileActionsDto,
   GitlabBranchDto,
   GitlabProjectDto,
   Pagination,
@@ -222,6 +223,7 @@ export interface GeneralInformation {
   versions: number[];
   latestVersion: number;
   currentVersion: number;
+  actions?: FileActionsDto;
   lastModified?: string | null;
   readOnly?: boolean;
   createdAt?: string;
-- 
GitLab