Browse Source

File upload working

master
Rory Powell 5 years ago
parent
commit
25fd268dd4
  1. 26
      packages/builder/src/components/backend/DatasourceNavigator/modals/ImportRestDatasourceModal.svelte
  2. 2
      packages/server/src/api/controllers/query.js

26
packages/builder/src/components/backend/DatasourceNavigator/modals/ImportRestDatasourceModal.svelte

@ -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"]}

2
packages/server/src/api/controllers/query.js

@ -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…
Cancel
Save