feat: the three folders are created when the main one is chosen, numbered in the flow's order
All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 3m31s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m4s

Tried on a local Kanban with Dropstar's flow: the folders appeared only with
the first file, and a listing showed Arte conferida before Arte recebida.

- "1. Arte recebida", "2. Arte conferida" and "3. Finalizado" are created
  as soon as the main folder is chosen or released, and again on every
  round if someone deletes one
- numbered, a folder listing shows them in the order the file moves

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-26 17:25:01 -03:00
parent ee1159065a
commit 0088158dc0
3 changed files with 24 additions and 17 deletions

View File

@@ -226,7 +226,8 @@ const BRAVE_FLAG='brave://flags/#file-system-access-api';
// to Arte conferida (the queue) with the card and stays there while it prints
// and is checked in Revisão, then goes to Finalizado, kept 30 days. Correção,
// a cancellation or a deletion takes it out; a replaced final is swapped.
const STAGE_FOLDERS={rec:'Arte recebida',tra:'Arte conferida',imp:'Arte conferida',rev:'Arte conferida',fin:'Finalizado'};
// Numbered so a folder listing shows them in the flow's order.
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,
@@ -320,11 +321,12 @@ 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(()=>{});
paintFolder();say('Os arquivos dos pedidos vão ser salvos nas três pastas dentro de “'+handle.name+'”.');syncFolder();
await makeStageFolders();
paintFolder();say('Pastas '+[...new Set(Object.values(STAGE_FOLDERS))].join(', ')+' criadas dentro de “'+handle.name+'”.');syncFolder(true);
}
async function releaseFolder(){
FOLDER.granted=(await FOLDER.handle.requestPermission({mode:'readwrite'}))==='granted';
FOLDER.lastSig=null;FOLDER.error='';paintFolder();if(FOLDER.granted)syncFolder();
FOLDER.lastSig=null;FOLDER.error='';if(FOLDER.granted)await makeStageFolders();paintFolder();if(FOLDER.granted)syncFolder(true);
}
async function forgetFolder(){
FOLDER.handle=null;FOLDER.granted=false;FOLDER.error='';FOLDER.status='';
@@ -352,6 +354,8 @@ async function writeWhole(dir,name,source){
await whole.write(await temp.getFile());await whole.close();await dir.removeEntry(temp.name);}
}
const stageDir=name=>FOLDER.handle.getDirectoryHandle(name,{create:true});
// The three folders exist from the moment the main one is chosen, empty or not.
const makeStageFolders=()=>Promise.all([...new Set(Object.values(STAGE_FOLDERS))].map(stageDir));
// Remove a saved file from its folder; one already gone (someone took it) is fine.
async function removeSaved(rec){
const dir=await stageDir(rec.folder);
@@ -389,6 +393,7 @@ async function syncFolder(force=false){
if(!force&&sig===FOLDER.lastSig)return;
FOLDER.busy=true;
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 wanted=new Map(files.map(f=>[f.order+':'+f.item,f]));