feat: a real progress bar per file while it uploads (Dropstar's third round, item 6)
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 3m42s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 56s

A file starts uploading as soon as it is on the product page, not once
the item is in the cart. Under the uploader, each file has its row:
"Enviando NOME · 62% · 1,2 MB de 2,0 MB", then the security check, then
"enviado"; a failure says why, with "Tentar de novo". Each part goes
through XMLHttpRequest, so the bytes move while a part is on its way
instead of once per 8 MB part. A file taken off the page, and in no cart
item, stops uploading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-29 18:18:56 -03:00
parent 95e7c64501
commit a5417d200e
8 changed files with 104 additions and 15 deletions

View File

@@ -58,6 +58,40 @@ Z.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){I.click();e.pr
if(ev==='drop') sel([...e.dataTransfer.files]);
}));
I.addEventListener('change',()=>sel([...I.files]));
// Each file's upload, under the uploader (Dropstar, 2026-10-29): the bytes
// sent of its size, then the security check; a failure says why. It starts
// as soon as the file is on the page (checkout.js sends it).
const ENVIADO_MS=4000;
const enviadoEm=new WeakMap();
// A few repaints a second, page in view or not: progress comes in far more often.
let envioQuadro=0;
function agendaEnvios(){ if(!envioQuadro) envioQuadro=setTimeout(()=>{ envioQuadro=0; pintaEnvios(); },120); }
function pintaEnvios(){
const el=$('envios'); if(!el || !window.dtfEnvio) return;
dtfEnvio.manter([...artes,...folhas].map(x=>x.f));
// Off the product page there is no uploader to paint under.
if(!MODOS[modo]){ el.innerHTML=''; return; }
const agora=Date.now();
el.innerHTML=(ehFolha()?folhas:artes).map((x,i)=>{
const f=x.f, e=dtfEnvio.estado(f), nome='<b>'+escapeHTML(f.name)+'</b>';
if(!e) return '';
if(e.fase==='pronto'){
if(!enviadoEm.has(f)){ enviadoEm.set(f,agora); setTimeout(agendaEnvios,ENVIADO_MS+50); }
return agora-enviadoEm.get(f)>ENVIADO_MS ? '' : '<div class="envio ok">'+icone('okCirculo')+'<span>'+nome+' enviado</span></div>';
}
if(e.fase==='falhou') return '<div class="envio erro"><span>Não foi possível enviar '+nome+': '+
escapeHTML(e.erro.replace(/\.$/,''))+'.</span><button type="button" data-envio="'+i+'">Tentar de novo</button></div>';
const pct=e.fase==='verificando' ? 100 : Math.floor(e.enviado/f.size*100);
return '<div class="envio"><span>'+(e.fase==='verificando' ? 'Verificando a segurança de '+nome+'…'
: 'Enviando '+nome+' · '+pct+'% · '+fmt(e.enviado)+' de '+fmt(f.size))+'</span>'+
'<div class="envioBarra"><i style="width:'+pct+'%"></i></div></div>';
}).join('');
}
addEventListener('dtf-envio',agendaEnvios);
$('envios').addEventListener('click',e=>{
const b=e.target.closest('[data-envio]'); if(!b || !MODOS[modo]) return;
const x=(ehFolha()?folhas:artes)[+b.dataset.envio]; if(x) dtfEnvio.deNovo(x.f);
});
// A sheet with residue gets its preview circled where the dots are.
async function marcaResiduos(x){
if(!(x.an && x.an.residuos && !x.an.fundoChapado && x.previewSrc && x.an.pontos?.length)) return;
@@ -84,6 +118,8 @@ async function sel(fs){
fs=fs.filter(f=>f.size<=max);
}
if(!fs.length) return;
// On their way at once; a JPG is refused at the order anyway.
fs.filter(f=>!/\.jpe?g$/i.test(f.name)).forEach(f=>window.dtfEnvio?.enviar(f));
if(ehFolha()){
const novas=fs.map(f=>({f, med:null, rep:1, m:0, semAnalise:null}));
folhas=folhas.concat(novas); // soma, não substitui