Browse Source

File upload working

master
Rory Powell 5 years ago
parent
commit
41fa958c78
  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" 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"]}

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()) 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)

Loading…
Cancel
Save