try to deploy

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-13 21:27:37 +08:00
parent f5254f7571
commit c8dc2628a6
9 changed files with 120 additions and 46 deletions
+9 -6
View File
@@ -9,10 +9,12 @@ function stripHtml(html) {
/**
* Estimate seconds for a single lesson block
* Block shape: { type: 'text'|'image'|'video', content, word_count, video_duration_seconds }
* Block shape: { id, type, content }, where content.duration_seconds holds
* the probed media length for video/audio blocks (see AssetPickerSheet
* consumers — VideoBlock/AudioBlock/TextVideoBlock save it on select).
*/
function estimateBlockDuration(block) {
const videoDuration = Number(block.video_duration_seconds) || 0;
const mediaDuration = Math.round(Number(block.content?.duration_seconds) || 0);
// Derive word count from HTML content on the fly
const getWordCount = (html) => {
@@ -32,7 +34,8 @@ function estimateBlockDuration(block) {
return 60;
case "video":
return videoDuration;
case "audio":
return mediaDuration;
case "text-image":
case "text_image":
@@ -40,7 +43,7 @@ function estimateBlockDuration(block) {
case "text-video":
case "text_video":
return readingSecs(block.content?.body) + videoDuration;
return readingSecs(block.content?.body) + mediaDuration;
default:
return 0;
@@ -104,8 +107,8 @@ async function recomputeDurations(lessonId) {
(sum, block) => sum + estimateBlockDuration(block), 0
);
// Guard against NaN before DB write
const safeLessonSecs = isNaN(lessonSecs) ? 0 : lessonSecs;
// Guard against NaN/fractional values before DB write (duration_seconds is INTEGER)
const safeLessonSecs = isNaN(lessonSecs) ? 0 : Math.round(lessonSecs);
await Lesson.update({ duration_seconds: safeLessonSecs }, { where: { lesson_id: lessonId } });
// 2. Every unit that contains this lesson