feat: Montar takes Dropstar's dotted codes and reads the size from the file name
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled

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 <code>-<size>.png form is no longer read.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-16 16:14:49 -03:00
parent c799fd9be4
commit 9de9b6abe1
4 changed files with 26 additions and 7 deletions

View File

@@ -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

View File

@@ -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}$');

View File

@@ -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,

View File

@@ -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;
}
// <code>-<SIZE>.png wins over <code>.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)<Number(size.width_cm)).reverse();
return [code+'.'+size.letter+'.png',code+'.png',...[...up,...down].map(other=>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(dpi<MONTAR_DPI_REFUSE)words.append(node('span','Só '+Math.floor(dpi)+' DPI em '+$('montar-size').value+': pequena demais para imprimir.','montar-missing'));
else if(dpi<MONTAR_DPI_WARN)words.append(node('span',Math.floor(dpi)+' DPI: abaixo de '+MONTAR_DPI_WARN+' DPI.','montar-dpiwarn'));
const img=node('img',undefined,'montar-foundthumb');img.src=found.url;img.alt='Estampa '+found.code;
@@ -657,7 +669,7 @@ function montarClear(){
async function montarAdd(){
const code=$('montar-code').value.trim(),size=montarSelected();
if(!MONTAR_CODE.test(code))return say('Código inválido: use letras, números, hífen ou sublinhado, até 40.',true);
if(!MONTAR_CODE.test(code))return say('Código inválido: use letras, números, ponto, hífen ou sublinhado, até 40.',true);
if(!size)return say('Nenhum tamanho na tabela. Peça à Gestão para cadastrar.',true);
const qty=Number($('montar-qty').value);
if(!Number.isInteger(qty)||qty<1||qty>9999)return say('A quantidade vai de 1 a 9999.',true);