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

This commit is contained in:
Book Pauk
2019-02-13 17:58:44 +07:00
parent edece5e17f
commit 835f9374f6
3 changed files with 8 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ const api = axios.create({
class Misc {
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;
}
}

View File

@@ -1,7 +1,6 @@
import axios from 'axios';
import {sleep} from '../share/utils';
const maxFileUploadSize = 50*1024*1024;
const api = axios.create({
baseURL: '/api/reader'
});
@@ -75,9 +74,11 @@ class Reader {
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();
formData.append('file', file);

View File

@@ -168,6 +168,7 @@ class Reader extends Vue {
this.commit = this.$store.commit;
this.dispatch = this.$store.dispatch;
this.reader = this.$store.state.reader;
this.config = this.$store.state.config;
this.$root.addKeyHook(this.keyHook);
@@ -713,7 +714,7 @@ class Reader extends Vue {
progress.show();
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);
});