From 9de9b6abe1e5f4ea5025098f56369e5fea5c694a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Mon, 16 Nov 2026 16:14:49 -0300 Subject: [PATCH] feat: Montar takes Dropstar's dotted codes and reads the size from the file name Codes like NX.226 and NX.1003 are allowed in the page, the API and the stamps table (a dot anywhere but first). A file's own size is a dot and its letter before .png (Marcus, 2026-11-16): NX.226.C.png is NX.226 in C, so nobody renames the library. Montar takes the size asked for, else the code without a size, else another size of it scaled (the closest larger one, else the largest) and says which file it was made from; the DPI warning still applies. The -.png form is no longer read. Co-Authored-By: Claude Opus 5.5 (1M context) --- app/api/stamps.py | 3 ++- .../202611161600_stamp-code-dot.sql | 5 +++++ tests/stamps_test.py | 3 ++- web/kanban-montador.js | 22 ++++++++++++++----- 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 app/migrations/202611161600_stamp-code-dot.sql diff --git a/app/api/stamps.py b/app/api/stamps.py index 4b64213..cb3325a 100644 --- a/app/api/stamps.py +++ b/app/api/stamps.py @@ -18,7 +18,8 @@ from .uploads import begin_upload router = APIRouter() -CODE = re.compile(r'^[A-Za-z0-9_-]{1,40}$') +# Dropstar's codes carry dots (NX.226); not as the first character. +CODE = re.compile(r'^[A-Za-z0-9_-][A-Za-z0-9._-]{0,39}$') INTERNAL_MISSING = 'Peça à Gestão para completar o cliente interno.' # Who chooses which kind of order in the montador (Marcus, 2026-11-10): the # Expedição only Interno, the Vendedor only Venda; Gestão and the diff --git a/app/migrations/202611161600_stamp-code-dot.sql b/app/migrations/202611161600_stamp-code-dot.sql new file mode 100644 index 0000000..e5546e2 --- /dev/null +++ b/app/migrations/202611161600_stamp-code-dot.sql @@ -0,0 +1,5 @@ +-- Dropstar's stamp codes carry dots (NX.226, Marcus 2026-11-16); not as the +-- first character, as in app/api/stamps.py CODE. +ALTER TABLE dtf_local.stamps DROP CONSTRAINT IF EXISTS stamps_code_check; +ALTER TABLE dtf_local.stamps ADD CONSTRAINT stamps_code_check + CHECK (code ~ '^[A-Za-z0-9_-][A-Za-z0-9._-]{0,39}$'); diff --git a/tests/stamps_test.py b/tests/stamps_test.py index 6de72e5..d560e47 100644 --- a/tests/stamps_test.py +++ b/tests/stamps_test.py @@ -84,7 +84,8 @@ def run(): identities = [operator_identity(emails['expedicao']), operator_identity(emails['vendedor'])] made_orders, made_quotes = [], [] # A code of its own, so a brand someone saved in Estampas/ is never touched. - stamp_code = 'T' + tag + # With a dot, as Dropstar's own codes (NX.226). + stamp_code = 'T.' + tag try: for role, email in emails.items(): su.call('/operator/users', {'name': role.title(), 'email': email, 'role': role, diff --git a/web/kanban-montador.js b/web/kanban-montador.js index 55cbcb3..ca229f0 100644 --- a/web/kanban-montador.js +++ b/web/kanban-montador.js @@ -4,7 +4,8 @@ Montar creates the card: Interno for the Expedição, Venda for a customer picked from Tiny (front 7a.3). Uses the globals of kanban.js and packing.js, loaded first. */ -const MONTAR_CODE=/^[A-Za-z0-9_-]{1,40}$/; +// Dropstar's codes carry dots (NX.226, NX.1003); not as the first character. +const MONTAR_CODE=/^[A-Za-z0-9_-][A-Za-z0-9._-]{0,39}$/; // The Site's ruler (web/site-config.js): the same numbers, copied there too. const MONTAR_DPI_REFUSE=96, MONTAR_DPI_WARN=200; const MONTAR_FILM_CM=57, MONTAR_GAP_CM=0.5; @@ -279,13 +280,23 @@ function montarFolderError(error){ return false; } -// -.png wins over .png; only PNG. +// The file's own size is a dot and the letter before .png (Marcus, +// 2026-11-16): NX.226.C.png is NX.226 in C. The size asked for first, then the +// code without a size, then another size of it, scaled: the closest larger +// one, so it shrinks, else the largest. Only PNG. +function montarNames(code,size){ + const others=MONTAR.sizes.filter(other=>other.letter!==size.letter) + .sort((a,b)=>Number(a.width_cm)-Number(b.width_cm)); + const up=others.filter(other=>Number(other.width_cm)>=Number(size.width_cm)); + const down=others.filter(other=>Number(other.width_cm)code+'.'+other.letter+'.png')]; +} async function montarRead(code,size){ const dir=await FOLDER.handle.getDirectoryHandle('Estampas',{create:true}); - for(const name of [code+'-'+size.letter+'.png',code+'.png']){ + for(const name of montarNames(code,size)){ let handle; try{handle=await dir.getFileHandle(name);} - catch(e){if(e.name==='NotFoundError')continue;throw e;} + catch(e){if(['NotFoundError','TypeError'].includes(e.name))continue;throw e;} const file=await handle.getFile(),url=URL.createObjectURL(file); try{const dim=await montarPicture(url);return {code,letter:size.letter,widthCm:Number(size.width_cm),file,name,url,width:dim.width,height:dim.height};} catch(e){URL.revokeObjectURL(url);throw e;} @@ -321,6 +332,7 @@ function montarPaintPreview(found,stamp){ const words=node('div',undefined,'montar-foundinfo'); words.append(node('b',found.code+' encontrada'), node('span',qty+' × '+cm(found.widthCm)+' cm de largura · cerca de '+metres(montarFoundMetres(found))+' de filme')); + if(found.name!==found.code+'.'+found.letter+'.png')words.append(node('span','Feita a partir de '+found.name+'.')); if(dpi9999)return say('A quantidade vai de 1 a 9999.',true);