feat: places per machine, drops on Imprimindo go to your machine, a Venda carries its seller to Tiny (DTF-WEB-V)
All checks were successful
Build and deploy / Validate source (push) Successful in 10s
Build and deploy / Integration suite on a real stack (push) Successful in 7m38s
Build and deploy / Secret scan and release gate (push) Successful in 7s
Build and deploy / Publish images (push) Successful in 1m19s

Marcus, 2026-11-17:
- Each machine has its own places (machines.places, 1 to 6, three to
  start): orders at once in Imprimindo and files at once in its hot
  folder. Admin sets it in the machine dialog; Admin and Gestão in the
  machine sheet's Dados da máquina. A third order shows as "Na vez".
- Whoever is signed in on a machine drops a card anywhere in Imprimindo
  and it goes to that machine; without one, the lane under the pointer.
- Each Kanban user may name their Tiny seller (Usuários, read from
  Tiny's own list); a montador Venda reaches Tiny with the seller of who
  assembled it. Every other order still sends no seller.
- A folder download that never reached storage (a network drop) waits
  for the next pass as a warning and is reported only if it keeps
  failing (Sentry DTF-WEB-V).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-17 14:18:19 -03:00
parent c61ac27ca4
commit aaa6090642
19 changed files with 244 additions and 63 deletions

View File

@@ -286,8 +286,9 @@ const REVIEWS_FOLDER='Revisões';
const FOLDER={mode:'showDirectoryPicker' in window?'folder':/Firefox\//.test(navigator.userAgent)?'downloads':'none',
brave:!!navigator.brave,handle:null,granted:false,downloads:false,since:null,
saved:new Map(),busy:false,status:'',error:'',last:null,lastSig:null,
// Passes in a row each file was held open by another program (DTF-WEB-M).
locked:new Map(),
// Passes in a row each file was held open by another program (DTF-WEB-M),
// or could not be downloaded for the network (DTF-WEB-V).
locked:new Map(),unreachable:new Map(),
// Since when the main folder does not answer (DTF-WEB-P), and whether that was reported.
awaySince:0,awayReported:false,
// Whether this page load cleared the old version's leftovers (order #30).
@@ -501,10 +502,11 @@ async function sweepLeftovers(dir,depth){
// tries again.
// A file that arrived incomplete waits for the next pass too, reported.
const LOCKED=new Set(['NoModificationAllowedError','InvalidModificationError','NotReadableError','InvalidStateError']);
function fileStep(locked,incomplete){
function fileStep(locked,incomplete,unreachable){
return async(name,fn)=>{try{await fn();return true;}
catch(e){
if(e.name==='IncompleteFile'){incomplete.push(e.message);return false;}
if(e.unreachable){unreachable.push(name);return false;}
if(!LOCKED.has(e.name))throw e;locked.push(name);return false;}};
}
const stageDir=name=>FOLDER.handle.getDirectoryHandle(name,{create:true});
@@ -532,8 +534,14 @@ async function moveSaved(rec,to){
return true;
}
// One file from storage, whole, into a folder.
// A download that never reached storage or the server (the network dropped
// for a moment, Sentry DTF-WEB-V) is marked unreachable: the file waits for
// the next pass, like one held open, and is reported only if it keeps failing.
async function fetchFile(url,options){
try{return await fetch(url,options);}catch(e){e.unreachable=true;throw e;}
}
async function fetchInto(dir,file,watched=false){
const r=await fetch(file.url,{referrerPolicy:'no-referrer'});
const r=await fetchFile(file.url,{referrerPolicy:'no-referrer'});
if(!r.ok||!r.body)throw new Error('não foi possível baixar '+file.name+' (erro '+r.status+').');
await writeWhole(dir,file.name,r,watched);
}
@@ -598,7 +606,7 @@ async function syncFolder(force=false){
const wanted=new Map(files.map(f=>[f.upload_id,f]));
const where=stages?'“'+FOLDER.handle.name+'”':'a pasta de downloads';
let removed=0, moved=0, saved=0;
const locked=[], incomplete=[], step=fileStep(locked,incomplete);
const locked=[], incomplete=[], unreachable=[], step=fileStep(locked,incomplete,unreachable);
if(stages){
await clearWork();
if(!FOLDER.swept){for(const name of FLOW_FOLDERS)await sweepLeftovers(await stageDir(name),2);FOLDER.swept=true;}
@@ -652,7 +660,7 @@ async function syncFolder(force=false){
for(const r of receipts){
try{await api('/orders/'+r.order+'/receipt/claim',{});}catch(e){if(e.status===409)continue;throw e;}
await step(r.name,async()=>{try{
const res=await fetch('/api/operator/orders/'+r.order+'/receipt');
const res=await fetchFile('/api/operator/orders/'+r.order+'/receipt');
if(!res.ok||!res.body)throw new Error('não foi possível gerar '+r.name+' (erro '+res.status+').');
await writeWhole(await stageDir(RECEIPTS_FOLDER),r.name,res,true);printed++;
}catch(e){await api('/orders/'+r.order+'/receipt/release',{}).catch(()=>{});throw e;}});
@@ -666,7 +674,7 @@ async function syncFolder(force=false){
FOLDER.status='Salvando revisão: '+review.name;paintFolder();
if(!await step(review.name,async()=>{
const view=await api('/orders/'+review.order+'/reviews/'+review.id+'/view');
const res=await fetch(view.url,{referrerPolicy:'no-referrer'});
const res=await fetchFile(view.url,{referrerPolicy:'no-referrer'});
if(!res.ok||!res.body)throw new Error('não foi possível baixar '+review.name+' (erro '+res.status+').');
await writeWhole(await stageDir(REVIEWS_FOLDER),review.name,res);
}))continue;
@@ -685,6 +693,19 @@ async function syncFolder(force=false){
// Expected while the FlexiPRINT reads a file: a warning the first time, and
// an error (which reaches Sentry) only when the same file is still held
// after LOCKED_REPORT_PASSES passes (Sentry DTF-WEB-M).
// Not downloaded for the network: a warning, and an error (so in Sentry)
// only when the same file still fails after LOCKED_REPORT_PASSES passes.
for(const name of [...FOLDER.unreachable.keys()])if(!unreachable.includes(name))FOLDER.unreachable.delete(name);
for(const name of unreachable)FOLDER.unreachable.set(name,(FOLDER.unreachable.get(name)||0)+1);
if(unreachable.length){
FOLDER.lastSig=null;
const stuck=unreachable.filter(name=>FOLDER.unreachable.get(name)===LOCKED_REPORT_PASSES);
FOLDER.error='Não foi possível baixar '+unreachable[0]+(unreachable.length>1?' e mais '+(unreachable.length-1):'')+
' agora (a rede oscilou). Os outros foram gravados; o Kanban tenta de novo em 30 s.';
if(stuck.length)say('Pastas automáticas: '+stuck.join(', ')+' não baixa há '+Math.round(LOCKED_REPORT_PASSES*30/60)+
' minutos. Confira a internet deste computador.',true);
else if(unreachable.some(name=>FOLDER.unreachable.get(name)===1))say('Pastas automáticas: '+FOLDER.error);
}
for(const name of [...FOLDER.locked.keys()])if(!locked.includes(name))FOLDER.locked.delete(name);
for(const name of locked)FOLDER.locked.set(name,(FOLDER.locked.get(name)||0)+1);
if(locked.length){
@@ -971,7 +992,7 @@ function stageLimitsDialog(){
}).catch(error=>say(error.message,true));
}
function field(label,input,hint){
const l=node('label',undefined,'fld');l.append(label,input);if(hint)l.append(node('small',hint));return l;
const l=node('label',undefined,'fld');l.append(label,input);if(hint)l.append(hint instanceof Node?hint:node('small',hint));return l;
}
// A checkbox drawn as the design's box.
function checkbox(label,input){