feat: the folders catch up on what passed while the Kanban computer was off
All checks were successful
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Successful in 3m27s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 56s

Dropstar's internal rules (2026-10-26): the folder must reproduce what passed,
not only what sits in the columns when the computer comes back, or a room
running 24 hours leaves a gap a week in the Finalizado archive.

- the Kanban remembers when the folders were chosen and asks for every order
  paid since then, whatever its stage; each file goes to its stage's folder,
  so an order finished while the computer was off lands in 3. Finalizado
- orders paid before the folders were chosen still stay out, so setting them
  up never pulls old orders back into the queue
- the server's file list for the folders and Baixar now loads only the orders
  that have a file, not every order in the stages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-27 10:15:16 -03:00
parent 35e64d77d7
commit 6a921415ea
4 changed files with 57 additions and 21 deletions

View File

@@ -230,8 +230,16 @@ const BRAVE_FLAG='brave://flags/#file-system-access-api';
const STAGE_FOLDERS={rec:'1. Arte recebida',tra:'2. Arte conferida',imp:'2. Arte conferida',rev:'2. Arte conferida',fin:'3. Finalizado'};
const KEEP_FINISHED_DAYS=30;
const FOLDER={mode:'showDirectoryPicker' in window?'folder':/Firefox\//.test(navigator.userAgent)?'downloads':'none',
brave:!!navigator.brave,handle:null,granted:false,downloads:false,
brave:!!navigator.brave,handle:null,granted:false,downloads:false,since:null,
saved:new Map(),busy:false,status:'',error:'',last:null,lastSig:null};
// When the folders were chosen: every order paid since then ends up in them,
// even one that went through while this computer was off (Dropstar's rules,
// 2026-10-26). Folders chosen before this existed count from their first round.
async function folderSince(reset=false){
let since=reset?null:await kv.get('folder-since').catch(()=>null);
if(!since){since=new Date().toISOString();await kv.set('folder-since',since).catch(()=>{});}
return FOLDER.since=since;
}
// Switched on: a chosen folder released, or automatic downloads.
const folderActive=()=>FOLDER.mode==='folder'?!!FOLDER.handle&&FOLDER.granted:FOLDER.downloads;
// The three folders started their own record: files saved by the single
@@ -251,7 +259,7 @@ async function restoreFolder(){
if(FOLDER.mode!=='folder')return;
try{FOLDER.handle=await kv.get('folder')||null;
if(FOLDER.handle){FOLDER.granted=(await FOLDER.handle.queryPermission({mode:'readwrite'}))==='granted';
FOLDER.saved=await loadSaved();
FOLDER.saved=await loadSaved();await folderSince();
if(!FOLDER.granted)setTimeout(()=>say('Para voltar a salvar os arquivos nas pastas, abra Integrações e clique em “Liberar pasta”.',false,10000),2500);}}
catch{FOLDER.handle=null;}
}
@@ -298,7 +306,8 @@ function folderCard(){
node('p','Dentro de “'+h.name+'”: o arquivo do pedido chega em Arte recebida, passa para Arte conferida quando o card vai para lá '+
'(e fica lá enquanto imprime e na Revisão) e vai para Finalizado quando o pedido é finalizado, onde fica '+KEEP_FINISHED_DAYS+' dias.'),
node('p','Pedido cancelado, excluído ou devolvido para correção: o arquivo sai das pastas. Arquivo trocado: a versão antiga sai. '+
'Pedidos que já estavam imprimindo quando a pasta foi escolhida não são baixados. Deixe o Kanban aberto neste computador.')],
'Pedidos que já estavam imprimindo quando a pasta foi escolhida não são baixados. Se este computador ficar desligado, '+
'ao voltar ele busca também o que passou nesse tempo, cada arquivo na pasta da etapa em que o pedido está. Deixe o Kanban aberto neste computador.')],
extra:[ghost('Trocar pasta',chooseFolder),ghost('Desligar',forgetFolder)]});
}
row.id='folder-card';return row;
@@ -321,6 +330,7 @@ async function chooseFolder(){
FOLDER.handle=handle;FOLDER.granted=true;FOLDER.lastSig=null;FOLDER.error='';FOLDER.last=null;
FOLDER.saved=await loadSaved();
await kv.set('folder',handle).catch(()=>{});
await folderSince(true);
await makeStageFolders();
paintFolder();say('Pastas '+[...new Set(Object.values(STAGE_FOLDERS))].join(', ')+' criadas dentro de “'+handle.name+'”.');syncFolder(true);
}
@@ -395,7 +405,7 @@ async function syncFolder(force=false){
try{
if(stages)await makeStageFolders();
const held=stages?[...new Set([...FOLDER.saved.values()].map(r=>r.order).filter(Boolean))].slice(-1000):[];
const {files,states}=await api('/queue/folder',{early:stages,held});
const {files,states}=await api('/queue/folder',{early:stages,held,since:stages?FOLDER.since||await folderSince():null});
const wanted=new Map(files.map(f=>[f.order+':'+f.item,f]));
const where=stages?'“'+FOLDER.handle.name+'”':'a pasta de downloads';
let removed=0, moved=0, saved=0;
@@ -416,9 +426,11 @@ async function syncFolder(force=false){
if(now&&now.upload_id===uid){await fetchInto(await stageDir(target),now);await record(uid,now,target);moved++;}
else{FOLDER.saved.delete(uid);await keepSaved();}
}
// New files: only orders in Arte recebida or Arte conferida. One already
// printing when the folder was chosen is the room's already.
const pending=files.filter(f=>!FOLDER.saved.has(f.upload_id)&&(stages?f.state==='rec'||f.state==='tra':f.state==='tra'));
// New files, each into its stage's folder: the server sends those in Arte
// recebida and Arte conferida, and the orders paid since the folders were
// chosen in any stage, so what passed while this computer was off comes in
// too. An order already printing when the folders were chosen is the room's.
const pending=files.filter(f=>!FOLDER.saved.has(f.upload_id)&&(stages?!!STAGE_FOLDERS[f.state]:f.state==='tra'));
for(const [i,file] of pending.entries()){
FOLDER.status=(stages?'Salvando ':'Baixando ')+(i+1)+' de '+pending.length+': '+file.name;paintFolder();
say(FOLDER.status,false,60000);