Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(files): prevent upload if file size is 0 bytes #1756

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion cypress
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