From c657b36292410f176b3781d37fdbe4bd6d93018f Mon Sep 17 00:00:00 2001 From: Anton Schegg Date: Fri, 18 Oct 2024 09:37:31 +0200 Subject: [PATCH] Import started --- src/stores/admin/database.ts | 4 +- src/views/admin/settings/Database.vue | 61 ++++++++++++++++++++------- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/stores/admin/database.ts b/src/stores/admin/database.ts index 6f84045..c6a5d54 100644 --- a/src/stores/admin/database.ts +++ b/src/stores/admin/database.ts @@ -20,7 +20,7 @@ export const useDatabaseStore = defineStore("database", { this.data = result.data; this.status = "success"; }) - .catch((err) => { + .catch(() => { this.status = "failed"; }); }, @@ -29,7 +29,7 @@ export const useDatabaseStore = defineStore("database", { this.status = "working"; const postData = {secret: secret}; const response: AxiosResponse = await http.post("/admin/database", postData); - this.data = response.data; + this.data = response.data.data; this.status = "success"; } catch (ex) { this.status = "failed"; diff --git a/src/views/admin/settings/Database.vue b/src/views/admin/settings/Database.vue index 220f244..3933984 100644 --- a/src/views/admin/settings/Database.vue +++ b/src/views/admin/settings/Database.vue @@ -8,19 +8,24 @@ @@ -40,6 +45,10 @@ import SuccessCheckmark from "@/components/SuccessCheckmark.vue"; export default defineComponent({ data() { return { + dataUrl: '' as string, + dataImport: '' as string, + file: null, + downloadFilename: '' as string, secret: '' as string, }; }, @@ -47,23 +56,43 @@ export default defineComponent({ ...mapState(useDatabaseStore, ["data", "status", "failureReason"]), disabled() : boolean { return this.status === 'working' || this.secret === ''; + }, + uploadDisabled() : boolean { + return this.status === 'working' || this.secret === '' || this.file === null; } }, mounted() { this.secret = '' as string; }, methods: { - ...mapActions(useDatabaseStore, ["export"]), + ...mapActions(useDatabaseStore, ["export", "import"]), + addFile(e) { + this.file = e.target.files[0]; + console.log(this.file); + }, async exportDatabase() { try { - const data = await this.export(this.secret); + if (this.dataUrl) { + this.dataUrl = ''; + } + await this.export(this.secret); + this.dataUrl = 'data:application/octet-stream,' + this.data; + this.downloadFilename = `${new Date().toISOString().replace(/:/g, '-')}_database_export.enc`; } catch(ex) { console.log(ex); } }, - importDatabase() { + onChangeFileUpload() { + }, + async importDatabase() { + try { + await this.import(this.secret, this.dataImport); + } + catch(ex) { + console.log(ex); + } } }, });