add summarize_story

This commit is contained in:
Luk 2025-04-09 21:34:55 +08:00
parent 5cb8755a00
commit 986f273006

View File

@ -349,6 +349,26 @@ 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 } = {}) => {
if (text) {
summary.textLength += text.length
summary.wordCount += text.split(/\s+/).length
} else if (image) {
summary.imageCount++
} else if (video) {
summary.videoCount++
} else if (file) {
summary.fileCount++
}
return summary
},
{ textLength: 0, wordCount: 0, imageCount: 0, videoCount: 0 }
)
},
is_empty (data) { is_empty (data) {
// empty: undefined, null, false, 0, NaN, '', '空格tab, \n等', [], {} // empty: undefined, null, false, 0, NaN, '', '空格tab, \n等', [], {}
if (data) { if (data) {