mirror of https://github.com/wg-easy/wg-easy
committed by
Bernd Storath
1 changed files with 23 additions and 21 deletions
@ -1,31 +1,33 @@ |
|||
import { z } from 'zod'; |
|||
|
|||
// TODO: check what are missing
|
|||
type Client = { |
|||
id: string; |
|||
name: string; |
|||
address: string; |
|||
privateKey: string; |
|||
publicKey: string; |
|||
preSharedKey: string; |
|||
createdAt: string; |
|||
updatedAt: string; |
|||
enabled: boolean; |
|||
}; |
|||
const clientSchema = z.object({ |
|||
id: z.string(), |
|||
name: z.string(), |
|||
address: z.string(), |
|||
privateKey: z.string(), |
|||
publicKey: z.string(), |
|||
preSharedKey: z.string(), |
|||
createdAt: z.string(), |
|||
updatedAt: z.string(), |
|||
enabled: z.boolean(), |
|||
}); |
|||
|
|||
type OldConfig = { |
|||
server: { |
|||
privateKey: string; |
|||
publicKey: string; |
|||
address: string; |
|||
}; |
|||
clients: Record<string, Client>; |
|||
}; |
|||
const oldConfigSchema = z.object({ |
|||
server: z.object({ |
|||
privateKey: z.string(), |
|||
publicKey: z.string(), |
|||
address: z.string(), |
|||
}), |
|||
clients: z.record(z.string(), clientSchema), |
|||
}); |
|||
|
|||
export default defineEventHandler(async (event) => { |
|||
const { file } = await readValidatedBody(event, validateZod(fileType, event)); |
|||
const file_ = JSON.parse(file) as OldConfig; |
|||
const file_ = await oldConfigSchema.parseAsync(JSON.parse(file)); |
|||
|
|||
// TODO: handle migration
|
|||
console.log('file_', file_); |
|||
console.log('zod file_', file_); |
|||
|
|||
return { success: true }; |
|||
}); |
|||
|
Loading…
Reference in new issue