* Apply truncation limits to content * @param {string} content - The content to truncate * @param {number} [maxLength] - Maximum length of content (default: 524288) * @returns {string} The truncated content
(content, maxLength)
| 1000 | * @returns {string} The truncated content |
| 1001 | */ |
| 1002 | function applyTruncation(content, maxLength) { |
| 1003 | maxLength = maxLength || 524288; |
| 1004 | const lines = content.split("\n"); |
| 1005 | const maxLines = 65000; |
| 1006 | |
| 1007 | // If content has too many lines, truncate by lines (primary limit) |
| 1008 | if (lines.length > maxLines) { |
| 1009 | const truncationMsg = "\n[Content truncated due to line count]"; |
| 1010 | const truncatedLines = lines.slice(0, maxLines).join("\n") + truncationMsg; |
| 1011 | |
| 1012 | // If still too long after line truncation, shorten but keep the line count message |
| 1013 | if (truncatedLines.length > maxLength) { |
| 1014 | return truncatedLines.substring(0, maxLength - truncationMsg.length) + truncationMsg; |
| 1015 | } else { |
| 1016 | return truncatedLines; |
| 1017 | } |
| 1018 | } else if (content.length > maxLength) { |
| 1019 | return content.substring(0, maxLength) + "\n[Content truncated due to length]"; |
| 1020 | } |
| 1021 | |
| 1022 | return content; |
| 1023 | } |
| 1024 | |
| 1025 | /** |
| 1026 | * Decodes HTML entities to prevent bypass of @mention detection and to ensure |
no outgoing calls
no test coverage detected