mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-05 00:52:59 +01:00
Add delete ha backups
This commit is contained in:
parent
d9aace4197
commit
bf67f692cf
@ -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(() => {
|
||||
|
@ -162,6 +162,7 @@ function downloadSnapshot(id: string): Promise<string> {
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
1
nextcloud_backup/frontend/components.d.ts
vendored
1
nextcloud_backup/frontend/components.d.ts
vendored
@ -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']
|
||||
|
@ -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>
|
@ -38,6 +38,7 @@
|
||||
:item="item"
|
||||
:index="index"
|
||||
@upload="upload"
|
||||
@delete="deleteBackup"
|
||||
>
|
||||
</ha-list-item>
|
||||
</v-list>
|
||||
@ -48,6 +49,10 @@
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</div>
|
||||
<ha-delete-dialog
|
||||
ref="deleteDialog"
|
||||
@deleted="refreshBackup"
|
||||
></ha-delete-dialog>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@ -59,8 +64,13 @@ import {
|
||||
} from "@/services/homeAssistantService";
|
||||
import HaListItem from "./HaListItem.vue";
|
||||
import { useAlertStore } from "@/store/alert";
|
||||
import HaDeleteDialog from "./HaDeleteDialog.vue";
|
||||
|
||||
const deleteDialog = ref<InstanceType<typeof HaDeleteDialog> | null>(null);
|
||||
const backups = ref<BackupModel[]>([]);
|
||||
|
||||
const deleteItem = ref<BackupModel | null>(null);
|
||||
|
||||
const loading = ref<boolean>(true);
|
||||
|
||||
const alertStore = useAlertStore();
|
||||
@ -87,9 +97,12 @@ function upload(item: BackupModel) {
|
||||
});
|
||||
}
|
||||
|
||||
function deleteBackup(item: BackupModel) {
|
||||
deleteItem.value = item;
|
||||
deleteDialog.value?.open(item);
|
||||
}
|
||||
|
||||
refreshBackup();
|
||||
|
||||
defineExpose({ refreshBackup });
|
||||
|
||||
// TODO Manage delete
|
||||
</script>
|
||||
|
@ -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}`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user