fix: a cancelled upload holds no reservation, an old ready sheet is flagged in the cart, the address check is guidance (DTF-WEB-14, 22, 24)
All checks were successful
Build and deploy / Validate source (push) Successful in 1m39s
Build and deploy / Integration suite on a real stack (push) Successful in 10m18s
Build and deploy / Secret scan and release gate (push) Successful in 16s
Build and deploy / Publish images (push) Successful in 2m33s

- 14: switching products cancelled the files being sent, but each one still
  waiting for a place opened its reservation when it got one, and none gave
  it back: 27 in ten seconds filled the cap of 30 (29/11). A cancelled upload
  now never starts, and one cancelled after starting gives its place back.
- 22: a ready sheet kept in the cart from before the 8 mm says so on its row
  and holds Pagar, instead of a refusal after the whole checkout.
- 24: "Preencha o endereço de entrega" is a warning, not an error.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-30 09:36:34 -03:00
parent 6ec0ea31a6
commit 9fc4d4e906
3 changed files with 33 additions and 5 deletions

View File

@@ -81,9 +81,17 @@ async function sendUpload(file, {api, prefix='/uploads', startPath=prefix, progr
signal?.addEventListener('abort',()=>xhr.abort(),{once:true});
xhr.send(body);
});
// A file taken off the page while it went gives its place back at once: a
// reservation it left would hold the pending cap for 20 minutes, and a
// customer switching products filled it (Sentry DTF-WEB-14, 29/11).
const giveBack=()=>{
fetch('/api'+prefix+'/'+id,{method:'DELETE',credentials:'same-origin'}).catch(()=>{});
if(resume)localStorage.removeItem(key);
};
if(signal?.aborted){giveBack();throw cancelled();}
for(let offset=0,part=1;offset<file.size;offset+=size,part++){
if(done.has(part))continue;
if(signal?.aborted)throw cancelled();
if(signal?.aborted){giveBack();throw cancelled();}
progress('Enviando '+file.name+' · parte '+part+'/'+Math.ceil(file.size/size));
// A part the network dropped goes again twice, on a fresh link, before
// the customer is asked to resume (DTF-WEB-13).
@@ -91,7 +99,8 @@ async function sendUpload(file, {api, prefix='/uploads', startPath=prefix, progr
const signed=await withRetry(options=>api(prefix+'/'+id+'/parts/'+part,{},options));
try{await put(signed.url,file.slice(offset,offset+size));break;}
catch(error){
if(error?.name==='AbortError'||attempt>=2)throw error;
if(error?.name==='AbortError'){giveBack();throw error;}
if(attempt>=2)throw error;
await new Promise(resolve=>setTimeout(resolve,(attempt+1)*3000));
}
}
@@ -104,6 +113,10 @@ async function sendUpload(file, {api, prefix='/uploads', startPath=prefix, progr
window.dtfUpload = async (file, options) => {
if(options?.signal?.aborted)throw new DOMException('Envio cancelado.','AbortError');
await uploadSlot();
try{return await sendUpload(file, options);}
try{
// Taken off the page while it waited for a place: no reservation at all.
if(options?.signal?.aborted)throw new DOMException('Envio cancelado.','AbortError');
return await sendUpload(file, options);
}
finally{releaseUploadSlot();}
};