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
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:
@@ -126,27 +126,42 @@
|
||||
message('Nenhum pedido aguardando pagamento.');
|
||||
button('Ir para o carrinho', () => vaiPara(CARRINHO));
|
||||
}
|
||||
// Files start uploading as soon as they are in the cart, so a sheet of
|
||||
// several GB is on its way while the customer fills in the order. The
|
||||
// checkout waits for whatever is still going.
|
||||
// Files start uploading as soon as they are on the product page (Dropstar,
|
||||
// 2026-10-29; before, once in the cart), so a sheet of several GB is on its
|
||||
// way while the customer builds the order. The checkout waits for whatever
|
||||
// is still going.
|
||||
const envios=new Map();
|
||||
const chaveArquivo=f=>[f.name,f.size,f.lastModified].join('|');
|
||||
function enviar(file) {
|
||||
const k=chaveArquivo(file);
|
||||
let e=envios.get(k);
|
||||
if (!e) {
|
||||
e={file, sent:0, done:false, failed:null};
|
||||
e={file, sent:0, done:false, failed:null, stop:new AbortController()};
|
||||
e.promise=(async()=>{
|
||||
const session=await ready;
|
||||
return window.dtfUpload(file,{api,scope:session.cart_scope,progress:()=>{},
|
||||
return window.dtfUpload(file,{api,scope:session.cart_scope,progress:()=>{},signal:e.stop.signal,
|
||||
onBytes:n=>{e.sent=n;pintaEnvio();}});
|
||||
})();
|
||||
e.promise.then(()=>{e.done=true;falhas.delete(k);pintaEnvio();},
|
||||
error=>{envios.delete(k);falhas.set(k,{file,error});pintaEnvio();});
|
||||
error=>{envios.delete(k);if(error?.name!=='AbortError')falhas.set(k,{file,error});pintaEnvio();});
|
||||
envios.set(k,e);
|
||||
}
|
||||
return e.promise;
|
||||
}
|
||||
// Each file's upload as the product page shows it, under the uploader.
|
||||
window.dtfEnvio={
|
||||
enviar:file=>{if(!falhas.has(chaveArquivo(file)))enviar(file).catch(()=>{});},
|
||||
estado:file=>{const k=chaveArquivo(file),e=envios.get(k),f=falhas.get(k);
|
||||
return f?{fase:'falhou',erro:f.error?.message||'erro no envio'}
|
||||
:!e?null:e.done?{fase:'pronto'}:e.sent>=file.size?{fase:'verificando'}:{fase:'enviando',enviado:e.sent};},
|
||||
deNovo:file=>{falhas.delete(chaveArquivo(file));enviar(file).catch(()=>{});pintaEnvio();},
|
||||
// A file taken off the page, and in no cart item, stops going.
|
||||
manter:files=>{
|
||||
const quero=new Set([...files,...pedido.flatMap(it=>it.localFiles||[]),...(itemAtual?.localFiles||[])].map(chaveArquivo));
|
||||
for(const [k,e] of envios) if(!e.done && !quero.has(k)) e.stop.abort();
|
||||
for(const k of falhas.keys()) if(!quero.has(k)) falhas.delete(k);
|
||||
},
|
||||
};
|
||||
// The Kanban shows each order's artwork from the small picture this page
|
||||
// already made of it (site-upload.js). Never blocks the order: a picture that
|
||||
// fails to go leaves the Kanban with the layout drawing it shows today.
|
||||
@@ -203,6 +218,7 @@
|
||||
return 'Enviando seus arquivos · '+restante(e);
|
||||
}
|
||||
function pintaEnvio() {
|
||||
window.dispatchEvent(new Event('dtf-envio'));
|
||||
const e=estadoEnvio(), texto=textoEnvio(e);
|
||||
const el=document.getElementById('envioArq');
|
||||
const falhou=arquivosDoCarrinho().map(f=>falhas.get(chaveArquivo(f))).filter(Boolean);
|
||||
|
||||
Reference in New Issue
Block a user