From c2d8662fd875159e1ab37bfa16c84d33fac8bc5d Mon Sep 17 00:00:00 2001 From: Bernd Storath <999999bst@gmail.com> Date: Wed, 12 Feb 2025 14:14:31 +0100 Subject: [PATCH] remove backup / restore --- src/app/components/Clients/BackupConfig.vue | 10 ------ src/app/components/Clients/RestoreConfig.vue | 34 -------------------- src/app/stores/clients.ts | 18 +++++++++-- src/app/utils/api.ts | 24 -------------- src/i18n/locales/en.json | 4 --- src/server/utils/WireGuard.ts | 21 ++---------- 6 files changed, 17 insertions(+), 94 deletions(-) delete mode 100644 src/app/components/Clients/BackupConfig.vue delete mode 100644 src/app/components/Clients/RestoreConfig.vue delete mode 100644 src/app/utils/api.ts diff --git a/src/app/components/Clients/BackupConfig.vue b/src/app/components/Clients/BackupConfig.vue deleted file mode 100644 index 0dd0d1de..00000000 --- a/src/app/components/Clients/BackupConfig.vue +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/src/app/components/Clients/RestoreConfig.vue b/src/app/components/Clients/RestoreConfig.vue deleted file mode 100644 index 67b1286c..00000000 --- a/src/app/components/Clients/RestoreConfig.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - diff --git a/src/app/stores/clients.ts b/src/app/stores/clients.ts index 33431942..d1c621ec 100644 --- a/src/app/stores/clients.ts +++ b/src/app/stores/clients.ts @@ -1,7 +1,14 @@ import { defineStore } from 'pinia'; import { sha256 } from 'js-sha256'; +import type { TypedInternalResponse } from 'nitropack/types'; -export type LocalClient = WGClient & { +type WGClientReturn = TypedInternalResponse< + '/api/client', + unknown, + 'get' +>[number]; + +export type LocalClient = WGClientReturn & { avatar?: string; transferMax?: number; } & Omit; @@ -24,8 +31,13 @@ export const useClientsStore = defineStore('Clients', () => { const clients = ref(null); const clientsPersist = ref>({}); + const { data: _clients, refresh: _refresh } = useFetch('/api/client', { + method: 'get', + }); + + // TODO: rewrite async function refresh({ updateCharts = false } = {}) { - const { data: _clients } = await api.getClients(); + await _refresh(); let transformedClients = _clients.value?.map((client) => { let avatar = undefined; if (client.name.includes('@') && client.name.includes('.')) { @@ -118,5 +130,5 @@ export const useClientsStore = defineStore('Clients', () => { clients.value = transformedClients ?? null; } - return { clients, clientsPersist, refresh }; + return { clients, clientsPersist, refresh, _clients }; }); diff --git a/src/app/utils/api.ts b/src/app/utils/api.ts deleted file mode 100644 index 94b5b47b..00000000 --- a/src/app/utils/api.ts +++ /dev/null @@ -1,24 +0,0 @@ -class API { - async getClients() { - return useFetch('/api/client', { - method: 'get', - }); - } - - async restoreConfiguration(file: string) { - return $fetch('/api/wireguard/restore', { - method: 'put', - body: { file }, - }); - } -} - -type WGClientReturn = Awaited< - ReturnType ->['data']['value']; - -export type WGClient = WGClientReturn extends (infer U)[] | undefined - ? U - : never; - -export default new API(); diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 2ba7387c..2edb235e 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -69,10 +69,6 @@ "light": "Light theme", "system": "System theme" }, - "restore": "Restore", - "backup": "Backup", - "titleRestoreConfig": "Restore your configuration", - "titleBackupConfig": "Backup your configuration", "rememberMe": "Remember me", "titleRememberMe": "Stay logged after closing the browser", "sort": "Sort", diff --git a/src/server/utils/WireGuard.ts b/src/server/utils/WireGuard.ts index 629c03fb..44928695 100644 --- a/src/server/utils/WireGuard.ts +++ b/src/server/utils/WireGuard.ts @@ -135,25 +135,6 @@ class WireGuard { }); } - // TODO: reimplement database restore - async restoreConfiguration(_config: string) { - /* DEBUG('Starting configuration restore process.'); - // TODO: sanitize config - const _config = JSON.parse(config); - await this.__saveConfig(_config); - await this.__reloadConfig(); - DEBUG('Configuration restore process completed.'); */ - } - - // TODO: reimplement database restore - async backupConfiguration() { - /* DEBUG('Starting configuration backup.'); - const config = await this.getConfig(); - const backup = JSON.stringify(config, null, 2); - DEBUG('Configuration backup completed.'); - return backup; */ - } - async Startup() { WG_DEBUG('Starting WireGuard...'); // let as it has to refetch if keys change @@ -253,4 +234,6 @@ Please follow the instructions on https://wg-easy.github.io/wg-easy/ to migrate ); } +// TODO: make static or object + export default new WireGuard();