Skip to content

Commit 6aa8c81

Browse files
author
k.haritonov
committed
added validation of uploaded files
1 parent 7c55811 commit 6aa8c81

File tree

22 files changed

+24612
-9144
lines changed

22 files changed

+24612
-9144
lines changed

package-lock.json

Lines changed: 24456 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "laravel-file-manager",
3-
"version": "2.5.4",
3+
"version": "2.6.0",
44
"description": "File manager for Laravel",
55
"keywords": [
66
"laravel",
@@ -37,7 +37,7 @@
3737
"eslint": "^6.8.0",
3838
"eslint-plugin-import": "^2.22.0",
3939
"eslint-plugin-vue": "^6.2.2",
40-
"node-sass": "^4.14.1",
40+
"sass": "^1.53.0",
4141
"sass-loader": "^8.0.2",
4242
"vue-template-compiler": "^2.6.12"
4343
}

src/components/modals/views/Upload.vue

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,21 @@
1919
v-bind:key="index">
2020
<div class="w-75 text-truncate">
2121
<i class="far" v-bind:class="mimeToIcon(item.type)"/>
22-
{{ item.name }}
22+
<span v-bind:class="[notValidFilesIndexes.includes(index) ? 'text-danger' : '']">
23+
{{ item.name }}
24+
</span>
2325
</div>
2426
<div class="text-right">
25-
{{ bytesToHuman(item.size) }}
27+
<span v-bind:class="[notValidFilesIndexes.includes(index) ? 'text-danger' : '']">
28+
{{ bytesToHuman(item.size) }}
29+
</span>
30+
<button type="button"
31+
class="close"
32+
aria-label="Delete"
33+
v-on:click="deleteFile(index)"
34+
v-bind:title="lang.btn.deleteFile">
35+
<span aria-hidden="true">&times;</span>
36+
</button>
2637
</div>
2738
</div>
2839
<hr>
@@ -33,7 +44,9 @@
3344
</div>
3445
<div class="text-right">
3546
<strong>{{ lang.modal.upload.size }}</strong>
36-
{{ allFilesSize }}
47+
<span v-bind:class="[!isValidAllFilesSize ? 'text-danger' : '']">
48+
{{ allFilesSize }}
49+
</span>
3750
</div>
3851
</div>
3952
<hr>
@@ -81,11 +94,22 @@
8194
</div>
8295
</div>
8396
</div>
97+
<div class="alert alert-danger" v-if="countFiles && (notValidFilesIndexes.length || !isValidAllFilesSize)">
98+
<p v-if="notValidFilesIndexes.length">
99+
{{ lang.modal.upload.noAllowFileTypes }} - {{ $store.state.fm.settings.allowFileTypes.join(', ') }}
100+
</p>
101+
<p v-if="notValidFilesIndexes.length">
102+
{{ lang.modal.upload.noMaxUploadFileSize }} - {{ bytesToHuman($store.state.fm.settings.maxUploadFileSize * 1024) }}
103+
</p>
104+
<p v-if="!isValidAllFilesSize">
105+
{{ lang.modal.upload.noMaxPostSize }} - {{ bytesToHuman($store.state.fm.settings.maxPostSize * 1024) }}
106+
</p>
107+
</div>
84108
</div>
85109
<div class="modal-footer">
86110
<button class="btn"
87-
v-bind:class="[countFiles ? 'btn-info' : 'btn-light']"
88-
v-bind:disabled="!countFiles"
111+
v-bind:class="[countFiles && !notValidFilesIndexes.length && isValidAllFilesSize ? 'btn-info' : 'btn-light']"
112+
v-bind:disabled="!countFiles || notValidFilesIndexes.length || !isValidAllFilesSize"
89113
v-on:click="uploadFiles">{{ lang.btn.submit }}
90114
</button>
91115
<button class="btn btn-light" v-on:click="hideModal()">{{ lang.btn.cancel }}</button>
@@ -142,6 +166,38 @@ export default {
142166
return this.bytesToHuman(size);
143167
},
144168
169+
notValidFilesIndexes() {
170+
const indexes = [];
171+
172+
for (let i = 0; i < this.newFiles.length; i += 1) {
173+
const ext = this.newFiles[i].name.split('.').pop();
174+
if (
175+
(
176+
this.$store.state.fm.settings.allowFileTypes.length
177+
&& !this.$store.state.fm.settings.allowFileTypes.includes(ext)
178+
)
179+
|| (
180+
this.$store.state.fm.settings.maxUploadFileSize !== null
181+
&& this.newFiles[i].size > this.$store.state.fm.settings.maxUploadFileSize * 1024
182+
)
183+
) {
184+
indexes.push(i);
185+
}
186+
}
187+
188+
return indexes;
189+
},
190+
191+
isValidAllFilesSize() {
192+
let size = 0;
193+
194+
for (let i = 0; i < this.newFiles.length; i += 1) {
195+
size += this.newFiles[i].size;
196+
}
197+
198+
return this.$store.state.fm.settings.maxPostSize === null || size <= this.$store.state.fm.settings.maxPostSize * 1024;
199+
},
200+
145201
},
146202
methods: {
147203
/**
@@ -178,6 +234,22 @@ export default {
178234
});
179235
}
180236
},
237+
238+
/**
239+
* Delete file
240+
* @param index
241+
*/
242+
deleteFile(index) {
243+
const dt = new DataTransfer();
244+
245+
for (let i = 0; i < this.newFiles.length; i += 1) {
246+
if (i !== index) {
247+
dt.items.add(this.newFiles[i]);
248+
}
249+
}
250+
251+
this.newFiles = dt.files;
252+
},
181253
},
182254
};
183255
</script>

