This commit is contained in:
Luk
2025-06-09 21:18:38 +08:00
parent 3e52b5a9f4
commit fc146dc10d
2 changed files with 44 additions and 7 deletions

View File

@@ -332,7 +332,11 @@ module.exports = {
// 返回新的数组
filter_story (story) {
if (Array.isArray(story) && story.length) {
return story.filter((section) => Object.values(section || {}).some((val) => !this.is_empty(val))) // (section.text || section.image || section.video)?.trim?.()
// section can contain property '_xxx' which shall not change filter result.
return story.filter((section) => {
if (!section) return false
return Object.entries(section).some(([key, val]) => !key.startsWith('_') && !this.is_empty(val))
})
} else {
return []
}
@@ -354,7 +358,7 @@ module.exports = {
summarize_story (story = []) {
// story is an array of objects, each object could either be {text:'some string'}, {image: url} or {video:url}. Please construct a summary object as result: { textLength, imageCount, VideoCount }
return story.reduce(
(summary, { text, image, video, file, linkTarget } = {}) => {
(summary, { text, image, video, audio, file, linkTarget } = {}) => {
if (text) {
summary.textLength += text.length
summary.wordCount += text.split(/\s+/).length
@@ -362,6 +366,8 @@ module.exports = {
summary.imageCount++
} else if (video) {
summary.videoCount++
} else if (audio) {
summary.audioCount++
} else if (file) {
summary.fileCount++
} else if (linkTarget) {
@@ -371,7 +377,7 @@ module.exports = {
}
return summary
},
{ textLength: 0, wordCount: 0, imageCount: 0, videoCount: 0, fileCount: 0, linkCount: 0, untypeCount: 0 }
{ textLength: 0, wordCount: 0, imageCount: 0, videoCount: 0, audioCount: 0, fileCount: 0, linkCount: 0, untypeCount: 0 }
)
},