| 1 | const MIN_CONTENT_LENGTH = 30; |
| 2 | |
| 3 | export function extractScriptContent(text: string): string | null { |
| 4 | const trimmed = text.trim(); |
| 5 | if (trimmed.length < MIN_CONTENT_LENGTH) return null; |
| 6 | |
| 7 | if (isMetaContent(trimmed)) return null; |
| 8 | |
| 9 | const paragraphs = trimmed.split(/\n\n+/).filter((p) => p.trim().length > 0); |
| 10 | if (paragraphs.length === 0) return null; |
| 11 | |
| 12 | const contentParagraphs = paragraphs.filter((p) => { |
| 13 | const t = p.trim(); |
| 14 | if (t.length < 10) return false; |
| 15 | if (/^(好的|没问题|当然|了解|明白|收到)/.test(t) && t.length < 30) |
| 16 | return false; |
| 17 | if (isMetaContent(t)) return false; |
| 18 | return true; |
| 19 | }); |
| 20 | |
| 21 | if (contentParagraphs.length === 0) return null; |
| 22 | return contentParagraphs.join("\n\n"); |
| 23 | } |
| 24 | |
| 25 | function isMetaContent(text: string): boolean { |
| 26 | const metaPatterns = [ |
| 27 | /步骤|流程|规划|计划/, |
| 28 | /首先.*然后.*最后/s, |
| 29 | /第[一二三四五六七八九十\d]+步/, |
| 30 | /我[会将来].*(?:帮你|为你|给你)/, |
| 31 | /接下来我/, |
| 32 | /多步骤|分步/, |
| 33 | /(?:^|\n)\s*\d+[.、))]\s*/, |
| 34 | ]; |
| 35 | const matchCount = metaPatterns.filter((p) => p.test(text)).length; |
| 36 | return matchCount >= 2; |
| 37 | } |
| 38 |