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

@@ -46,7 +46,17 @@
let data;
try { data = text ? JSON.parse(text) : {}; }
catch (_) { throw new Error(response.ok ? 'Resposta inválida do serviço.' : 'O serviço está indisponível. Tente novamente em instantes.'); }
if (!response.ok) { const error=new Error(problem(data.detail));error.status=response.status;throw error; }
if (!response.ok) {
const text=problem(data.detail);
// A validation the customer cannot read still needs to reach us (Sentry
// picks up console.error later); the customer keeps the generic sentence.
if (response.status===422 && text==='Não foi possível concluir. Confira os dados e tente de novo.')
console.error('Detalhe da validação recusada:',data.detail);
const error=new Error(text);error.status=response.status;
const retry=response.headers.get('Retry-After');
if(retry!=null)error.retryAfter=retry;
throw error;
}
return data;
};
// A refusal as one sentence: the server's own, or the first field a form
@@ -262,10 +272,35 @@
pintaEnvio();
}
const arquivosDoCarrinho=()=>[...pedido.filter(it=>it.marcado!==false),...(busy&&itemAtual?[itemAtual]:[])].flatMap(it=>it.localFiles||[]);
// Every file of the paying cart must be sent (and none failed) before the
// quote and before the payment button (bugs B2 and B4, Marcus 2026-11-11).
function faltaEnvio(){
const files=arquivosDoCarrinho();
let pending=0,failed=0;
for(const f of files){
const k=chaveArquivo(f);
if(falhas.has(k)){failed++;continue;}
const e=envios.get(k);
if(!e||!e.done)pending++;
}
return {total:files.length,pending,failed,falta:pending+failed};
}
window.dtfFaltaEnvio=faltaEnvio;
function faltaEnvioMensagem(){
const missing=[];
for(const f of arquivosDoCarrinho()){
const k=chaveArquivo(f),e=envios.get(k);
if(falhas.has(k)||!e||!e.done)missing.push(f);
}
if(!missing.length) return '';
return 'Falta enviar '+missing[0].name+
(missing.length>1?' (e mais '+(missing.length-1)+')':'');
}
const gb=n=>(n/1073741824).toLocaleString('pt-BR',{maximumFractionDigits:1})+' GB';
const mb=n=>n>=1073741824 ? gb(n) : Math.round(n/1048576)+' MB';
// Where the uploads stand, and roughly how long is left from the recent speed.
const amostras=[];
let ultimaFalta=null;
function estadoEnvio() {
const files=arquivosDoCarrinho(); if(!files.length) return null;
let total=0, sent=0, pendentes=0;
@@ -292,6 +327,13 @@
return 'Enviando seus arquivos · '+restante(e);
}
function pintaEnvio() {
// The cart button carries the uploads too (B2): repaint it only when the
// number of missing files changes, not on every progress tick.
const falta=faltaEnvio().falta;
if(falta!==ultimaFalta){
ultimaFalta=falta;
if(typeof pintaPedido==='function')pintaPedido();
}
window.dispatchEvent(new Event('dtf-envio'));
const e=estadoEnvio(), texto=textoEnvio(e);
const el=document.getElementById('envioArq');
@@ -391,6 +433,8 @@
if (!clienteOk() || !entrega.cotado) return;
if (!enderecoOk()) return message('Preencha o endereço de entrega.','error');
if (!cartPodeEnviar()) return message('Revise a qualidade e confirme a ressalva de cada item antes de enviar o pedido.','error');
const semArquivo=faltaEnvioMensagem();
if (semArquivo) return message(semArquivo+'.','error');
const cart = itensAPagar();
if (!cart.length) return message('Adicione um item ao pedido.','error');
const initialCart=cartSnapshot();