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);