Skip to content

Commit

Permalink
feat(files): prevent upload if file size is 0 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmcg committed Mar 1, 2022
1 parent 494b98e commit 11b36b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
20 changes: 13 additions & 7 deletions components/views/files/controls/Controls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ export default Vue.extend({
const originalFiles: File[] = [...event.target.files]
// todo - for now, index is stored in the bucket. we could try moving it to the thread, then sat.json wouldn't be reserved
const protectedNameFiles: File[] = originalFiles.filter(
const protectedNameResults: File[] = originalFiles.filter(
(file) => !(file.name === 'sat.json'),
)
const sameNameResults: File[] = protectedNameFiles.filter(
(file: File) => {
return !this.$FileSystem.hasChild(file.name)
},
// filter out files with 0 bytes size
const emptyFileResults: File[] = protectedNameResults.filter(
(file) => !(file.size === 0),
)
// filter out files with the same name as another file
const sameNameResults: File[] = emptyFileResults.filter((file) => {
return !this.$FileSystem.hasChild(file.name)
})
const nsfwResults: Promise<{ file: File; nsfw: boolean }>[] =
sameNameResults.map(async (file: File) => {
// todo - fix with AP-807. don't scan large files to prevent crash
Expand Down Expand Up @@ -149,10 +152,13 @@ export default Vue.extend({
this.$emit('forceRender')
if (protectedNameFiles.length !== originalFiles.length) {
if (originalFiles.length !== protectedNameResults.length) {
this.errors.push(this.$t('pages.files.errors.reserved_name') as string)
}
if (sameNameResults.length !== protectedNameFiles.length) {
if (protectedNameResults.length !== emptyFileResults.length) {
this.errors.push(this.$t('pages.files.errors.empty_file') as string)
}
if (emptyFileResults.length !== sameNameResults.length) {
this.errors.push(this.$t('pages.files.errors.file_name') as string)
}
if (nsfwResults.length !== files.length) {
Expand Down
1 change: 1 addition & 0 deletions locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export default {
},
errors: {
reserved_name: 'sat.json is a reserved file name',
empty_file: 'File needs to have a size of 1 byte or greater',
file_name: 'File with name already exists in this file system',
},
},
Expand Down

0 comments on commit 11b36b0

Please sign in to comment.