Some checks failed
Build and deploy / Validate source (push) Successful in 12s
Build and deploy / Integration suite on a real stack (push) Failing after 2m36s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Has been skipped
Sheets of several GB are the normal order. The upload limit is now 5 GB. ClamAV scans files up to 2 GB; a larger file is released only when its first bytes match the format its name claims, and a disguised file is refused. The Site grades a sheet over 150 MB from the pixel size in its PNG, JPEG or WebP header without decoding it, and reads large PDFs in ranges. The worker never opens a source over 300 MB: a finished sheet placed whole becomes its own print file, which the Kanban offers to approve as the final, and anything else goes to hand preparation. Files start uploading as they enter the cart, with progress in the summary, and each part renews the reservation so slow uploads do not expire. Quotas grow to 50 GB per customer and 500 GB in total; the Swarm config for ClamAV is renamed because a deployed config cannot change in place. Verified locally with a 386 MB and a 1.8 GB PNG (scanned, paid, original as print file), a 2.3 GB PNG (format check) and a disguised 2.3 GB file (refused). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
2.3 KiB
JavaScript
38 lines
2.3 KiB
JavaScript
/* Shared direct multipart transport for customer originals/corrections and operator finals. */
|
|
window.dtfUpload = async (file, {api, prefix='/uploads', startPath=prefix, progress=()=>{}, onBytes=()=>{}, scope='guest', resume=true}) => {
|
|
const samples=new Blob([file.slice(0,65536),file.slice(Math.max(0,file.size-65536))]);
|
|
const hash=Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',await samples.arrayBuffer())),b=>b.toString(16).padStart(2,'0')).join('');
|
|
const key='dtf-upload:'+JSON.stringify([scope,file.name,file.size,file.lastModified,hash]);
|
|
let id=resume?localStorage.getItem(key):null,state;
|
|
if(id){try{state=await api(prefix+'/'+id);}catch(error){if(![404,410].includes(error.status))throw error;id=null;}}
|
|
if(!id){state=await api(startPath,{name:file.name,size:file.size});id=state.id;if(resume)localStorage.setItem(key,id);}
|
|
async function waitForScan(){
|
|
onBytes(file.size);
|
|
// The antivirus streams the whole file: about a second per 2 MB, and at
|
|
// least two and a half minutes.
|
|
const attempts=Math.max(150,Math.ceil(file.size/2e6));
|
|
for(let attempt=0;attempt<attempts;attempt++){
|
|
const checked=await api(prefix+'/'+id);
|
|
if(checked.scan_state==='clean')return id;
|
|
if(['rejected','error'].includes(checked.scan_state))throw new Error(checked.scan_reason||'Arquivo bloqueado pela verificação de segurança.');
|
|
progress('Verificando segurança de '+file.name+'…');
|
|
await new Promise(resolve=>setTimeout(resolve,1000));
|
|
}
|
|
throw new Error('Verificação de segurança pendente. Tente novamente para consultar o resultado.');
|
|
}
|
|
if(state.complete)return waitForScan();
|
|
const done=new Set(state.parts||[]),size=state.part_bytes;
|
|
onBytes(Math.min(file.size,done.size*size));
|
|
for(let offset=0,part=1;offset<file.size;offset+=size,part++){
|
|
if(done.has(part))continue;
|
|
progress('Enviando '+file.name+' · parte '+part+'/'+Math.ceil(file.size/size));
|
|
const signed=await api(prefix+'/'+id+'/parts/'+part,{});
|
|
const response=await fetch(signed.url,{method:'PUT',body:file.slice(offset,offset+size)});
|
|
if(!response.ok)throw new Error('Upload interrompido. Tente novamente para retomar.');
|
|
done.add(part);
|
|
onBytes(Math.min(file.size,done.size*size));
|
|
}
|
|
await api(prefix+'/'+id+'/complete',{});
|
|
return waitForScan();
|
|
};
|