mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user