printhive/lib/licenses.js
dlawler489 2768a71c63 Add per-license commercial-use rules (settings + auto-register)
- license_rules table (name -> commercial); licenses auto-register on
  import with a best-effort seed, overridable in Settings (applies the
  choice to every model with that license)
- resolveCommercial() replaces ad-hoc inferCommercial across import/refresh
- GET/PUT /api/licenses; "License types" section in Settings
- Fix CC short codes: BY / BY-SA / BY-ND now classed sellable (MakerWorld
  stores e.g. "BY-SA"); NC variants stay non-commercial

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 10:20:28 +10:00

22 lines
1.2 KiB
JavaScript

// Best-effort guess at whether a license permits commercial use (selling prints),
// from its name/abbreviation or — preferably — its full license text. Returns
// true / false / null (unknown). This is a hint only; the UI tells the user to
// verify before selling, and it deliberately leans toward NOT sellable when
// ambiguous (the safer error for "can I sell this?").
function inferCommercial(text) {
if (!text) return null;
const s = String(text).replace(/<[^>]*>/g, ' ').toLowerCase();
// Restrictive / non-commercial — checked first so it wins over stray "sell"s.
if (/non-?commercial|personal use|community use|[-_\s]nc([-_\s]|$)|exclusive|standard digital file|all rights reserved|^\s*none\s*$|charge money|shall not[^.]*\bsell|not be sold/.test(s)) {
return false;
}
// Clearly permissive (commercial use OK). NC variants are already excluded above,
// so any remaining CC "BY" code (by, by-sa, by-nd) allows commercial use.
if (/cc0|public ?domain|creative commons|attribution|cc[-_\s]?by|(^|[-_\s])by([-_\s]|$)|by[-_](sa|nd)|share[- ]?alike|^\s*mit\b|^\s*bsd\b|^\s*l?gpl\b|royalty[- ]free|commercial use (is )?(allowed|permitted)|may be sold/.test(s)) {
return true;
}
return null;
}
module.exports = { inferCommercial };