printhive/lib/licenses.js
dlawler489 a37db15a3f Initial commit: Printhive 3D-print file library
Self-hosted Express + Postgres app for organizing STL/3MF/OBJ/etc. with:
- Model/file library, tags, collections, print settings
- URL import: Thingiverse (API), Printables (GraphQL), MakerWorld
  (FlareSolverr + token), cubee3d/other (metadata + manual files)
- In-browser 3D viewer; 3MF rendered via Python/trimesh GLB conversion
- Auto thumbnails, license/commercial-use tracking, in-app editing
- Settings (API tokens / FlareSolverr) stored in DB with .env fallback

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 13:15:17 +10:00

21 lines
1.1 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.
if (/cc0|public ?domain|creative commons|attribution|cc[-_\s]?by|^\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 };