Browse Source

restore: clients

pull/1397/head
tetuaoro 7 months ago
committed by Bernd Storath
parent
commit
e435e76fa9
  1. 21
      src/server/api/admin/migration.post.ts

21
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'; import { z } from 'zod';
// TODO: check what are missing // 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 readValidatedBody(event, validateZod(fileType, event));
const file_ = await oldConfigSchema.parseAsync(JSON.parse(file)); const file_ = await oldConfigSchema.parseAsync(JSON.parse(file));
// TODO: handle migration for (const [_, value] of Object.entries(file_.clients)) {
console.log('zod file_', file_); // 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 }; return { success: true };
}); });

Loading…
Cancel
Save