diff --git a/packages/builder/src/components/start/ImportAppModal.svelte b/packages/builder/src/components/start/ImportAppModal.svelte index 329c8286ca..7496b5824d 100644 --- a/packages/builder/src/components/start/ImportAppModal.svelte +++ b/packages/builder/src/components/start/ImportAppModal.svelte @@ -1,5 +1,7 @@ diff --git a/packages/frontend-core/src/api/app.js b/packages/frontend-core/src/api/app.js index 982066f05a..49137cbecd 100644 --- a/packages/frontend-core/src/api/app.js +++ b/packages/frontend-core/src/api/app.js @@ -1,3 +1,5 @@ +import { sdk } from "@budibase/shared-core" + export const buildAppEndpoints = API => ({ /** * Fetches screen definition for an app. @@ -81,6 +83,22 @@ export const buildAppEndpoints = API => ({ }) }, + /** + * Update an application using an export - the body + * should be of type FormData, with a "file" and a "password" if encrypted. + * @param appId The ID of the app to update - this will always be + * converted to development ID. + * @param body a FormData body with a file and password. + */ + updateAppFromExport: async (appId, body) => { + const devId = sdk.applications.getDevAppID(appId) + return await API.post({ + url: `/api/applications/${devId}/import`, + body, + json: false, + }) + }, + /** * Imports an export of all apps. * @param apps the FormData containing the apps to import diff --git a/packages/server/src/api/controllers/application.ts b/packages/server/src/api/controllers/application.ts index ad6780e61b..a7d3634a89 100644 --- a/packages/server/src/api/controllers/application.ts +++ b/packages/server/src/api/controllers/application.ts @@ -575,7 +575,16 @@ export async function sync(ctx: UserCtx) { } } -export async function updateWithExport(ctx: UserCtx) {} +export async function importToApp(ctx: UserCtx) { + const { appId } = ctx.params + const appExport = ctx.request.files?.appExport + const password = ctx.request.body.encryptionPassword + if (!appExport) { + ctx.throw(400, "Must supply app export to import") + } + console.log(appExport) + ctx.body = { message: "app updated" } +} export async function updateAppPackage(appPackage: any, appId: any) { return context.doInAppContext(appId, async () => { diff --git a/packages/server/src/api/routes/application.ts b/packages/server/src/api/routes/application.ts index aef32ee559..a21d6a2153 100644 --- a/packages/server/src/api/routes/application.ts +++ b/packages/server/src/api/routes/application.ts @@ -4,6 +4,7 @@ import * as deploymentController from "../controllers/deploy" import authorized from "../../middleware/authorized" import { permissions } from "@budibase/backend-core" import { applicationValidator } from "./utils/validators" +import { importToApp } from "../controllers/application" const router: Router = new Router() @@ -59,9 +60,9 @@ router controller.destroy ) .post( - "/api/applications/:appId/update", + "/api/applications/:appId/import", authorized(permissions.BUILDER), - controller.updateWithExport + controller.importToApp ) export default router