e5fb6ff3a6
* fix otls * one otl per client * revert some code * revert some more code, add comments * adjust migration
38 lines
921 B
TypeScript
38 lines
921 B
TypeScript
import { OneTimeLinkGetSchema } from '#db/repositories/oneTimeLink/types';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { oneTimeLink } = await getValidatedRouterParams(
|
|
event,
|
|
validateZod(OneTimeLinkGetSchema, event)
|
|
);
|
|
|
|
const otl = await Database.oneTimeLinks.getByOtl(oneTimeLink);
|
|
if (!otl) {
|
|
throw createError({
|
|
statusCode: 404,
|
|
statusMessage: 'Invalid One Time Link',
|
|
});
|
|
}
|
|
|
|
const client = await Database.clients.get(otl.id);
|
|
if (!client) {
|
|
throw createError({
|
|
statusCode: 404,
|
|
statusMessage: 'Invalid One Time Link',
|
|
});
|
|
}
|
|
|
|
const config = await WireGuard.getClientConfiguration({
|
|
clientId: client.id,
|
|
});
|
|
await Database.oneTimeLinks.erase(otl.id);
|
|
|
|
setHeader(
|
|
event,
|
|
'Content-Disposition',
|
|
`attachment; filename="${client.name}.conf"`
|
|
);
|
|
setHeader(event, 'Content-Type', 'text/plain');
|
|
return config;
|
|
});
|