fix: large carts upload all their files (Marcus's bugs of 11/11, B1 to B4)

B1: an upload start was limited to 60 per 15 minutes per session, so a
66-file cart failed with 'Muitas tentativas'; now 1000 per session and
3000 per source, and the Site waits Retry-After and retries quietly.
B2: a failed file shows its error and 'Tentar de novo' on its own card, and
payment stays blocked with 'Falta enviar N arquivos'. B3: after signing in
again, an upload id the new session does not own (403) is dropped and the
file starts again. B4: the quote is never created before every file is
sent, and an untranslatable 422 is logged for Sentry.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-11 14:49:04 -03:00
parent 07515abbd8
commit 7a24c66997
7 changed files with 180 additions and 12 deletions

View File

@@ -66,9 +66,44 @@ 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); }
// A failed upload must show on the file's own card too (B2, Marcus 11/11):
// the same red block and "Tentar de novo" as the row under the uploader, on
// the sheet/art card itself, so the list does not look complete.
function pintaErrosDosArquivos(){
const lista=$('lista'); if(!lista || !window.dtfEnvio) return;
const decorate=(selector,items,kind)=>{
items.forEach((item,index)=>{
const card=lista.querySelector(selector.replace('{i}',index));
if(!card) return;
const estado=dtfEnvio.estado(item.f);
const atual=card.querySelector('[data-envio-falha]');
if(!estado || estado.fase!=='falhou'){ if(atual) atual.remove(); return; }
if(atual){
// Keep the block while the file is failed: a repaint for another
// file's progress must not take the button from under the pointer.
const texto=atual.querySelector('span');
if(texto) texto.textContent='Não foi possível enviar '+item.f.name+': '+
(estado.erro||'erro no envio').replace(/\.$/,'')+'.';
return;
}
const box=document.createElement('div');
box.className='envio erro';box.dataset.envioFalha='1';
const texto=document.createElement('span');
texto.textContent='Não foi possível enviar '+item.f.name+': '+
(estado.erro||'erro no envio').replace(/\.$/,'')+'.';
const button=document.createElement('button');
button.type='button';button.textContent='Tentar de novo';
button.dataset.envioCard=kind;button.dataset.envioIndex=String(index);
box.append(texto,button);card.append(box);
});
};
decorate('[data-folha="{i}"]',folhas,'folha');
decorate('[data-arte="{i}"]',artes,'arte');
}
function pintaEnvios(){
const el=$('envios'); if(!el || !window.dtfEnvio) return;
dtfEnvio.manter([...artes,...folhas].map(x=>x.f));
pintaErrosDosArquivos();
// Off the product page there is no uploader to paint under.
if(!MODOS[modo]){ el.innerHTML=''; return; }
const agora=Date.now();
@@ -92,6 +127,11 @@ $('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);
});
$('lista').addEventListener('click',e=>{
const b=e.target.closest('[data-envio-card]'); if(!b || !window.dtfEnvio) return;
const x=(b.dataset.envioCard==='folha'?folhas:artes)[+b.dataset.envioIndex];
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;