feat: a file's type comes from its first bytes, not its name (Dropstar's rule D-13)
All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 3m37s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m11s
All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 3m37s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m11s
The Site reads the first bytes when a file is chosen and renames it to its real extension: a .cdr that is a PDF is measured and priced as a PDF, without the manual charge; a JPG called .png is refused, naming the file. The scan does the same on the server and stores the real name, so every decision that reads the name follows the content. A name its content agrees with stays (an .ai is a PDF inside but is still handled by hand). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,13 +7,38 @@
|
||||
function escapeHTML(value){
|
||||
return String(value).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
||||
}
|
||||
// Dropstar's rule D-13 (2026-10-26): what a file is comes from its first bytes,
|
||||
// never from its name. A ".cdr" that is a PDF is renamed ".pdf" and checked as
|
||||
// a PDF, without the manual charge; a JPG called ".png" is refused as a JPG.
|
||||
// A name its content agrees with stays, so an Illustrator file, a PDF inside,
|
||||
// is still ".ai". The same signatures as the server (app/scanning.py).
|
||||
const TIFF_INICIOS=['II*\0','MM\0*','II+\0','MM\0+'];
|
||||
const INICIOS={png:['\x89PNG\r\n\x1a\n'], jpg:['\xff\xd8\xff'], jpeg:['\xff\xd8\xff'],
|
||||
tif:TIFF_INICIOS, tiff:TIFF_INICIOS, pdf:['%PDF-'], ai:['%PDF-','%!PS'], psd:['8BPS'], psb:['8BPS']};
|
||||
const RIFF_TIPOS={cdr:/^RIFF[\s\S]{4}CDR/, webp:/^RIFF[\s\S]{4}WEBP/};
|
||||
const confere=(ext,ini)=>RIFF_TIPOS[ext] ? RIFF_TIPOS[ext].test(ini) : (INICIOS[ext]||[]).some(a=>ini.startsWith(a));
|
||||
const formatoDe=ini=>['pdf','png','jpg','tif','psd','cdr','webp'].find(e=>confere(e,ini))||null;
|
||||
async function nomeReal(f){
|
||||
let ini;
|
||||
try{ ini=String.fromCharCode(...new Uint8Array(await f.slice(0,16).arrayBuffer())); }
|
||||
catch(e){ return f; }
|
||||
const real=formatoDe(ini);
|
||||
if(!real || confere(extDe(f.name).toLowerCase(),ini)) return f;
|
||||
const ponto=f.name.lastIndexOf('.');
|
||||
const g=new File([f], (ponto>0?f.name.slice(0,ponto):f.name)+'.'+real, {type:f.type, lastModified:f.lastModified});
|
||||
g.nomeEnviado=f.name;
|
||||
return g;
|
||||
}
|
||||
function recusa(lista){
|
||||
const el=$('recusa'); if(!el) return;
|
||||
if(!lista.length){ el.style.display='none'; el.innerHTML=''; return; }
|
||||
const exts=escapeHTML([...new Set(lista.map(f=>extDe(f.name)))].join(', '));
|
||||
el.style.display='block';
|
||||
if(lista.every(f=>/\.jpe?g$/i.test(f.name))){
|
||||
el.innerHTML='<b>JPG não dá para enviar.</b> JPG não tem fundo transparente, e o branco do fundo '+
|
||||
const disfarcados=lista.filter(f=>f.nomeEnviado).map(f=>f.nomeEnviado);
|
||||
el.innerHTML='<b>JPG não dá para enviar.</b> '+
|
||||
(disfarcados.length ? escapeHTML(disfarcados.join(', '))+' é JPG, mesmo com outro nome. ' : '')+
|
||||
'JPG não tem fundo transparente, e o branco do fundo '+
|
||||
'sai no filme. Exporte em '+(ehFolha()?'PNG ou PDF':'PNG')+' com fundo transparente e envie de novo.';
|
||||
return;
|
||||
}
|
||||
@@ -39,8 +64,9 @@ async function marcaResiduos(x){
|
||||
const marcada=await previaMarcada(x.previewSrc, x.an.pontos);
|
||||
if(folhas.includes(x)){ x.previewSrc=marcada; pintaFolha(); }
|
||||
}
|
||||
function sel(fs){
|
||||
async function sel(fs){
|
||||
if(!fs.length) return;
|
||||
fs=await Promise.all(fs.map(nomeReal));
|
||||
// Pixels cannot tell a loose artwork from a finished sheet, so the customer
|
||||
// declares it by choosing the product in the selector above. The declaration is
|
||||
// verified in medirFolha; the file never changes product or price on its own.
|
||||
|
||||
Reference in New Issue
Block a user