2025-11-24 01:00:50 +01:00
|
|
|
import { ZCertificateDownload, ZCourseDownloadContent } from '@cio/utils/validation/course';
|
2025-11-01 15:49:29 +01:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
import { Hono } from '@api/utils/hono';
|
|
|
|
|
import { cloneRouter } from '@api/routes/course/clone';
|
2025-11-01 15:49:29 +01:00
|
|
|
import { generateCertificate } from '@api/utils/certificate';
|
|
|
|
|
import { generateCoursePdf } from '@api/utils/course';
|
|
|
|
|
import { katexRouter } from '@api/routes/course/katex';
|
|
|
|
|
import { lessonRouter } from '@api/routes/course/lesson';
|
|
|
|
|
import { presignRouter } from '@api/routes/course/presign';
|
2025-09-21 19:35:41 +01:00
|
|
|
import { zValidator } from '@hono/zod-validator';
|
|
|
|
|
|
|
|
|
|
export const courseRouter = new Hono()
|
|
|
|
|
.post('/download/certificate', zValidator('json', ZCertificateDownload), async (c) => {
|
2025-11-24 01:00:50 +01:00
|
|
|
const validatedData = c.req.valid('json');
|
2025-09-21 19:35:41 +01:00
|
|
|
|
|
|
|
|
const result = await generateCertificate(validatedData);
|
|
|
|
|
|
|
|
|
|
c.header('Content-Type', 'application/pdf');
|
2025-11-24 01:00:50 +01:00
|
|
|
c.header('Content-Disposition', `attachment; filename="certificate-${validatedData.courseName}.pdf"`);
|
2025-09-21 19:35:41 +01:00
|
|
|
|
|
|
|
|
return c.body(
|
|
|
|
|
new ReadableStream({
|
|
|
|
|
start(controller) {
|
|
|
|
|
controller.enqueue(result);
|
|
|
|
|
controller.close();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
.post('/download/content', zValidator('json', ZCourseDownloadContent), async (c) => {
|
2025-11-24 01:00:50 +01:00
|
|
|
const validatedData = c.req.valid('json');
|
2025-09-21 19:35:41 +01:00
|
|
|
|
|
|
|
|
const pdfBuffer = await generateCoursePdf(validatedData);
|
|
|
|
|
|
|
|
|
|
c.header('Content-Type', 'application/pdf');
|
|
|
|
|
|
|
|
|
|
return c.body(
|
|
|
|
|
new ReadableStream({
|
|
|
|
|
start(controller) {
|
|
|
|
|
controller.enqueue(pdfBuffer);
|
|
|
|
|
controller.close();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
.route('/katex', katexRouter)
|
|
|
|
|
.route('/lesson', lessonRouter)
|
2025-10-29 09:57:29 +01:00
|
|
|
.route('/presign', presignRouter)
|
|
|
|
|
.route('/clone', cloneRouter);
|