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
|
// TODO: check what are missing
|
||||
type Client = { |
const clientSchema = z.object({ |
||||
id: string; |
id: z.string(), |
||||
name: string; |
name: z.string(), |
||||
address: string; |
address: z.string(), |
||||
privateKey: string; |
privateKey: z.string(), |
||||
publicKey: string; |
publicKey: z.string(), |
||||
preSharedKey: string; |
preSharedKey: z.string(), |
||||
createdAt: string; |
createdAt: z.string(), |
||||
updatedAt: string; |
updatedAt: z.string(), |
||||
enabled: boolean; |
enabled: z.boolean(), |
||||
}; |
}); |
||||
|
|
||||
type OldConfig = { |
const oldConfigSchema = z.object({ |
||||
server: { |
server: z.object({ |
||||
privateKey: string; |
privateKey: z.string(), |
||||
publicKey: string; |
publicKey: z.string(), |
||||
address: string; |
address: z.string(), |
||||
}; |
}), |
||||
clients: Record<string, Client>; |
clients: z.record(z.string(), clientSchema), |
||||
}; |
}); |
||||
|
|
||||
export default defineEventHandler(async (event) => { |
export default defineEventHandler(async (event) => { |
||||
const { file } = await readValidatedBody(event, validateZod(fileType, 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
|
// TODO: handle migration
|
||||
console.log('file_', file_); |
console.log('zod file_', file_); |
||||
|
|
||||
return { success: true }; |
return { success: true }; |
||||
}); |
}); |
||||
|
Loading…
Reference in new issue