File upload working
This commit is contained in:
parent
71ba024974
commit
41fa958c78
|
@ -25,24 +25,29 @@
|
|||
|
||||
let lastTouched = "url"
|
||||
|
||||
$: {
|
||||
console.log({ data })
|
||||
console.log({ lastTouched })
|
||||
const getPayload = async () => {
|
||||
let payloadData
|
||||
let type
|
||||
|
||||
// parse the file into memory and send as string
|
||||
if (lastTouched === "file") {
|
||||
type = "raw"
|
||||
payloadData = await data.file[0].text()
|
||||
} else {
|
||||
type = lastTouched
|
||||
payloadData = data[lastTouched]
|
||||
}
|
||||
|
||||
const getPayload = () => {
|
||||
return {
|
||||
type: lastTouched,
|
||||
data: data[lastTouched],
|
||||
type: type,
|
||||
data: payloadData,
|
||||
}
|
||||
}
|
||||
|
||||
async function importDatasource() {
|
||||
try {
|
||||
// Create datasource
|
||||
const resp = await datasources.import(getPayload())
|
||||
const resp = await datasources.import(await getPayload())
|
||||
|
||||
// // update the tables incase data source plus
|
||||
await queries.fetch()
|
||||
await datasources.select(resp._id)
|
||||
$goto(`./datasource/${resp._id}`)
|
||||
|
@ -82,6 +87,7 @@
|
|||
</Tab>
|
||||
<Tab title="File">
|
||||
<Dropzone
|
||||
gallery={false}
|
||||
bind:value={data.file}
|
||||
on:change={() => (lastTouched = "file")}
|
||||
fileTags={["OpenAPI", "Swagger 2.0"]}
|
||||
|
|
|
@ -110,6 +110,8 @@ exports.import = async function (ctx) {
|
|||
data = await fetch(importConfig.data).then(res => res.json())
|
||||
} else if (importConfig.type === "raw") {
|
||||
data = JSON.parse(importConfig.data)
|
||||
} else {
|
||||
throw new Error("Invalid data type")
|
||||
}
|
||||
|
||||
const db = new CouchDB(ctx.appId)
|
||||
|
|
Loading…
Reference in New Issue