@hed-hog/lms 0.0.364 → 0.0.365
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bitcode-wallet/bitcode-wallet.service.d.ts +1 -0
- package/dist/bitcode-wallet/bitcode-wallet.service.d.ts.map +1 -1
- package/dist/bitcode-wallet/bitcode-wallet.service.js +22 -3
- package/dist/bitcode-wallet/bitcode-wallet.service.js.map +1 -1
- package/dist/course/course-export-scorm12-worker.service.d.ts +21 -0
- package/dist/course/course-export-scorm12-worker.service.d.ts.map +1 -0
- package/dist/course/course-export-scorm12-worker.service.js +109 -0
- package/dist/course/course-export-scorm12-worker.service.js.map +1 -0
- package/dist/course/course-export-scorm12.service.d.ts +42 -0
- package/dist/course/course-export-scorm12.service.d.ts.map +1 -0
- package/dist/course/course-export-scorm12.service.js +628 -0
- package/dist/course/course-export-scorm12.service.js.map +1 -0
- package/dist/course/course-export.service.d.ts +84 -0
- package/dist/course/course-export.service.d.ts.map +1 -0
- package/dist/course/course-export.service.js +237 -0
- package/dist/course/course-export.service.js.map +1 -0
- package/dist/course/course-structure.controller.d.ts +17 -9
- package/dist/course/course-structure.controller.d.ts.map +1 -1
- package/dist/course/course-structure.controller.js +17 -4
- package/dist/course/course-structure.controller.js.map +1 -1
- package/dist/course/course-structure.service.d.ts +12 -4
- package/dist/course/course-structure.service.d.ts.map +1 -1
- package/dist/course/course-structure.service.js +98 -23
- package/dist/course/course-structure.service.js.map +1 -1
- package/dist/course/course-video-hls.service.d.ts +57 -0
- package/dist/course/course-video-hls.service.d.ts.map +1 -0
- package/dist/course/course-video-hls.service.js +767 -0
- package/dist/course/course-video-hls.service.js.map +1 -0
- package/dist/course/course.controller.d.ts +45 -13
- package/dist/course/course.controller.d.ts.map +1 -1
- package/dist/course/course.controller.js +40 -26
- package/dist/course/course.controller.js.map +1 -1
- package/dist/course/course.mcp-tools.js +1 -1
- package/dist/course/course.mcp-tools.js.map +1 -1
- package/dist/course/course.module.d.ts.map +1 -1
- package/dist/course/course.module.js +11 -0
- package/dist/course/course.module.js.map +1 -1
- package/dist/course/course.service.d.ts +6 -9
- package/dist/course/course.service.d.ts.map +1 -1
- package/dist/course/course.service.js +57 -48
- package/dist/course/course.service.js.map +1 -1
- package/dist/course/dto/cleanup-course-storage.dto.d.ts +1 -1
- package/dist/course/dto/cleanup-course-storage.dto.d.ts.map +1 -1
- package/dist/course/dto/cleanup-course-storage.dto.js +1 -0
- package/dist/course/dto/cleanup-course-storage.dto.js.map +1 -1
- package/dist/course/dto/cleanup-upload-history.dto.d.ts +1 -1
- package/dist/course/dto/cleanup-upload-history.dto.d.ts.map +1 -1
- package/dist/course/dto/cleanup-upload-history.dto.js +1 -1
- package/dist/course/dto/cleanup-upload-history.dto.js.map +1 -1
- package/dist/course/dto/create-course-bulk-job.dto.d.ts +2 -1
- package/dist/course/dto/create-course-bulk-job.dto.d.ts.map +1 -1
- package/dist/course/dto/create-course-bulk-job.dto.js +6 -1
- package/dist/course/dto/create-course-bulk-job.dto.js.map +1 -1
- package/dist/course/dto/create-course-export.dto.d.ts +14 -0
- package/dist/course/dto/create-course-export.dto.d.ts.map +1 -0
- package/dist/course/dto/create-course-export.dto.js +71 -0
- package/dist/course/dto/create-course-export.dto.js.map +1 -0
- package/dist/course/dto/create-course-structure-lesson.dto.d.ts +2 -2
- package/dist/course/dto/create-course-structure-lesson.dto.d.ts.map +1 -1
- package/dist/course/dto/create-course-structure-lesson.dto.js +3 -2
- package/dist/course/dto/create-course-structure-lesson.dto.js.map +1 -1
- package/dist/course/lms-bulk-upload-automation.service.d.ts +16 -1
- package/dist/course/lms-bulk-upload-automation.service.d.ts.map +1 -1
- package/dist/course/lms-bulk-upload-automation.service.js +102 -8
- package/dist/course/lms-bulk-upload-automation.service.js.map +1 -1
- package/dist/course/lms-bulk-upload-infra.service.d.ts +1 -0
- package/dist/course/lms-bulk-upload-infra.service.d.ts.map +1 -1
- package/dist/course/lms-bulk-upload-infra.service.js +32 -8
- package/dist/course/lms-bulk-upload-infra.service.js.map +1 -1
- package/dist/course/lms-bulk-upload.controller.d.ts +30 -3
- package/dist/course/lms-bulk-upload.controller.d.ts.map +1 -1
- package/dist/course/lms-bulk-upload.controller.js +43 -2
- package/dist/course/lms-bulk-upload.controller.js.map +1 -1
- package/dist/course/lms-bulk-upload.service.d.ts +11 -0
- package/dist/course/lms-bulk-upload.service.d.ts.map +1 -1
- package/dist/course/lms-bulk-upload.service.js +59 -6
- package/dist/course/lms-bulk-upload.service.js.map +1 -1
- package/dist/course/lms-setting.controller.d.ts +2 -1
- package/dist/course/lms-setting.controller.d.ts.map +1 -1
- package/dist/course/lms-setting.controller.js +4 -2
- package/dist/course/lms-setting.controller.js.map +1 -1
- package/dist/course/scorm12-schemas.d.ts +4 -0
- package/dist/course/scorm12-schemas.d.ts.map +1 -0
- package/dist/course/scorm12-schemas.js +9 -0
- package/dist/course/scorm12-schemas.js.map +1 -0
- package/dist/enterprise/training/training-student.service.d.ts +51 -0
- package/dist/enterprise/training/training-student.service.d.ts.map +1 -1
- package/dist/enterprise/training/training-student.service.js +217 -4
- package/dist/enterprise/training/training-student.service.js.map +1 -1
- package/dist/evaluation/evaluation.service.d.ts +18 -0
- package/dist/evaluation/evaluation.service.d.ts.map +1 -1
- package/dist/evaluation/evaluation.service.js +125 -0
- package/dist/evaluation/evaluation.service.js.map +1 -1
- package/dist/exam/dto/create-standalone-question.dto.d.ts +12 -0
- package/dist/exam/dto/create-standalone-question.dto.d.ts.map +1 -0
- package/dist/exam/dto/create-standalone-question.dto.js +70 -0
- package/dist/exam/dto/create-standalone-question.dto.js.map +1 -0
- package/dist/exam/exam.module.d.ts.map +1 -1
- package/dist/exam/exam.module.js +2 -1
- package/dist/exam/exam.module.js.map +1 -1
- package/dist/exam/exam.service.d.ts +21 -0
- package/dist/exam/exam.service.d.ts.map +1 -1
- package/dist/exam/exam.service.js +80 -0
- package/dist/exam/exam.service.js.map +1 -1
- package/dist/exam/question.controller.d.ts +27 -0
- package/dist/exam/question.controller.d.ts.map +1 -0
- package/dist/exam/question.controller.js +53 -0
- package/dist/exam/question.controller.js.map +1 -0
- package/dist/lesson-xp-map/lesson-xp-ai-calculation.service.d.ts +4 -0
- package/dist/lesson-xp-map/lesson-xp-ai-calculation.service.d.ts.map +1 -1
- package/dist/lesson-xp-map/lesson-xp-ai-calculation.service.js +161 -25
- package/dist/lesson-xp-map/lesson-xp-ai-calculation.service.js.map +1 -1
- package/dist/libraries/lms/tsconfig.tsbuildinfo +1 -1
- package/dist/lms-commerce-access.subscriber.d.ts +11 -0
- package/dist/lms-commerce-access.subscriber.d.ts.map +1 -0
- package/dist/lms-commerce-access.subscriber.js +74 -0
- package/dist/lms-commerce-access.subscriber.js.map +1 -0
- package/dist/lms.module.d.ts.map +1 -1
- package/dist/lms.module.js +6 -5
- package/dist/lms.module.js.map +1 -1
- package/dist/platforma/platforma-video.service.d.ts +39 -0
- package/dist/platforma/platforma-video.service.d.ts.map +1 -0
- package/dist/platforma/platforma-video.service.js +301 -0
- package/dist/platforma/platforma-video.service.js.map +1 -0
- package/dist/platforma/platforma.controller.d.ts +95 -1
- package/dist/platforma/platforma.controller.d.ts.map +1 -1
- package/dist/platforma/platforma.controller.js +160 -2
- package/dist/platforma/platforma.controller.js.map +1 -1
- package/dist/student-xp/dto/grant-skill-card-xp.dto.d.ts +5 -0
- package/dist/student-xp/dto/grant-skill-card-xp.dto.d.ts.map +1 -0
- package/dist/student-xp/dto/grant-skill-card-xp.dto.js +26 -0
- package/dist/student-xp/dto/grant-skill-card-xp.dto.js.map +1 -0
- package/dist/student-xp/student-xp.controller.d.ts +15 -0
- package/dist/student-xp/student-xp.controller.d.ts.map +1 -1
- package/dist/student-xp/student-xp.controller.js +24 -0
- package/dist/student-xp/student-xp.controller.js.map +1 -1
- package/dist/student-xp/student-xp.service.d.ts +16 -0
- package/dist/student-xp/student-xp.service.d.ts.map +1 -1
- package/dist/student-xp/student-xp.service.js +51 -1
- package/dist/student-xp/student-xp.service.js.map +1 -1
- package/hedhog/data/evaluation_topic.yaml +17 -0
- package/hedhog/data/menu.yaml +0 -17
- package/hedhog/data/queue_definition.yaml +48 -0
- package/hedhog/data/route.yaml +94 -124
- package/hedhog/data/setting_group.yaml +19 -19
- package/hedhog/frontend/app/bulk-upload-sessions/page.tsx.ejs +337 -41
- package/hedhog/frontend/app/courses/[id]/page.tsx.ejs +69 -4
- package/hedhog/frontend/app/courses/[id]/structure/_components/course-export-sheet.tsx.ejs +420 -0
- package/hedhog/frontend/app/courses/[id]/structure/_components/course-exports-tab.tsx.ejs +308 -0
- package/hedhog/frontend/app/courses/[id]/structure/_components/course-overview-tab.tsx.ejs +17 -15
- package/hedhog/frontend/app/courses/[id]/structure/_components/detail-lesson.tsx.ejs +51 -63
- package/hedhog/frontend/app/courses/[id]/structure/_components/detail-panel.tsx.ejs +8 -3
- package/hedhog/frontend/app/courses/[id]/structure/_components/detail-session.tsx.ejs +31 -8
- package/hedhog/frontend/app/courses/[id]/structure/_components/drag-overlay.tsx.ejs +16 -9
- package/hedhog/frontend/app/courses/[id]/structure/_components/editor-course.tsx.ejs +201 -401
- package/hedhog/frontend/app/courses/[id]/structure/_components/editor-lesson.tsx.ejs +378 -690
- package/hedhog/frontend/app/courses/[id]/structure/_components/mock-data.ts.ejs +1 -2
- package/hedhog/frontend/app/courses/[id]/structure/_components/tree-row-lesson.tsx.ejs +3 -9
- package/hedhog/frontend/app/courses/[id]/structure/_components/types.ts.ejs +1 -1
- package/hedhog/frontend/app/courses/[id]/structure/_data/adapters/course-structure.adapter.ts.ejs +6 -10
- package/hedhog/frontend/app/courses/[id]/structure/_data/services/course-structure.service.ts.ejs +49 -0
- package/hedhog/frontend/app/courses/[id]/structure/_data/types/api-course.types.ts.ejs +4 -3
- package/hedhog/frontend/app/courses/[id]/structure/_data/use-course-content-overview.ts.ejs +0 -1
- package/hedhog/frontend/app/courses/[id]/structure/_data/use-course-exports.ts.ejs +106 -0
- package/hedhog/frontend/app/courses/[id]/structure/_data/use-course-structure-mutations.ts.ejs +28 -1
- package/hedhog/frontend/app/courses/[id]/structure/_data/use-lms-settings-query.ts.ejs +0 -2
- package/hedhog/frontend/app/courses/page.tsx.ejs +45 -0
- package/hedhog/frontend/messages/en.json +26 -28
- package/hedhog/frontend/messages/pt.json +26 -28
- package/hedhog/table/course_export.yaml +62 -0
- package/package.json +13 -9
- package/src/bitcode-wallet/bitcode-wallet.service.ts +43 -4
- package/src/course/course-export-scorm12-worker.service.ts +124 -0
- package/src/course/course-export-scorm12.service.ts +668 -0
- package/src/course/course-export.service.ts +280 -0
- package/src/course/course-structure.controller.ts +14 -2
- package/src/course/course-structure.service.ts +100 -7
- package/src/course/course-video-hls.service.ts +946 -0
- package/src/course/course.controller.ts +33 -19
- package/src/course/course.mcp-tools.ts +1 -1
- package/src/course/course.module.ts +11 -0
- package/src/course/course.service.ts +73 -60
- package/src/course/dto/cleanup-course-storage.dto.ts +1 -0
- package/src/course/dto/cleanup-upload-history.dto.ts +1 -1
- package/src/course/dto/create-course-bulk-job.dto.ts +7 -3
- package/src/course/dto/create-course-export.dto.ts +56 -0
- package/src/course/dto/create-course-structure-lesson.dto.ts +4 -3
- package/src/course/lms-bulk-upload-automation.service.ts +153 -6
- package/src/course/lms-bulk-upload-infra.service.ts +39 -6
- package/src/course/lms-bulk-upload.controller.ts +32 -2
- package/src/course/lms-bulk-upload.service.ts +70 -7
- package/src/course/lms-setting.controller.ts +4 -2
- package/src/course/scorm12-schemas.ts +9 -0
- package/src/enterprise/training/training-student.service.ts +221 -2
- package/src/evaluation/evaluation.service.ts +123 -0
- package/src/exam/dto/create-standalone-question.dto.ts +66 -0
- package/src/exam/exam.module.ts +2 -1
- package/src/exam/exam.service.ts +86 -0
- package/src/exam/question.controller.ts +28 -0
- package/src/lesson-xp-map/lesson-xp-ai-calculation.service.ts +205 -31
- package/src/lms-commerce-access.subscriber.ts +88 -0
- package/src/lms.module.ts +6 -5
- package/src/platforma/platforma-video.service.ts +346 -0
- package/src/platforma/platforma.controller.ts +95 -1
- package/src/platforma/platforma.service.ts +268 -268
- package/src/student-xp/dto/grant-skill-card-xp.dto.ts +10 -0
- package/src/student-xp/student-xp.controller.ts +18 -2
- package/src/student-xp/student-xp.service.ts +84 -2
- package/hedhog/data/video_resolution_profile.yaml +0 -7
- package/hedhog/frontend/app/video-resolution-profiles/page.tsx.ejs +0 -607
- package/hedhog/table/course_video_resolution_profile.yaml +0 -22
- package/hedhog/table/video_resolution_profile.yaml +0 -18
- package/src/video-resolution-profile/dto/create-video-resolution-profile.dto.ts +0 -16
- package/src/video-resolution-profile/dto/update-video-resolution-profile.dto.ts +0 -16
- package/src/video-resolution-profile/video-resolution-profile.controller.ts +0 -62
- package/src/video-resolution-profile/video-resolution-profile.mcp-tools.ts +0 -128
- package/src/video-resolution-profile/video-resolution-profile.module.ts +0 -13
- package/src/video-resolution-profile/video-resolution-profile.service.ts +0 -117
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { FileService } from '@hed-hog/core';
|
|
2
|
+
import { PrismaService } from '@hed-hog/api-prisma';
|
|
3
|
+
import {
|
|
4
|
+
forwardRef,
|
|
5
|
+
Inject,
|
|
6
|
+
Injectable,
|
|
7
|
+
Logger,
|
|
8
|
+
NotFoundException,
|
|
9
|
+
UnauthorizedException,
|
|
10
|
+
} from '@nestjs/common';
|
|
11
|
+
import { JwtService } from '@nestjs/jwt';
|
|
12
|
+
import type { Request, Response } from 'express';
|
|
13
|
+
|
|
14
|
+
@Injectable()
|
|
15
|
+
export class PlatformaVideoService {
|
|
16
|
+
private readonly logger = new Logger(PlatformaVideoService.name);
|
|
17
|
+
constructor(
|
|
18
|
+
@Inject(forwardRef(() => PrismaService))
|
|
19
|
+
private readonly prisma: PrismaService,
|
|
20
|
+
@Inject(forwardRef(() => FileService))
|
|
21
|
+
private readonly fileService: FileService,
|
|
22
|
+
@Inject(forwardRef(() => JwtService))
|
|
23
|
+
private readonly jwtService: JwtService,
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
async getVideoOptions(lessonId: number) {
|
|
27
|
+
const lesson = await this.prisma.course_lesson.findFirst({
|
|
28
|
+
where: { id: lessonId, published: true },
|
|
29
|
+
select: {
|
|
30
|
+
id: true,
|
|
31
|
+
course_lesson_file: {
|
|
32
|
+
where: { file_id: { not: null } },
|
|
33
|
+
select: { id: true, title: true, type: true, file: { select: { id: true } } },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!lesson) throw new NotFoundException('Lesson not found');
|
|
39
|
+
|
|
40
|
+
// HLS takes priority over legacy MP4 profiles
|
|
41
|
+
const hlsFile = lesson.course_lesson_file.find((f) => f.type === 'video_hls' && f.file?.id);
|
|
42
|
+
if (hlsFile) {
|
|
43
|
+
return [{ type: 'video_hls', label: 'HLS', fileId: hlsFile.file!.id! }];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const videoFiles = lesson.course_lesson_file.filter(
|
|
47
|
+
(f) => f.type === 'video_original' || f.type?.startsWith('video_profile:'),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (videoFiles.length === 0) return [];
|
|
51
|
+
|
|
52
|
+
return videoFiles
|
|
53
|
+
.filter((f) => f.file?.id)
|
|
54
|
+
.map((f) => {
|
|
55
|
+
const profileMatch = f.type?.match(/^video_profile:(\d+)$/);
|
|
56
|
+
const profileId = profileMatch ? Number(profileMatch[1]) : null;
|
|
57
|
+
const label =
|
|
58
|
+
f.type === 'video_original'
|
|
59
|
+
? 'Original'
|
|
60
|
+
: profileId !== null
|
|
61
|
+
? f.title || `Perfil ${profileId}`
|
|
62
|
+
: f.title || f.type || 'Vídeo';
|
|
63
|
+
|
|
64
|
+
return { type: f.type!, label, fileId: f.file!.id! };
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async generateVideoToken(lessonId: number, quality?: string) {
|
|
69
|
+
const options = await this.getVideoOptions(lessonId);
|
|
70
|
+
if (options.length === 0) throw new NotFoundException('No video available for this lesson');
|
|
71
|
+
|
|
72
|
+
const selected = quality
|
|
73
|
+
? (options.find((o) => o.type === quality) ?? options[0])
|
|
74
|
+
: options[0];
|
|
75
|
+
|
|
76
|
+
const token = this.jwtService.sign(
|
|
77
|
+
{ fileId: selected.fileId, lessonId },
|
|
78
|
+
{ secret: process.env.JWT_SECRET, expiresIn: '4h' },
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return { token, label: selected.label, type: selected.type, expiresIn: 14400 };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async streamVideo(token: string, req: Request, res: Response) {
|
|
85
|
+
let fileId: number;
|
|
86
|
+
try {
|
|
87
|
+
const payload = this.jwtService.verify<{ fileId: number }>(token, {
|
|
88
|
+
secret: process.env.JWT_SECRET,
|
|
89
|
+
});
|
|
90
|
+
fileId = payload.fileId;
|
|
91
|
+
} catch {
|
|
92
|
+
throw new UnauthorizedException('Invalid or expired video token');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const rangeHeader = req.headers['range'];
|
|
96
|
+
let start: number | undefined;
|
|
97
|
+
let end: number | undefined;
|
|
98
|
+
|
|
99
|
+
if (rangeHeader) {
|
|
100
|
+
const match = rangeHeader.match(/bytes=(\d+)-(\d*)/);
|
|
101
|
+
if (match) {
|
|
102
|
+
start = parseInt(match[1], 10);
|
|
103
|
+
end = match[2] ? parseInt(match[2], 10) : undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const result = await this.fileService.openReadStreamWithRange(fileId, start, end);
|
|
108
|
+
if (!result) throw new NotFoundException('Video file not found');
|
|
109
|
+
|
|
110
|
+
const { stream, totalSize, start: resolvedStart, end: resolvedEnd, contentLength, mimetype } = result;
|
|
111
|
+
|
|
112
|
+
const headers: Record<string, string | number> = {
|
|
113
|
+
'Content-Type': mimetype,
|
|
114
|
+
'Content-Disposition': 'inline',
|
|
115
|
+
'Accept-Ranges': 'bytes',
|
|
116
|
+
'Cache-Control': 'no-store',
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if (start !== undefined) {
|
|
120
|
+
headers['Content-Range'] = `bytes ${resolvedStart}-${resolvedEnd ?? totalSize - 1}/${totalSize || '*'}`;
|
|
121
|
+
headers['Content-Length'] = contentLength;
|
|
122
|
+
res.writeHead(206, headers);
|
|
123
|
+
} else {
|
|
124
|
+
if (totalSize > 0) headers['Content-Length'] = totalSize;
|
|
125
|
+
res.writeHead(200, headers);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
stream.pipe(res);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// HLS endpoints
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
async generateHlsToken(lessonId: number) {
|
|
136
|
+
const lesson = await this.prisma.course_lesson.findFirst({
|
|
137
|
+
where: { id: lessonId, published: true },
|
|
138
|
+
select: {
|
|
139
|
+
id: true,
|
|
140
|
+
course_lesson_file: {
|
|
141
|
+
where: { type: 'video_hls', file_id: { not: null } },
|
|
142
|
+
select: { id: true },
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
if (!lesson) throw new NotFoundException('Lesson not found');
|
|
148
|
+
if (lesson.course_lesson_file.length === 0) throw new NotFoundException('No HLS stream available for this lesson');
|
|
149
|
+
|
|
150
|
+
const token = this.jwtService.sign(
|
|
151
|
+
{ lessonId },
|
|
152
|
+
{ secret: process.env.JWT_SECRET, expiresIn: '4h' },
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
return { token, expiresIn: 14400 };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private verifyHlsToken(token: string): { lessonId: number } {
|
|
159
|
+
try {
|
|
160
|
+
return this.jwtService.verify<{ lessonId: number }>(token, {
|
|
161
|
+
secret: process.env.JWT_SECRET,
|
|
162
|
+
});
|
|
163
|
+
} catch {
|
|
164
|
+
throw new UnauthorizedException('Invalid or expired HLS token');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async serveHlsMasterManifest(token: string, req: Request, res: Response) {
|
|
169
|
+
const { lessonId } = this.verifyHlsToken(token);
|
|
170
|
+
|
|
171
|
+
const manifestFile = await (this.prisma as any).file.findFirst({
|
|
172
|
+
where: {
|
|
173
|
+
location: `lms/lessons/hls/${lessonId}`,
|
|
174
|
+
filename: 'master.m3u8',
|
|
175
|
+
},
|
|
176
|
+
select: { id: true },
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (!manifestFile) throw new NotFoundException('HLS master manifest not found');
|
|
180
|
+
|
|
181
|
+
const { stream } = await this.fileService.openReadStreamById(manifestFile.id);
|
|
182
|
+
|
|
183
|
+
const chunks: Buffer[] = [];
|
|
184
|
+
await new Promise<void>((resolve, reject) => {
|
|
185
|
+
stream.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
186
|
+
stream.on('end', resolve);
|
|
187
|
+
stream.on('error', reject);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
|
191
|
+
const content = Buffer.concat(chunks).toString('utf8');
|
|
192
|
+
|
|
193
|
+
// Rewrite relative variant playlist paths to absolute authenticated URLs
|
|
194
|
+
const rewritten = content.replace(
|
|
195
|
+
/^(stream_\d+\/playlist\.m3u8)$/gm,
|
|
196
|
+
(_, variantPath) => `${baseUrl}/lms/platforma/hls/${token}/${variantPath}`,
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
res.set({
|
|
200
|
+
'Content-Type': 'application/x-mpegURL',
|
|
201
|
+
'Cache-Control': 'no-store',
|
|
202
|
+
'Access-Control-Allow-Origin': '*',
|
|
203
|
+
});
|
|
204
|
+
res.send(rewritten);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async serveHlsVariantPlaylist(token: string, variant: string, req: Request, res: Response) {
|
|
208
|
+
const { lessonId } = this.verifyHlsToken(token);
|
|
209
|
+
|
|
210
|
+
const playlistFile = await (this.prisma as any).file.findFirst({
|
|
211
|
+
where: {
|
|
212
|
+
location: `lms/lessons/hls/${lessonId}/${variant}`,
|
|
213
|
+
filename: 'playlist.m3u8',
|
|
214
|
+
},
|
|
215
|
+
select: { id: true },
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (!playlistFile) throw new NotFoundException('HLS variant playlist not found');
|
|
219
|
+
|
|
220
|
+
const { stream } = await this.fileService.openReadStreamById(playlistFile.id);
|
|
221
|
+
|
|
222
|
+
const chunks: Buffer[] = [];
|
|
223
|
+
await new Promise<void>((resolve, reject) => {
|
|
224
|
+
stream.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
225
|
+
stream.on('end', resolve);
|
|
226
|
+
stream.on('error', reject);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
|
230
|
+
const content = Buffer.concat(chunks).toString('utf8');
|
|
231
|
+
|
|
232
|
+
// Rewrite relative segment paths to absolute authenticated URLs
|
|
233
|
+
const rewritten = content.replace(
|
|
234
|
+
/^(seg\d+\.ts)$/gm,
|
|
235
|
+
(_, segName) => `${baseUrl}/lms/platforma/hls/${token}/${variant}/${segName}`,
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
res.set({
|
|
239
|
+
'Content-Type': 'application/x-mpegURL',
|
|
240
|
+
'Cache-Control': 'no-store',
|
|
241
|
+
'Access-Control-Allow-Origin': '*',
|
|
242
|
+
});
|
|
243
|
+
res.send(rewritten);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async serveHlsSegment(token: string, variant: string, segment: string, res: Response) {
|
|
247
|
+
const { lessonId } = this.verifyHlsToken(token);
|
|
248
|
+
|
|
249
|
+
if (!/^seg\d+\.ts$/.test(segment)) {
|
|
250
|
+
throw new NotFoundException('Invalid segment name');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const segmentFile = await (this.prisma as any).file.findFirst({
|
|
254
|
+
where: {
|
|
255
|
+
location: `lms/lessons/hls/${lessonId}/${variant}`,
|
|
256
|
+
filename: segment,
|
|
257
|
+
},
|
|
258
|
+
select: { id: true },
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
if (!segmentFile) throw new NotFoundException('HLS segment not found');
|
|
262
|
+
|
|
263
|
+
const { stream } = await this.fileService.openReadStreamById(segmentFile.id);
|
|
264
|
+
|
|
265
|
+
res.set({
|
|
266
|
+
'Content-Type': 'video/MP2T',
|
|
267
|
+
'Cache-Control': 'public, max-age=31536000, immutable',
|
|
268
|
+
'Access-Control-Allow-Origin': '*',
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
stream.pipe(res);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// ---------------------------------------------------------------------------
|
|
275
|
+
// Subtitle (VTT) endpoints
|
|
276
|
+
// ---------------------------------------------------------------------------
|
|
277
|
+
|
|
278
|
+
async generateSubtitlesToken(lessonId: number) {
|
|
279
|
+
const lesson = await this.prisma.course_lesson.findFirst({
|
|
280
|
+
where: { id: lessonId, published: true },
|
|
281
|
+
select: { id: true },
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
if (!lesson) throw new NotFoundException('Lesson not found');
|
|
285
|
+
|
|
286
|
+
const count = await (this.prisma as any).course_lesson_transcription_segment.count({
|
|
287
|
+
where: { course_lesson_id: lessonId },
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
if (count === 0) throw new NotFoundException('No subtitles available for this lesson');
|
|
291
|
+
|
|
292
|
+
const token = this.jwtService.sign(
|
|
293
|
+
{ lessonId, type: 'subtitles' },
|
|
294
|
+
{ secret: process.env.JWT_SECRET, expiresIn: '4h' },
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
return { token, expiresIn: 14400 };
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async serveSubtitles(token: string, res: Response) {
|
|
301
|
+
let lessonId: number;
|
|
302
|
+
try {
|
|
303
|
+
const payload = this.jwtService.verify<{ lessonId: number; type: string }>(token, {
|
|
304
|
+
secret: process.env.JWT_SECRET,
|
|
305
|
+
});
|
|
306
|
+
if (payload.type !== 'subtitles') throw new Error('Wrong token type');
|
|
307
|
+
lessonId = payload.lessonId;
|
|
308
|
+
} catch {
|
|
309
|
+
throw new UnauthorizedException('Invalid or expired subtitles token');
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const segments = await (this.prisma as any).course_lesson_transcription_segment.findMany({
|
|
313
|
+
where: { course_lesson_id: lessonId },
|
|
314
|
+
orderBy: { start_seconds: 'asc' },
|
|
315
|
+
select: { start_seconds: true, end_seconds: true, text: true },
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const vtt = this.buildVtt(segments);
|
|
319
|
+
|
|
320
|
+
res.set({
|
|
321
|
+
'Content-Type': 'text/vtt; charset=utf-8',
|
|
322
|
+
'Cache-Control': 'no-store',
|
|
323
|
+
'Access-Control-Allow-Origin': '*',
|
|
324
|
+
});
|
|
325
|
+
res.send(vtt);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
private secondsToVttTime(seconds: number): string {
|
|
329
|
+
const s = Number(seconds);
|
|
330
|
+
const h = Math.floor(s / 3600);
|
|
331
|
+
const m = Math.floor((s % 3600) / 60);
|
|
332
|
+
const sec = Math.floor(s % 60);
|
|
333
|
+
const ms = Math.round((s % 1) * 1000);
|
|
334
|
+
return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(sec).padStart(2, '0')}.${String(ms).padStart(3, '0')}`;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
private buildVtt(segments: { start_seconds: any; end_seconds: any; text: string }[]): string {
|
|
338
|
+
if (segments.length === 0) return 'WEBVTT\n';
|
|
339
|
+
const cues = segments.map((seg, i) => {
|
|
340
|
+
const start = this.secondsToVttTime(seg.start_seconds);
|
|
341
|
+
const end = this.secondsToVttTime(seg.end_seconds);
|
|
342
|
+
return `${i + 1}\n${start} --> ${end}\n${seg.text}`;
|
|
343
|
+
});
|
|
344
|
+
return `WEBVTT\n\n${cues.join('\n\n')}\n`;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { NoRole, User } from '@hed-hog/api';
|
|
1
|
+
import { NoRole, Public, User } from '@hed-hog/api';
|
|
2
2
|
import { NotificationService } from '@hed-hog/core';
|
|
3
3
|
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post, Put, Query, Req, Res } from '@nestjs/common';
|
|
4
4
|
import type { Request, Response } from 'express';
|
|
5
5
|
import { BitcodeWalletService } from '../bitcode-wallet/bitcode-wallet.service';
|
|
6
6
|
import { CreateCurrentBitcodeWalletTransactionDto } from '../bitcode-wallet/dto/create-current-bitcode-wallet-transaction.dto';
|
|
7
|
+
import { EvaluationService } from '../evaluation/evaluation.service';
|
|
7
8
|
import { TrainingStudentService } from '../enterprise/training/training-student.service';
|
|
8
9
|
import { UpdatePlatformaProfileDto } from './dto/update-profile.dto';
|
|
9
10
|
import { PlatformaService } from './platforma.service';
|
|
11
|
+
import { PlatformaVideoService } from './platforma-video.service';
|
|
10
12
|
|
|
11
13
|
@NoRole()
|
|
12
14
|
@Controller('lms/platforma')
|
|
@@ -16,6 +18,8 @@ export class PlataformaController {
|
|
|
16
18
|
private readonly notificationService: NotificationService,
|
|
17
19
|
private readonly platforma: PlatformaService,
|
|
18
20
|
private readonly bitcodeWalletService: BitcodeWalletService,
|
|
21
|
+
private readonly platformaVideoService: PlatformaVideoService,
|
|
22
|
+
private readonly evaluationService: EvaluationService,
|
|
19
23
|
) {}
|
|
20
24
|
|
|
21
25
|
@Get()
|
|
@@ -45,6 +49,96 @@ export class PlataformaController {
|
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
@Get('courses/:slug')
|
|
53
|
+
getCourseBySlug(@Param('slug') slug: string, @User('id') userId?: number) {
|
|
54
|
+
return this.trainingStudentService.getPublishedCourseBySlug(slug, userId);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Get('lessons/:lessonId')
|
|
58
|
+
getLessonDetail(@Param('lessonId', ParseIntPipe) lessonId: number) {
|
|
59
|
+
return this.trainingStudentService.getLessonDetail(lessonId);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Get('lessons/:lessonId/video-token')
|
|
63
|
+
getVideoToken(
|
|
64
|
+
@Param('lessonId', ParseIntPipe) lessonId: number,
|
|
65
|
+
@Query('quality') quality?: string,
|
|
66
|
+
) {
|
|
67
|
+
return this.platformaVideoService.generateVideoToken(lessonId, quality);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Get('lessons/:lessonId/hls-token')
|
|
71
|
+
getHlsToken(@Param('lessonId', ParseIntPipe) lessonId: number) {
|
|
72
|
+
return this.platformaVideoService.generateHlsToken(lessonId);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Public()
|
|
76
|
+
@Get('video/:token')
|
|
77
|
+
streamVideo(@Param('token') token: string, @Req() req: Request, @Res() res: Response) {
|
|
78
|
+
return this.platformaVideoService.streamVideo(token, req, res);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Public()
|
|
82
|
+
@Get('hls/:token/master.m3u8')
|
|
83
|
+
serveHlsMaster(@Param('token') token: string, @Req() req: Request, @Res() res: Response) {
|
|
84
|
+
return this.platformaVideoService.serveHlsMasterManifest(token, req, res);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Public()
|
|
88
|
+
@Get('hls/:token/:variant/playlist.m3u8')
|
|
89
|
+
serveHlsVariant(
|
|
90
|
+
@Param('token') token: string,
|
|
91
|
+
@Param('variant') variant: string,
|
|
92
|
+
@Req() req: Request,
|
|
93
|
+
@Res() res: Response,
|
|
94
|
+
) {
|
|
95
|
+
return this.platformaVideoService.serveHlsVariantPlaylist(token, variant, req, res);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@Public()
|
|
99
|
+
@Get('hls/:token/:variant/:segment')
|
|
100
|
+
serveHlsSegment(
|
|
101
|
+
@Param('token') token: string,
|
|
102
|
+
@Param('variant') variant: string,
|
|
103
|
+
@Param('segment') segment: string,
|
|
104
|
+
@Res() res: Response,
|
|
105
|
+
) {
|
|
106
|
+
return this.platformaVideoService.serveHlsSegment(token, variant, segment, res);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Get('lessons/:lessonId/subtitles-token')
|
|
110
|
+
getSubtitlesToken(@Param('lessonId', ParseIntPipe) lessonId: number) {
|
|
111
|
+
return this.platformaVideoService.generateSubtitlesToken(lessonId);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@Get('lessons/:lessonId/evaluation-topics')
|
|
115
|
+
getCourseLessonEvaluationTopics(@Param('lessonId', ParseIntPipe) lessonId: number) {
|
|
116
|
+
return this.evaluationService.getCourseLessonTopics(lessonId);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@Get('lessons/:lessonId/my-evaluation')
|
|
120
|
+
getMyLessonEvaluation(
|
|
121
|
+
@Param('lessonId', ParseIntPipe) lessonId: number,
|
|
122
|
+
@User('id') userId: number,
|
|
123
|
+
) {
|
|
124
|
+
return this.evaluationService.getMyLessonRatings(lessonId, userId);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@Post('lessons/:lessonId/evaluate')
|
|
128
|
+
submitLessonEvaluation(
|
|
129
|
+
@Param('lessonId', ParseIntPipe) lessonId: number,
|
|
130
|
+
@User('id') userId: number,
|
|
131
|
+
@Body() body: { ratings: Array<{ topicId: number; score: number; comment?: string }> },
|
|
132
|
+
) {
|
|
133
|
+
return this.evaluationService.submitLessonRatings(lessonId, userId, body.ratings ?? []);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@Public()
|
|
137
|
+
@Get('subtitles/:token/captions.vtt')
|
|
138
|
+
serveSubtitles(@Param('token') token: string, @Res() res: Response) {
|
|
139
|
+
return this.platformaVideoService.serveSubtitles(token, res);
|
|
140
|
+
}
|
|
141
|
+
|
|
48
142
|
@Get('notifications')
|
|
49
143
|
listNotifications(
|
|
50
144
|
@User('id') userId: number,
|