src/lang/ar.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const ar = {
2424
upload: 'رفع',
2525
uploadSelect: 'اختر الملفات',
2626
hidden: 'الملفات المخفية',
27+
deleteFile: 'Delete file',
2728
},
2829
clipboard: {
2930
actionType: 'نوع',
@@ -123,6 +124,9 @@ const ar = {
123124
size: 'الحجم:',
124125
skip: 'تخطي',
125126
title: 'رفع الملفات',
127+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
128+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
129+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
126130
},
127131
editor: {
128132
title: 'محرر',

src/lang/cs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const cs = {
2525
upload: 'Nahrát',
2626
uploadSelect: 'Vybrat soubory',
2727
hidden: ' Skryté soubory',
28+
deleteFile: 'Delete file',
2829
},
2930
clipboard: {
3031
actionType: 'Typ',
@@ -124,6 +125,9 @@ const cs = {
124125
size: 'Velikost:',
125126
skip: 'Přeskočit',
126127
title: 'Nahrát soubory',
128+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
129+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
130+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
127131
},
128132
editor: {
129133
title: 'Editor',

src/lang/de.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const de = {
2424
upload: 'Hochladen',
2525
uploadSelect: 'Auswählen',
2626
hidden: ' Versteckte Dateien',
27+
deleteFile: 'Delete file',
2728
},
2829
clipboard: {
2930
actionType: 'Type',
@@ -123,6 +124,9 @@ const de = {
123124
size: 'Größe:',
124125
skip: 'Überspringen',
125126
title: 'Hochladen von Dateien',
127+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
128+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
129+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
126130
},
127131
editor: {
128132
title: 'Editor',

src/lang/en.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const en = {
2424
upload: 'Upload',
2525
uploadSelect: 'Select files',
2626
hidden: ' Hidden files',
27+
deleteFile: 'Delete file',
2728
},
2829
clipboard: {
2930
actionType: 'Type',
@@ -123,6 +124,9 @@ const en = {
123124
size: 'Size:',
124125
skip: 'Skip',
125126
title: 'Upload files',
127+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
128+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
129+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
126130
},
127131
editor: {
128132
title: 'Editor',

src/lang/es.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const es = {
2525
upload: 'Subir',
2626
uploadSelect: 'Seleccionar archivos',
2727
hidden: ' Archivos ocultos',
28+
deleteFile: 'Delete file',
2829
},
2930
clipboard: {
3031
actionType: 'Tipo',
@@ -124,6 +125,9 @@ const es = {
124125
size: 'Size:',
125126
skip: 'Omitir',
126127
title: 'Subir archivos',
128+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
129+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
130+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
127131
},
128132
editor: {
129133
title: 'Editor',

src/lang/fa.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const fa = {
2525
upload: 'بارگذاری',
2626
uploadSelect: 'انتخاب فایل',
2727
hidden: ' فایل های مخفی',
28+
deleteFile: 'Delete file',
2829
},
2930
clipboard: {
3031
actionType: 'نوع',
@@ -124,6 +125,9 @@ const fa = {
124125
size: 'اندازه:',
125126
skip: 'رد شدن',
126127
title: 'بارگزاری فایل ها',
128+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
129+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
130+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
127131
},
128132
editor: {
129133
title: 'ویرایشگر',

src/lang/fr.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const fr = {
2424
upload: 'Télécharger',
2525
uploadSelect: 'Sélectionner fichiers',
2626
hidden: ' Masquer fichiers',
27+
deleteFile: 'Delete file',
2728
},
2829
clipboard: {
2930
actionType: 'Type',
@@ -123,6 +124,9 @@ const fr = {
123124
size: 'Taille:',
124125
skip: 'Passer',
125126
title: 'Télécharger fichiers',
127+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
128+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
129+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
126130
},
127131
editor: {
128132
title: 'Editeur',

src/lang/it.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const it = {
2525
upload: 'Upload',
2626
uploadSelect: 'Seleziona files',
2727
hidden: ' Files Nascosti',
28+
deleteFile: 'Delete file',
2829
},
2930
clipboard: {
3031
actionType: 'Tipo',
@@ -124,6 +125,9 @@ const it = {
124125
size: 'Dim.:',
125126
skip: 'Salta',
126127
title: 'Carica files',
128+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
129+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
130+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
127131
},
128132
editor: {
129133
title: 'Editor',

src/lang/nl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const nl = {
2626
upload: 'Upload',
2727
uploadSelect: 'Select files',
2828
hidden: ' Verborgen bestanden',
29+
deleteFile: 'Delete file',
2930
},
3031
clipboard: {
3132
actionType: 'Type',
@@ -125,6 +126,9 @@ const nl = {
125126
size: 'Size:',
126127
skip: 'Skip',
127128
title: 'Upload files',
129+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
130+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
131+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
128132
},
129133
editor: {
130134
title: 'Editor',

src/lang/pl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const pl = {
2424
upload: 'Wyślij plik',
2525
uploadSelect: 'Wybierz pliki',
2626
hidden: 'Ukryte pliki',
27+
deleteFile: 'Delete file',
2728
},
2829
clipboard: {
2930
actionType: 'Rodzaj',
@@ -123,6 +124,9 @@ const pl = {
123124
size: 'Rozmiar:',
124125
skip: 'Pomiń',
125126
title: 'Prześlij pliki',
127+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
128+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
129+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
126130
},
127131
editor: {
128132
title: 'Edytor',

src/lang/pt_BR.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const pt_BR = {
2525
upload: 'Upload',
2626
uploadSelect: 'Selecionar arquivos',
2727
hidden: ' Arquivos ocultos',
28+
deleteFile: 'Delete file',
2829
},
2930
clipboard: {
3031
actionType: 'Formato',
@@ -124,6 +125,9 @@ const pt_BR = {
124125
size: 'Tamanho:',
125126
skip: 'Pular',
126127
title: 'Upload de arquivos',
128+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
129+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
130+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
127131
},
128132
editor: {
129133
title: 'Editor',

src/lang/ru.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const ru = {
2424
upload: 'Загрузить',
2525
uploadSelect: 'Выбрать файлы',
2626
hidden: 'Скрытые файлы',
27+
deleteFile: 'Удалить файл',
2728
},
2829
clipboard: {
2930
actionType: 'Тип операции',
@@ -123,6 +124,9 @@ const ru = {
123124
size: 'Размер:',
124125
skip: 'Пропустить',
125126
title: 'Загрузить файлы',
127+
noAllowFileTypes: 'Расширение файла не входит в список разрешенных для загрузки',
128+
noMaxUploadFileSize: 'Превышен максимальный размер загружаемого файла',
129+
noMaxPostSize: 'Превышен максимальный размер загружаемых файлов',
126130
},
127131
editor: {
128132
title: 'Редактор',

src/lang/sr.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const sr = {
2525
upload: 'Upload',
2626
uploadSelect: 'Izaberi datoteke',
2727
hidden: ' Skrivene datoteke',
28+
deleteFile: 'Delete file',
2829
},
2930
clipboard: {
3031
actionType: 'Tip operacije',
@@ -124,6 +125,9 @@ const sr = {
124125
size: 'Veličina:',
125126
skip: 'Preskoči',
126127
title: 'DOdaj fajlove',
128+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
129+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
130+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
127131
},
128132
editor: {
129133
title: 'Editor',

src/lang/tr.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const tr = {
2424
upload: 'Yükle',
2525
uploadSelect: 'Dosyaları seç',
2626
hidden: ' Gizli dosyalar',
27+
deleteFile: 'Delete file',
2728
},
2829
clipboard: {
2930
actionType: 'İşlem türü',
@@ -123,6 +124,9 @@ const tr = {
123124
size: 'Boyut:',
124125
skip: 'Atla',
125126
title: 'Dosyaları yükle',
127+
noAllowFileTypes: 'The file extension is not on the list of allowed uploads',
128+
noMaxUploadFileSize: 'The maximum file upload size has been exceeded',
129+
noMaxPostSize: 'The maximum size of uploaded files has been exceeded',
126130
},
127131
editor: {
128132
title: 'Editör',

0 commit comments

Comments
 (0)