Menu ▾ ▴

#504 Refactor: extract the repeated --allow-dangerous validation preamble

open
nobody
2026-10-03
2026-10-03
Anonymous
No

Originally created by: Redo-San

Six CLI command files repeat the same ~10-line preamble: resolve path, read allowDangerous, try { validateFile(...) } catch { console.error(...); if message includes "Blocked dangerous file type" print a hint; process.exit(1); }.

Locations

cli/commands/c2pa.js:190-199, fingerprint.js:115-126, forensic.js:137-147, metadata.js:71-82, pixel_injection.js:91-100, watermark.js:325-335

Change

Add an exported helper next to the already-exported validateFile at cli/utils.js:842, and call it from all six.

Note the hint wording is inconsistent today: 4 files say "Use --allow-dangerous to bypass" while fingerprint.js:123 and watermark.js:332 say "...bypass file validation". Pick one wording for all six.

Acceptance criteria

  • [ ] npm run test:cli passes.
  • [ ] node cli/index.js fingerprint <some.exe> still prints Validation failed: … and exits 1; with --allow-dangerous it proceeds.
  • [ ] The six files no longer contain the literal Blocked dangerous file type check.

Discussion


Log in to post a comment.