2025-11-24 01:00:50 +01:00
|
|
|
import { Hono } from '@api/utils/hono';
|
|
|
|
|
import { ZLessonDownloadContent } from '@cio/utils/validation/course';
|
2025-11-01 15:49:29 +01:00
|
|
|
import { generateLessonPdf } from '@api/utils/lesson';
|
2025-09-21 19:35:41 +01:00
|
|
|
import { zValidator } from '@hono/zod-validator';
|
|
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
export const lessonRouter = new Hono().post('/download/pdf', zValidator('json', ZLessonDownloadContent), async (c) => {
|
|
|
|
|
const validatedData = c.req.valid('json');
|
2025-09-21 19:35:41 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
const pdfBuffer = await generateLessonPdf(validatedData);
|
2025-09-21 19:35:41 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
c.header('Content-Type', 'application/pdf');
|
|
|
|
|
return c.body(
|
|
|
|
|
new ReadableStream({
|
|
|
|
|
start(controller) {
|
|
|
|
|
controller.enqueue(pdfBuffer);
|
|
|
|
|
controller.close();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|