1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-07 10:38:54 +08:00

#116 JSON file import

This commit is contained in:
lana-k
2024-09-05 22:15:12 +02:00
parent a2464d839f
commit 1b6b7c71e9
13 changed files with 346 additions and 213 deletions

View File

@@ -1,4 +1,10 @@
export default {
isJSON (file) {
return file && file.type === 'application/json'
},
isNDJSON (file) {
return file && file.name.endsWith('.ndjson')
},
isDatabase (file) {
const dbTypes = ['application/vnd.sqlite3', 'application/x-sqlite3']
return file.type
@@ -51,19 +57,20 @@ export default {
},
importFile () {
const reader = new FileReader()
return this.getFileFromUser('.json')
.then(file => {
return new Promise((resolve, reject) => {
reader.onload = e => {
resolve(e.target.result)
}
reader.readAsText(file)
})
return this.getFileContent(file)
})
},
getFileContent (file) {
const reader = new FileReader()
return new Promise(resolve => {
reader.onload = e => resolve(e.target.result)
reader.readAsText(file)
})
},
readFile (path) {
return fetch(path)
},