From 02a2e73c29545cf625db418448f514e390bef9b7 Mon Sep 17 00:00:00 2001 From: SebClem Date: Mon, 22 Jul 2024 14:12:44 +0200 Subject: [PATCH] Add delete ha backups --- .../backend/src/routes/homeAssistant.ts | 11 +++ .../src/services/homeAssistantService.ts | 2 + nextcloud_backup/frontend/components.d.ts | 1 + .../homeAssistant/HaDeleteDialog.vue | 74 +++++++++++++++++++ .../src/components/homeAssistant/HaList.vue | 17 ++++- .../src/services/homeAssistantService.ts | 4 + 6 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 nextcloud_backup/frontend/src/components/homeAssistant/HaDeleteDialog.vue diff --git a/nextcloud_backup/backend/src/routes/homeAssistant.ts b/nextcloud_backup/backend/src/routes/homeAssistant.ts index 62e8b0b..e56eb83 100644 --- a/nextcloud_backup/backend/src/routes/homeAssistant.ts +++ b/nextcloud_backup/backend/src/routes/homeAssistant.ts @@ -31,6 +31,17 @@ homeAssistantRouter.get("/backup/:slug", (req, res) => { }); }); +homeAssistantRouter.delete("/backup/:slug", (req, res) => { + haOsService + .delSnap(req.params.slug) + .then((value) => { + res.json(value.body); + }) + .catch((reason) => { + res.status(500).json(reason); + }); +}); + homeAssistantRouter.post("/backup/:slug/upload", (req, res) => { uploadToCloud(req.params.slug) .then(() => { diff --git a/nextcloud_backup/backend/src/services/homeAssistantService.ts b/nextcloud_backup/backend/src/services/homeAssistantService.ts index f187b74..c9cee72 100644 --- a/nextcloud_backup/backend/src/services/homeAssistantService.ts +++ b/nextcloud_backup/backend/src/services/homeAssistantService.ts @@ -162,6 +162,7 @@ function downloadSnapshot(id: string): Promise { } function delSnap(id: string) { + logger.info(`Deleting Home Assistant backup ${id}`); const option = { headers: { authorization: `Bearer ${token}` }, }; @@ -540,4 +541,5 @@ export { startAddons, stopAddons, uploadSnapshot, + delSnap, }; diff --git a/nextcloud_backup/frontend/components.d.ts b/nextcloud_backup/frontend/components.d.ts index 82f9a10..a498262 100644 --- a/nextcloud_backup/frontend/components.d.ts +++ b/nextcloud_backup/frontend/components.d.ts @@ -22,6 +22,7 @@ declare module 'vue' { CloudList: typeof import('./src/components/cloud/CloudList.vue')['default'] CloudListItem: typeof import('./src/components/cloud/CloudListItem.vue')['default'] ConnectionStatus: typeof import('./src/components/statusBar/ConnectionStatus.vue')['default'] + HaDeleteDialog: typeof import('./src/components/homeAssistant/HaDeleteDialog.vue')['default'] HaList: typeof import('./src/components/homeAssistant/HaList.vue')['default'] HaListItem: typeof import('./src/components/homeAssistant/HaListItem.vue')['default'] HaListItemContent: typeof import('./src/components/homeAssistant/HaListItemContent.vue')['default'] diff --git a/nextcloud_backup/frontend/src/components/homeAssistant/HaDeleteDialog.vue b/nextcloud_backup/frontend/src/components/homeAssistant/HaDeleteDialog.vue new file mode 100644 index 0000000..6a8cdf6 --- /dev/null +++ b/nextcloud_backup/frontend/src/components/homeAssistant/HaDeleteDialog.vue @@ -0,0 +1,74 @@ + + + diff --git a/nextcloud_backup/frontend/src/components/homeAssistant/HaList.vue b/nextcloud_backup/frontend/src/components/homeAssistant/HaList.vue index 00e8952..9b86a0b 100644 --- a/nextcloud_backup/frontend/src/components/homeAssistant/HaList.vue +++ b/nextcloud_backup/frontend/src/components/homeAssistant/HaList.vue @@ -38,6 +38,7 @@ :item="item" :index="index" @upload="upload" + @delete="deleteBackup" > @@ -48,6 +49,10 @@ + diff --git a/nextcloud_backup/frontend/src/services/homeAssistantService.ts b/nextcloud_backup/frontend/src/services/homeAssistantService.ts index c99dcba..b84e1aa 100644 --- a/nextcloud_backup/frontend/src/services/homeAssistantService.ts +++ b/nextcloud_backup/frontend/src/services/homeAssistantService.ts @@ -25,3 +25,7 @@ export function getBackupDetail(slug: string) { export function uploadHomeAssistantBackup(slug: string) { return kyClient.post(`homeAssistant/backup/${slug}/upload`); } + +export function deleteHomeAssistantBackup(slug: string) { + return kyClient.delete(`homeAssistant/backup/${slug}`); +}