From cee0decfcc3ae10e3f3c3972b90040ab76c422a3 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 15 Mar 2021 18:32:20 +0000 Subject: [PATCH] Remove electron specific app import --- .../src/components/start/CreateAppModal.svelte | 18 ++++++++++++------ .../src/components/start/Steps/Info.svelte | 5 ++--- .../server/src/api/controllers/application.js | 15 ++++++++++----- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index 7f1d73f744..5102179cde 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -123,13 +123,19 @@ async function createNewApp() { submitting = true try { - // Create App - const appResp = await post("/api/applications", { - name: $createAppStore.values.applicationName, - template, - }) - const appJson = await appResp.json() + // Create form data to create app + let data = new FormData() + data.append("name", $createAppStore.values.applicationName) + data.append("useTemplate", template != null) + if (template) { + data.append("templateName", template.name) + data.append("templateKey", template.key) + data.append("templateFile", template.file) + } + // Create App + const appResp = await post("/api/applications", data, {}) + const appJson = await appResp.json() if (!appResp.ok) { throw new Error(appJson.message) } diff --git a/packages/builder/src/components/start/Steps/Info.svelte b/packages/builder/src/components/start/Steps/Info.svelte index e14e327bce..fa74e8b3a0 100644 --- a/packages/builder/src/components/start/Steps/Info.svelte +++ b/packages/builder/src/components/start/Steps/Info.svelte @@ -1,6 +1,5 @@ diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index cba3e6455a..2023385a7f 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -91,7 +91,6 @@ async function getAppUrlIfNotInUse(ctx) { async function createInstance(template) { const appId = generateAppID() - const db = new CouchDB(appId) await db.put({ _id: "_design/database", @@ -106,10 +105,10 @@ async function createInstance(template) { // replicate the template data to the instance DB // this is currently very hard to test, downloading and importing template files /* istanbul ignore next */ - if (template) { + if (template && template.useTemplate === "true") { let dbDumpReadStream - if (template.fileImportPath) { - dbDumpReadStream = fs.createReadStream(template.fileImportPath) + if (template.file) { + dbDumpReadStream = fs.createReadStream(template.file.path) } else { const templatePath = await downloadTemplate(...template.key.split("/")) dbDumpReadStream = fs.createReadStream( @@ -162,8 +161,14 @@ exports.fetchAppPackage = async function(ctx) { } exports.create = async function(ctx) { + const { useTemplate, templateKey } = ctx.request.body + const instance = await createInstance({ + useTemplate, + key: templateKey, + file: ctx.request.files.templateFile, + }) + const url = await getAppUrlIfNotInUse(ctx) - const instance = await createInstance(ctx.request.body.template) const appId = instance._id const version = packageJson.version const newApplication = {