Browse Source

add: migration server

pull/1397/head
tetuaoro 6 months ago
committed by Bernd Storath
parent
commit
82ddb53101
  1. 7
      src/app/components/setup/migration.vue
  2. 10
      src/app/stores/setup.ts
  3. 9
      src/app/utils/api.ts
  4. 0
      src/server/api/admin/hostport.post.ts
  5. 9
      src/server/api/admin/migration.post.ts
  6. 7
      src/server/utils/types.ts

7
src/app/components/setup/migration.vue

@ -13,7 +13,7 @@
<script setup lang="ts">
import { FetchError } from 'ofetch';
// const setupStore = useSetupStore();
const setupStore = useSetupStore();
const { t } = useI18n();
const emit = defineEmits(['validated']);
@ -35,8 +35,11 @@ function onChangeFile(evt: Event) {
const target = evt.target as HTMLInputElement;
const file = target.files?.[0];
console.log('file', file);
if (file) {
backupFile.value = file;
console.log('backupFile.value', backupFile.value);
}
}
@ -50,7 +53,7 @@ async function sendFile() {
}
try {
// TODO: handle migration
await setupStore.runMigration(backupFile.value);
emit('validated', null);
} catch (error) {
if (error instanceof FetchError) {

10
src/app/stores/setup.ts

@ -17,5 +17,13 @@ export const useSetupStore = defineStore('Setup', () => {
return response.success;
}
return { signup, updateHostPort };
/**
* @throws if unsuccessful
*/
async function runMigration(file: File) {
const response = await api.setupMigration({ file });
return response.success;
}
return { signup, updateHostPort, runMigration };
});

9
src/app/utils/api.ts

@ -138,11 +138,18 @@ class API {
}
async setupHostPort({ host, port }: { host: string; port: number }) {
return $fetch('/api/wireguard/clients/hostport', {
return $fetch('/api/admin/hostport', {
method: 'post',
body: { host, port },
});
}
async setupMigration({ file }: { file: File }) {
return $fetch('/api/admin/migration', {
method: 'post',
body: { file },
});
}
}
type WGClientReturn = Awaited<

0
src/server/api/wireguard/clients/hostport.post.ts → src/server/api/admin/hostport.post.ts

9
src/server/api/admin/migration.post.ts

@ -0,0 +1,9 @@
export default defineEventHandler(async (event) => {
const { file } = await readValidatedBody(
event,
validateZod(fileType_, event)
);
// TODO: handle migration
console.log('fileType_', file);
return { success: true };
});

7
src/server/utils/types.ts

@ -22,6 +22,7 @@ const name = z
.pipe(safeStringRefine);
const file = z.string({ message: 'zod.file' }).pipe(safeStringRefine);
const file_ = z.instanceof(File, { message: 'zod.file' });
const username = z
.string({ message: 'zod.username' })
@ -146,6 +147,12 @@ export const fileType = z.object(
},
{ message: objectMessage }
);
export const fileType_ = z.object(
{
file: file_,
},
{ message: objectMessage }
);
export const credentialsType = z.object(
{

Loading…
Cancel
Save