mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
fix: throttle request issue per video,audio as indicated requirements in units and lessons
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -219,11 +219,17 @@ async function recomputeCourseAfterAssessment(userId, courseId, t) {
|
||||
* live block set on every write, not a snapshot taken when configured).
|
||||
* No-ops (returns null) if the lesson has neither type configured.
|
||||
*/
|
||||
// text-video counts as a video block for watch_video purposes — same <video> element
|
||||
// under the hood, just paired with text. A lesson mixing plain "video" and "text-video"
|
||||
// blocks needs both kinds counted together when checking "every video block hit 100%".
|
||||
const VIDEO_LIKE_BLOCK_TYPES = ['video', 'text-video'];
|
||||
|
||||
async function recordWatchProgress(userId, {
|
||||
lessonId, lessonUuid, unitId = null, unitUuid = null, courseId = null, courseUuid = null,
|
||||
percent, blockId = null, blockType = null,
|
||||
}) {
|
||||
const blockRequirementType = blockType === 'video' ? 'watch_video' : blockType === 'audio' ? 'listen_audio' : null;
|
||||
const isVideoLikeBlock = VIDEO_LIKE_BLOCK_TYPES.includes(blockType);
|
||||
const blockRequirementType = isVideoLikeBlock ? 'watch_video' : blockType === 'audio' ? 'listen_audio' : null;
|
||||
|
||||
const requirements = await CompletionRequirement.findAll({
|
||||
where: {
|
||||
@@ -273,7 +279,9 @@ async function recordWatchProgress(userId, {
|
||||
const nextBlockProgress = { ...prevBlockProgress, [blockId]: Math.max(prevBlockProgress[blockId] ?? 0, clampedPercent) };
|
||||
|
||||
const page = await LessonPage.findOne({ where: { lesson_id: lessonId }, attributes: ['blocks'], transaction: t });
|
||||
const matchingBlockIds = (page?.blocks ?? []).filter((b) => b.type === blockType).map((b) => b.id);
|
||||
const matchingBlockIds = (page?.blocks ?? [])
|
||||
.filter((b) => isVideoLikeBlock ? VIDEO_LIKE_BLOCK_TYPES.includes(b.type) : b.type === blockType)
|
||||
.map((b) => b.id);
|
||||
const completed = matchingBlockIds.length > 0 && matchingBlockIds.every((id) => (nextBlockProgress[id] ?? 0) >= 100);
|
||||
|
||||
await CompletionRequirementProgress.upsert({
|
||||
|
||||
Reference in New Issue
Block a user