2025-09-21 19:35:41 +01:00
|
|
|
import { Hono } from 'hono';
|
2025-10-29 09:57:29 +01:00
|
|
|
import { TLessonDownloadContent, ZLessonDownloadContent } from '$src/types/course/lesson';
|
2025-09-21 19:35:41 +01:00
|
|
|
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');
|
2025-09-21 19:35:41 +01:00
|
|
|
|
|
|
|
|
const pdfBuffer = await generateLessonPdf(validatedData);
|
|
|
|
|
|
|
|
|
|
c.header('Content-Type', 'application/pdf');
|
|
|
|
|
return c.body(
|
|
|
|
|
new ReadableStream({
|
|
|
|
|
start(controller) {
|
|
|
|
|
controller.enqueue(pdfBuffer);
|
|
|
|
|
controller.close();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|