File upload working

This commit is contained in:
Rory Powell 2021-11-26 09:51:56 +00:00
parent 71ba024974
commit 41fa958c78
2 changed files with 18 additions and 10 deletions

View File

@ -25,24 +25,29 @@
let lastTouched = "url" let lastTouched = "url"
$: { const getPayload = async () => {
console.log({ data }) let payloadData
console.log({ lastTouched }) 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 { return {
type: lastTouched, type: type,
data: data[lastTouched], data: payloadData,
} }
} }
async function importDatasource() { async function importDatasource() {
try { try {
// Create datasource const resp = await datasources.import(await getPayload())
const resp = await datasources.import(getPayload())
// // update the tables incase data source plus
await queries.fetch() await queries.fetch()
await datasources.select(resp._id) await datasources.select(resp._id)
$goto(`./datasource/${resp._id}`) $goto(`./datasource/${resp._id}`)
@ -82,6 +87,7 @@
</Tab> </Tab>
<Tab title="File"> <Tab title="File">
<Dropzone <Dropzone
gallery={false}
bind:value={data.file} bind:value={data.file}
on:change={() => (lastTouched = "file")} on:change={() => (lastTouched = "file")}
fileTags={["OpenAPI", "Swagger 2.0"]} fileTags={["OpenAPI", "Swagger 2.0"]}

View File

@ -110,6 +110,8 @@ exports.import = async function (ctx) {
data = await fetch(importConfig.data).then(res => res.json()) data = await fetch(importConfig.data).then(res => res.json())
} else if (importConfig.type === "raw") { } else if (importConfig.type === "raw") {
data = JSON.parse(importConfig.data) data = JSON.parse(importConfig.data)
} else {
throw new Error("Invalid data type")
} }
const db = new CouchDB(ctx.appId) const db = new CouchDB(ctx.appId)