Переглянути джерело

Добавил использование на клиенте настройки maxUploadFileSize

Book Pauk 6 роки тому
батько
коміт
835f9374f6
3 змінених файлів з 8 додано та 6 видалено
  1. 1 1
      client/api/misc.js
  2. 5 4
      client/api/reader.js
  3. 2 1
      client/components/Reader/Reader.vue

+ 1 - 1
client/api/misc.js

@@ -6,7 +6,7 @@ const api = axios.create({
 
 
 class Misc {
 class Misc {
     async loadConfig() {
     async loadConfig() {
-        const response = await api.post('/config', {params: ['name', 'version', 'mode']});
+        const response = await api.post('/config', {params: ['name', 'version', 'mode', 'maxUploadFileSize']});
         return response.data;
         return response.data;
     }
     }
 }
 }

+ 5 - 4
client/api/reader.js

@@ -1,7 +1,6 @@
 import axios from 'axios';
 import axios from 'axios';
 import {sleep} from '../share/utils';
 import {sleep} from '../share/utils';
 
 
-const maxFileUploadSize = 50*1024*1024;
 const api = axios.create({
 const api = axios.create({
   baseURL: '/api/reader'
   baseURL: '/api/reader'
 });
 });
@@ -75,9 +74,11 @@ class Reader {
         return await axios.get(url, options);
         return await axios.get(url, options);
     }
     }
 
 
-    async uploadFile(file, callback) {
-        if (file.size > maxFileUploadSize)
-            throw new Error(`Размер файла превышает ${maxFileUploadSize} байт`);
+    async uploadFile(file, maxUploadFileSize, callback) {
+        if (!maxUploadFileSize)
+            maxUploadFileSize = 10*1024*1024;
+        if (file.size > maxUploadFileSize)
+            throw new Error(`Размер файла превышает ${maxUploadFileSize} байт`);
 
 
         let formData = new FormData();
         let formData = new FormData();
         formData.append('file', file);
         formData.append('file', file);

+ 2 - 1
client/components/Reader/Reader.vue

@@ -168,6 +168,7 @@ class Reader extends Vue {
         this.commit = this.$store.commit;
         this.commit = this.$store.commit;
         this.dispatch = this.$store.dispatch;
         this.dispatch = this.$store.dispatch;
         this.reader = this.$store.state.reader;
         this.reader = this.$store.state.reader;
+        this.config = this.$store.state.config;
 
 
         this.$root.addKeyHook(this.keyHook);
         this.$root.addKeyHook(this.keyHook);
 
 
@@ -713,7 +714,7 @@ class Reader extends Vue {
                 progress.show();
                 progress.show();
                 progress.setState({state: 'upload'});
                 progress.setState({state: 'upload'});
 
 
-                const url = await readerApi.uploadFile(opts.file, (state) => {
+                const url = await readerApi.uploadFile(opts.file, this.config.maxUploadFileSize, (state) => {
                     progress.setState(state);
                     progress.setState(state);
                 });
                 });