mirror of https://github.com/wg-easy/wg-easy
6 changed files with 17 additions and 94 deletions
@ -1,10 +0,0 @@ |
|||||
<template> |
|
||||
<BaseButton |
|
||||
as="a" |
|
||||
href="./api/wireguard/backup" |
|
||||
:title="$t('titleBackupConfig')" |
|
||||
> |
|
||||
<IconsStack class="w-4 md:mr-2" /> |
|
||||
<span class="text-sm max-md:hidden">{{ $t('backup') }}</span> |
|
||||
</BaseButton> |
|
||||
</template> |
|
@ -1,34 +0,0 @@ |
|||||
<template> |
|
||||
<BaseButton as="label" for="inputRC" :title="$t('titleRestoreConfig')"> |
|
||||
<IconsArrowInf class="w-4 md:mr-2" /> |
|
||||
<span class="text-sm max-md:hidden">{{ $t('restore') }}</span> |
|
||||
<input |
|
||||
id="inputRC" |
|
||||
type="file" |
|
||||
name="configurationfile" |
|
||||
accept="text/*,.json" |
|
||||
class="hidden" |
|
||||
@change="restoreConfig" |
|
||||
/> |
|
||||
</BaseButton> |
|
||||
</template> |
|
||||
|
|
||||
<script setup lang="ts"> |
|
||||
function restoreConfig(e: Event) { |
|
||||
e.preventDefault(); |
|
||||
const file = (e.currentTarget as HTMLInputElement).files?.item(0); |
|
||||
if (file) { |
|
||||
file |
|
||||
.text() |
|
||||
.then((content) => { |
|
||||
api |
|
||||
.restoreConfiguration(content) |
|
||||
.then(() => alert('The configuration was updated.')) |
|
||||
.catch((err) => alert(err.message || err.toString())); |
|
||||
}) |
|
||||
.catch((err) => alert(err.message || err.toString())); |
|
||||
} else { |
|
||||
alert('Failed to load your file!'); |
|
||||
} |
|
||||
} |
|
||||
</script> |
|
@ -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<typeof API.prototype.getClients> |
|
||||
>['data']['value']; |
|
||||
|
|
||||
export type WGClient = WGClientReturn extends (infer U)[] | undefined |
|
||||
? U |
|
||||
: never; |
|
||||
|
|
||||
export default new API(); |
|
Loading…
Reference in new issue