Add delete ha backups

This commit is contained in:
SebClem 2024-07-22 14:12:44 +02:00
parent e94f767e93
commit 02a2e73c29
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
6 changed files with 107 additions and 2 deletions

View File

@ -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) => { homeAssistantRouter.post("/backup/:slug/upload", (req, res) => {
uploadToCloud(req.params.slug) uploadToCloud(req.params.slug)
.then(() => { .then(() => {

View File

@ -162,6 +162,7 @@ function downloadSnapshot(id: string): Promise<string> {
} }
function delSnap(id: string) { function delSnap(id: string) {
logger.info(`Deleting Home Assistant backup ${id}`);
const option = { const option = {
headers: { authorization: `Bearer ${token}` }, headers: { authorization: `Bearer ${token}` },
}; };
@ -540,4 +541,5 @@ export {
startAddons, startAddons,
stopAddons, stopAddons,
uploadSnapshot, uploadSnapshot,
delSnap,
}; };

View File

@ -22,6 +22,7 @@ declare module 'vue' {
CloudList: typeof import('./src/components/cloud/CloudList.vue')['default'] CloudList: typeof import('./src/components/cloud/CloudList.vue')['default']
CloudListItem: typeof import('./src/components/cloud/CloudListItem.vue')['default'] CloudListItem: typeof import('./src/components/cloud/CloudListItem.vue')['default']
ConnectionStatus: typeof import('./src/components/statusBar/ConnectionStatus.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'] HaList: typeof import('./src/components/homeAssistant/HaList.vue')['default']
HaListItem: typeof import('./src/components/homeAssistant/HaListItem.vue')['default'] HaListItem: typeof import('./src/components/homeAssistant/HaListItem.vue')['default']
HaListItemContent: typeof import('./src/components/homeAssistant/HaListItemContent.vue')['default'] HaListItemContent: typeof import('./src/components/homeAssistant/HaListItemContent.vue')['default']

View File

@ -0,0 +1,74 @@
<template>
<div>
<v-dialog
v-model="dialog"
:width="width"
:fullscreen="isFullScreen"
:persistent="loading"
>
<v-card>
<v-card-title class="d-flex align-center">
<v-icon color="red" class="mr-2">mdi-trash-can</v-icon> Delete Home
Assistant backup
</v-card-title>
<v-divider></v-divider>
<v-card-text>
Delete <v-code tag="code">{{ item?.name }}</v-code> backup in Home
Assistant ?
</v-card-text>
<v-divider></v-divider>
<v-card-actions class="justify-end">
<v-btn color="success" @click="dialog = false" :disabled="loading">
Close
</v-btn>
<v-btn color="red" @click="confirm()" :loading="loading">
<v-icon>mdi-trash-can</v-icon> Delete
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</div>
</template>
<script setup lang="ts">
import { useMenuSize } from "@/composable/menuSize";
import { deleteHomeAssistantBackup } from "@/services/homeAssistantService";
import { deleteWebdabBackup } from "@/services/webdavService";
import { useAlertStore } from "@/store/alert";
import { BackupModel } from "@/types/homeAssistant";
import { ref } from "vue";
const dialog = ref(false);
const loading = ref(false);
const item = ref<BackupModel | null>(null);
const { width, isFullScreen } = useMenuSize();
const emit = defineEmits<{
(e: "deleted"): void;
}>();
const alertStore = useAlertStore();
function confirm() {
loading.value = true;
if (item.value) {
deleteHomeAssistantBackup(item.value.slug)
.then(() => {
loading.value = false;
dialog.value = false;
alertStore.add("success", "Backup deleted from Home Assistant");
emit("deleted");
})
.catch(() => {
loading.value = false;
alertStore.add("error", "Fail to deleted backup from Home Assistant");
});
}
}
function open(value: BackupModel) {
item.value = value;
dialog.value = true;
}
defineExpose({ open });
</script>

View File

@ -38,6 +38,7 @@
:item="item" :item="item"
:index="index" :index="index"
@upload="upload" @upload="upload"
@delete="deleteBackup"
> >
</ha-list-item> </ha-list-item>
</v-list> </v-list>
@ -48,6 +49,10 @@
</v-card-text> </v-card-text>
</v-card> </v-card>
</div> </div>
<ha-delete-dialog
ref="deleteDialog"
@deleted="refreshBackup"
></ha-delete-dialog>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -59,8 +64,13 @@ import {
} from "@/services/homeAssistantService"; } from "@/services/homeAssistantService";
import HaListItem from "./HaListItem.vue"; import HaListItem from "./HaListItem.vue";
import { useAlertStore } from "@/store/alert"; import { useAlertStore } from "@/store/alert";
import HaDeleteDialog from "./HaDeleteDialog.vue";
const deleteDialog = ref<InstanceType<typeof HaDeleteDialog> | null>(null);
const backups = ref<BackupModel[]>([]); const backups = ref<BackupModel[]>([]);
const deleteItem = ref<BackupModel | null>(null);
const loading = ref<boolean>(true); const loading = ref<boolean>(true);
const alertStore = useAlertStore(); const alertStore = useAlertStore();
@ -87,9 +97,12 @@ function upload(item: BackupModel) {
}); });
} }
function deleteBackup(item: BackupModel) {
deleteItem.value = item;
deleteDialog.value?.open(item);
}
refreshBackup(); refreshBackup();
defineExpose({ refreshBackup }); defineExpose({ refreshBackup });
// TODO Manage delete
</script> </script>

View File

@ -25,3 +25,7 @@ export function getBackupDetail(slug: string) {
export function uploadHomeAssistantBackup(slug: string) { export function uploadHomeAssistantBackup(slug: string) {
return kyClient.post(`homeAssistant/backup/${slug}/upload`); return kyClient.post(`homeAssistant/backup/${slug}/upload`);
} }
export function deleteHomeAssistantBackup(slug: string) {
return kyClient.delete(`homeAssistant/backup/${slug}`);
}