From e435e76fa9eacd59a1318fdb696fc32948a184e8 Mon Sep 17 00:00:00 2001 From: tetuaoro <65575727+tetuaoro@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:08:58 +0200 Subject: [PATCH] restore: clients --- src/server/api/admin/migration.post.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/server/api/admin/migration.post.ts b/src/server/api/admin/migration.post.ts index 8e37c460..b112c004 100644 --- a/src/server/api/admin/migration.post.ts +++ b/src/server/api/admin/migration.post.ts @@ -1,3 +1,5 @@ +import { parseCidr } from 'cidr-tools'; +import { stringifyIp } from 'ip-bigint'; import { z } from 'zod'; // TODO: check what are missing @@ -26,8 +28,23 @@ export default defineEventHandler(async (event) => { const { file } = await readValidatedBody(event, validateZod(fileType, event)); const file_ = await oldConfigSchema.parseAsync(JSON.parse(file)); - // TODO: handle migration - console.log('zod file_', file_); + for (const [_, value] of Object.entries(file_.clients)) { + // remove the unused field + const { address: _, ...filterValue } = value; + const cidr4 = parseCidr(value.address); + const address4 = stringifyIp({ number: cidr4.start + 0n, version: 4 }); + + await Database.client.create({ + ...filterValue, + address4, + address6: '', + expiresAt: null, + allowedIPs: ['0.0.0.0/0', '::/0'], + oneTimeLink: null, + serverAllowedIPs: [], + persistentKeepalive: 0, + }); + } return { success: true }; });