From 9913e0bbbe148fae77454574a83d909c1a2a30bf Mon Sep 17 00:00:00 2001
From: Sonia Zorba <sonia.zorba@inaf.it>
Date: Wed, 21 Jul 2021 14:42:30 +0200
Subject: [PATCH] Added check on max upload file size

---
 Dockerfile                                           |  1 +
 vospace-ui-frontend/.env.development                 |  1 +
 vospace-ui-frontend/.env.production                  |  1 +
 .../src/components/modal/UploadFilesModal.vue        | 12 ++++++++++++
 4 files changed, 15 insertions(+)

diff --git a/Dockerfile b/Dockerfile
index 9eeeeba..11a753a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -14,6 +14,7 @@ ADD vospace-ui-frontend/*.js /vospace-ui-frontend/
 ADD vospace-ui-frontend/*.json /vospace-ui-frontend/
 ADD vospace-ui-frontend/.env.production /vospace-ui-frontend/
 WORKDIR /vospace-ui-frontend
+ARG VUE_APP_MAX_UPLOAD_SIZE=10
 RUN npm run build
 
 ADD vospace-ui-backend/src /vospace-ui-backend/src/
diff --git a/vospace-ui-frontend/.env.development b/vospace-ui-frontend/.env.development
index b4b1787..a30a4d9 100644
--- a/vospace-ui-frontend/.env.development
+++ b/vospace-ui-frontend/.env.development
@@ -1,2 +1,3 @@
 VUE_APP_API_CLIENT = 'mock'
 VUE_APP_API_BASE_URL = 'http://localhost:8085/'
+VUE_APP_MAX_UPLOAD_SIZE = 10
diff --git a/vospace-ui-frontend/.env.production b/vospace-ui-frontend/.env.production
index 6010f55..d05173e 100644
--- a/vospace-ui-frontend/.env.production
+++ b/vospace-ui-frontend/.env.production
@@ -1,2 +1,3 @@
 VUE_APP_API_CLIENT = 'server'
 VUE_APP_API_BASE_URL = ''
+VUE_APP_MAX_UPLOAD_SIZE = 10
diff --git a/vospace-ui-frontend/src/components/modal/UploadFilesModal.vue b/vospace-ui-frontend/src/components/modal/UploadFilesModal.vue
index 8d9ca50..17d68b1 100644
--- a/vospace-ui-frontend/src/components/modal/UploadFilesModal.vue
+++ b/vospace-ui-frontend/src/components/modal/UploadFilesModal.vue
@@ -10,7 +10,10 @@
   <div class="mt-3">Selected files: {{ selectedFiles }}</div>
 </b-modal>
 </template>
+
 <script>
+const maxUploadSize = process.env.VUE_APP_MAX_UPLOAD_SIZE;
+
 export default {
   data() {
     return {
@@ -56,6 +59,15 @@ export default {
           }
         }
 
+        // Check size limit
+        for (let file of this.files) {
+          if (file.size >= maxUploadSize * Math.pow(10, 9)) {
+            this.uploadFileError = "File " + file.name + " is too big. Max allowed file size is " + maxUploadSize + " GB";
+            return;
+          }
+        }
+
+        // Upload
         this.$store.dispatch('uploadFiles', this.files)
           .then(() => {
             this.$bvModal.hide('upload-files-modal');
-- 
GitLab