Добавил использование на клиенте настройки 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 { 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;
} }
} }

View File

@@ -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) { async uploadFile(file, maxUploadFileSize, callback) {
if (file.size > maxFileUploadSize) if (!maxUploadFileSize)
throw new Error(`Размер файла превышает ${maxFileUploadSize} байт`); 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);

View File

@@ -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);
}); });