backup read, upload and restore
This commit is contained in:
parent
e5cb8fecc6
commit
f8fb222ebb
13 changed files with 555 additions and 8 deletions
|
@ -133,6 +133,7 @@ export const useNavigationStore = defineStore("navigation", {
|
|||
...(abilityStore.can("read", "user", "user") ? [{ key: "user", title: "Benutzer" }] : []),
|
||||
...(abilityStore.can("read", "user", "role") ? [{ key: "role", title: "Rollen" }] : []),
|
||||
...(abilityStore.can("read", "user", "webapi") ? [{ key: "webapi", title: "Webapi-Token" }] : []),
|
||||
...(abilityStore.can("read", "user", "backup") ? [{ key: "backup", title: "Backups" }] : []),
|
||||
],
|
||||
},
|
||||
} as navigationModel;
|
||||
|
|
56
src/stores/admin/user/backup.ts
Normal file
56
src/stores/admin/user/backup.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { http } from "@/serverCom";
|
||||
import type { AxiosResponse, AxiosProgressEvent } from "axios";
|
||||
import type { BackupRestoreViewModel } from "../../../viewmodels/admin/user/backup.models";
|
||||
|
||||
export const useBackupStore = defineStore("backup", {
|
||||
state: () => {
|
||||
return {
|
||||
backups: [] as Array<string>,
|
||||
loading: null as null | "loading" | "success" | "failed",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
fetchBackups() {
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get("/admin/backup")
|
||||
.then((result) => {
|
||||
this.backups = result.data;
|
||||
this.loading = "success";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
fetchBackupById(filename: string): Promise<AxiosResponse<any, any>> {
|
||||
return http.get(`/admin/backup/${filename}`);
|
||||
},
|
||||
async triggerBackupCreate(): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.post("/admin/backup");
|
||||
this.fetchBackups();
|
||||
return result;
|
||||
},
|
||||
async restoreBackup(backup: BackupRestoreViewModel): Promise<AxiosResponse<any, any>> {
|
||||
return await http.post("/admin/backup/restore", backup);
|
||||
},
|
||||
async uploadBackup(file: File): Promise<AxiosResponse<any, any>> {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
|
||||
const options = {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
onUploadProgress: (progressEvent: AxiosProgressEvent) => {
|
||||
const { loaded, total = 1 } = progressEvent;
|
||||
console.log("progress", Math.floor((loaded * 100) / total));
|
||||
},
|
||||
};
|
||||
|
||||
const result = await http.post("/admin/backup/upload", formData, options);
|
||||
this.fetchBackups();
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue