Browse Source

Merge pull request #3428 from nocodb/fix/gui-v2-import-type

fix(gui-v2): check import file mime types
pull/3434/head
navi 2 years ago committed by GitHub
parent
commit
e0fd8bc76c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      packages/nc-gui-v2/pages/[projectType]/[projectId]/index/index/index.vue

16
packages/nc-gui-v2/pages/[projectType]/[projectId]/index/index/index.vue

@ -20,13 +20,18 @@ type QuickImportTypes = 'excel' | 'json' | 'csv'
const allowedQuickImportTypes = [ const allowedQuickImportTypes = [
// Excel // Excel
'.xls, .xlsx, .xlsm, .ods, .ots', 'application/vnd.ms-excel', // .xls
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // .xlsx
'application/vnd.ms-excel.sheet.macroenabled.12', // .xlsm
'application/vnd.oasis.opendocument.spreadsheet', // .ods
'application/vnd.oasis.opendocument.spreadsheet-template', // .ots
// CSV // CSV
'.csv', 'text/csv',
// JSON // JSON
'.json', 'application/json',
'text/json',
] ]
watch(files, (nextFiles) => nextFiles && onFileSelect(nextFiles), { flush: 'post' }) watch(files, (nextFiles) => nextFiles && onFileSelect(nextFiles), { flush: 'post' })
@ -52,10 +57,11 @@ function onDrop(droppedFiles: File[] | null) {
let fileType: QuickImportTypes | null = null let fileType: QuickImportTypes | null = null
const isValid = allowedQuickImportTypes.some((type) => { const isValid = allowedQuickImportTypes.some((type) => {
const isAllowed = droppedFiles[0].type.replace('/', '.').endsWith(type) const isAllowed = droppedFiles[0].type === type
if (isAllowed) { if (isAllowed) {
fileType = type.replace('.', '') as QuickImportTypes const ext = droppedFiles[0].name.split('.').pop()
fileType = (ext === 'csv' || ext === 'json') ? ext : 'excel' as QuickImportTypes
} }
return isAllowed return isAllowed

Loading…
Cancel
Save