Skip to content

Commit

Permalink
Adicionado validaçao de tamanho de arquivo ao upload
Browse files Browse the repository at this point in the history
  • Loading branch information
urielfcampos committed Jun 3, 2019
1 parent f871bfb commit bb62e55
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions components/importStudents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ export default {
return this.studentsCsv.name !== 'Nenhum arquivo selecionado'
},
validateUpload() {
const { config } = process.env
if (!this.studentsCsv) {
return
}
if (this.studentsCsv.size >= config.MAX_FILE_SIZE) {
this.openErrorNotification(process.env.errors.MAX_FILE_SIZE_EXCEEDED)
this.studentsCsv = new File([''], 'Nenhum arquivo selecionado')
this.hasErrors = true
return
}
if (this.studentsCsv.name.split('.').pop() === 'csv') {
const reader = new FileReader()
reader.readAsText(this.studentsCsv)
reader.onload = e => {
debugger
const validation = this.validateCsv(reader.result)
if (typeof validation === 'string') {
this.openErrorNotification(validation)
Expand Down
2 changes: 2 additions & 0 deletions components/mixins/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const errorsHandler = {
return 'Por favor selecione um arquivo do tipo csv'
case errors.IMPORT_CSV_REGISTRATION_NUMBER_REPEATED:
return 'Arquivo csv com números de matrícula repetidos'
case errors.MAX_FILE_SIZE_EXCEEDED:
return 'Arquivo com tamanho superior a 6MB'
default:
return 'Ocorreu um erro'
}
Expand Down
7 changes: 7 additions & 0 deletions components/studentComboBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,16 @@ export default {
})
},
validateUpload(type) {
const { config } = process.env
if (!this.uploadFile) {
return
}
if (this.uploadFile.size >= config.MAX_FILE_SIZE) {
this.openErrorNotification(process.env.errors.MAX_FILE_SIZE_EXCEEDED)
this.uploadFile = new File([''], 'Nenhum arquivo selecionado')
this.hasErrors = true
return
}
const isPDF = this.uploadFile.name.split('.').pop() === 'pdf'
if (isPDF) {
return this.documentUpload(type)
Expand Down
5 changes: 3 additions & 2 deletions nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const pkg = require('./package')
const errors = require('./shared/errors')
const enums = require('./shared/enums')

const config = require('./shared/config')
module.exports = {
mode: 'spa',

Expand Down Expand Up @@ -65,7 +65,8 @@ module.exports = {
},
env: {
errors,
enums
enums,
config
},

/*
Expand Down
2 changes: 2 additions & 0 deletions shared/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Size in Bytes
exports.MAX_FILE_SIZE = 6291456
1 change: 1 addition & 0 deletions shared/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports.INVALID_PARAMS = 'INVALID_PARAMS'
exports.NOT_FOUND = 'NOT_FOUND'
exports.UPLOAD_FILE_FIELD_MISSING = 'UPLOAD_FILE_FIELD_MISSING'
exports.UPLOAD_FILE_TYPE_INVALID = 'UPLOAD_FILE_TYPE_INVALID'
exports.MAX_FILE_SIZE_EXCEEDED = 'MAX_FILE_SIZE_EXCEEDED'
exports.NOT_FOUND_ROUTE = 'NOT_FOUND_ROUTE'
exports.INVALID_SORT_ARGUMENT = 'INVALID SORT ARGUMENT'
exports.INVALID_ORDER_ARGUMENT = 'INVALID ORDER ARGUMENT'
Expand Down

0 comments on commit bb62e55

Please sign in to comment.