Files
classroomio/apps/api/src/routes/course/section.ts
T
Rotimi Best d5b07d356e feat: HLS streaming, transcripts, agent course generation & landing-page course previews (#663)
New features:
- HLS video encoding/streaming (hls routes, hls-encoder) and a media
  transcripts pipeline (transcripts route + media-transcript queries)
- AI assistant chat vs. run model: agent-course-generation worker/queue,
  run-monitor pane, chat-changes card, content ask-ai bar
- Per-theme course-page previews across org landing-page themes (bold,
  classic, corporate, editorial, etc.) with a shared course token/component set
- View-as-student mode and login-link / link-invite invite flows

Refactor:
- Extract packages/core consolidating config (env, storage, dashboard-url),
  services and utils previously duplicated under apps/api/src/config
- Remove legacy agent service modules (chat-tools, chat-context,
  context-window, document, fetch-url, lesson-content)
- Relax Cross-Origin-Resource-Policy to allow cross-origin media embedding
- Add format script to tenant-router so turbo run format covers it
2026-06-07 18:43:05 +01:00

98 lines
3.0 KiB
TypeScript

import { Hono } from '@api/utils/hono';
import { authMiddleware } from '@api/middlewares/auth';
import { courseMemberMiddleware } from '@api/middlewares/course-member';
import { handleError } from '@api/utils/errors';
import {
createCourseSection,
deleteCourseSectionService,
promoteUngroupedSection,
reorderCourseSections,
updateCourseSectionService
} from '@cio/core/services/course/section';
import {
ZCourseSectionCreate,
ZCourseSectionGetParam,
ZCourseSectionPromoteUngrouped,
ZCourseSectionReorder,
ZCourseSectionUpdate
} from '@cio/utils/validation/course/section';
import { zValidator } from '@hono/zod-validator';
export const sectionRouter = new Hono()
.post('/', authMiddleware, courseMemberMiddleware, zValidator('json', ZCourseSectionCreate), async (c) => {
try {
const courseId = c.req.param('courseId')!;
const data = c.req.valid('json');
const section = await createCourseSection(courseId, { ...data, courseId });
return c.json({ success: true, data: section }, 201);
} catch (error) {
return handleError(c, error, 'Failed to create course section');
}
})
.post(
'/promote-ungrouped',
authMiddleware,
courseMemberMiddleware,
zValidator('json', ZCourseSectionPromoteUngrouped),
async (c) => {
try {
const courseId = c.req.param('courseId')!;
const data = c.req.valid('json');
const result = await promoteUngroupedSection(courseId, data);
return c.json({ success: true, data: result }, 201);
} catch (error) {
return handleError(c, error, 'Failed to promote ungrouped section');
}
}
)
.put(
'/:sectionId',
authMiddleware,
courseMemberMiddleware,
zValidator('param', ZCourseSectionGetParam),
zValidator('json', ZCourseSectionUpdate),
async (c) => {
try {
const { sectionId } = c.req.valid('param');
const data = c.req.valid('json');
const section = await updateCourseSectionService(sectionId, data);
return c.json({ success: true, data: section }, 200);
} catch (error) {
return handleError(c, error, 'Failed to update course section');
}
}
)
.delete(
'/:sectionId',
authMiddleware,
courseMemberMiddleware,
zValidator('param', ZCourseSectionGetParam),
async (c) => {
try {
const { sectionId } = c.req.valid('param');
const section = await deleteCourseSectionService(sectionId);
return c.json({ success: true, data: section }, 200);
} catch (error) {
return handleError(c, error, 'Failed to delete course section');
}
}
)
.post('/reorder', authMiddleware, courseMemberMiddleware, zValidator('json', ZCourseSectionReorder), async (c) => {
try {
const { sections } = c.req.valid('json');
const updated = await reorderCourseSections(sections);
return c.json({ success: true, data: updated }, 200);
} catch (error) {
return handleError(c, error, 'Failed to reorder course sections');
}
});