Files
classroomio/apps/api/src/routes/course/lesson.ts
T

25 lines
736 B
TypeScript
Raw Normal View History

import { Hono } from 'hono';
2025-10-29 09:57:29 +01:00
import { TLessonDownloadContent, ZLessonDownloadContent } from '$src/types/course/lesson';
import { generateLessonPdf } from '$src/utils/lesson';
import { zValidator } from '@hono/zod-validator';
export const lessonRouter = new Hono().post(
'/download/pdf',
zValidator('json', ZLessonDownloadContent),
async (c) => {
2025-10-29 09:57:29 +01:00
const validatedData = (c.req.valid as (key: 'json') => TLessonDownloadContent)('json');
const pdfBuffer = await generateLessonPdf(validatedData);
c.header('Content-Type', 'application/pdf');
return c.body(
new ReadableStream({
start(controller) {
controller.enqueue(pdfBuffer);
controller.close();
}
})
);
}
);