( content: string, url: string, command: string, )
| 282 | * Returns aggregated result with all warnings. |
| 283 | */ |
| 284 | export function runContentFilters( |
| 285 | content: string, |
| 286 | url: string, |
| 287 | command: string, |
| 288 | ): ContentFilterResult { |
| 289 | const mode = getFilterMode(); |
| 290 | if (mode === 'off') { |
| 291 | return { safe: true, warnings: [] }; |
| 292 | } |
| 293 | |
| 294 | const allWarnings: string[] = []; |
| 295 | let blocked = false; |
| 296 | |
| 297 | for (const filter of registeredFilters) { |
| 298 | const result = filter(content, url, command); |
| 299 | if (!result.safe) { |
| 300 | allWarnings.push(...result.warnings); |
| 301 | if (mode === 'block') { |
| 302 | blocked = true; |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | if (blocked && allWarnings.length > 0) { |
| 308 | return { |
| 309 | safe: false, |
| 310 | warnings: allWarnings, |
| 311 | blocked: true, |
| 312 | message: `Content blocked: ${allWarnings.join('; ')}`, |
| 313 | }; |
| 314 | } |
| 315 | |
| 316 | return { |
| 317 | safe: allWarnings.length === 0, |
| 318 | warnings: allWarnings, |
| 319 | }; |
| 320 | } |
| 321 | |
| 322 | // ─── Built-in URL Blocklist Filter ────────────────────────────── |
| 323 |
no test coverage detected