feat: "Baixar todos" downloads every final file in the print queue, named after its order

To import a day's work into FlexiPRINT the operator opened each order in
Fila de impressão and downloaded its final. The column now has "Baixar
todos": the approved finals of every order in the queue, in queue order,
each named pedido-<n>-item-<i>-<original>. They download one by one from
storage with short-lived links; a zip of multi-GB sheets would go through
the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-05 11:48:57 -03:00
parent c5b1bd37a6
commit f567e6da89
4 changed files with 53 additions and 2 deletions

View File

@@ -624,6 +624,33 @@ def thumbnail(uid: UUID, user=Depends(operator)):
return Response(bytes(row['data']), media_type=row['mime'],
headers={'Cache-Control': 'private, max-age=86400', 'Content-Disposition': 'inline'})
@router.get('/api/operator/queue/finals')
def queue_finals(user=Depends(operator)):
"""The approved final files of every order in the print queue, in queue
order, each named after its order so a folder of them stays readable. The
browser downloads them straight from storage: a zip of multi-GB sheets
would go through the server."""
with db.connect() as c:
rows = c.execute(f'''SELECT o.number,f.item_index,u.object_key,u.name FROM dtf_local.orders o
JOIN dtf_local.order_files f ON f.order_id=o.id JOIN dtf_local.uploads u ON u.id=f.upload_id
WHERE o.state='fil' AND o.cancelled_at IS NULL AND {FINAL_OK}
ORDER BY COALESCE(o.queue_key, extract(epoch FROM o.created_at)),o.id,f.item_index,f.created_at''').fetchall()
files, names = [], set()
for row in rows:
prefix = f"pedido-{row['number']}-item-{row['item_index'] + 1}"
name = row['name'] if row['name'].startswith(prefix) else f"{prefix}-{row['name']}"
stem, dot, ext = name.rpartition('.')
copy = 2
while name in names:
name = f'{stem} ({copy}).{ext}' if dot else f'{ext} ({copy})'
copy += 1
names.add(name)
files.append({'number': row['number'], 'item': row['item_index'] + 1, 'name': name,
'url': storage.download(row['object_key'], name)})
audit('queue_finals_downloaded', operator=user, files=len(files))
return {'files': files}
@router.get('/api/operator/uploads/{uid}/download')
def download(uid: UUID, user=Depends(operator)):
with db.connect() as c:

View File

@@ -61,7 +61,13 @@ def run():
link=customer.call('/customer/orders/'+oid+'/files/'+final['id']+'/download')
assert urlopen(link['url']).read()==b'LOCAL FINAL VERSION ONE'
guest=Client();guest.call('/session');guest.call('/customer/orders/'+oid+'/files/'+final['id']+'/download',expected=404)
version=move('fil',version);version=move('imp',version);version=move('cor',version)
version=move('fil',version)
# The print queue's files come named after their order, straight from storage.
queued=customer.call('/operator/queue/finals',operator=True)['files']
mine=[f for f in queued if urlopen(f['url']).read()==b'LOCAL FINAL VERSION ONE']
assert len(mine)==1 and mine[0]['name'].startswith('pedido-%d-item-1-' % mine[0]['number']), queued
customer.call('/operator/queue/finals',expected=401)
version=move('imp',version);version=move('cor',version)
customer.call('/customer/orders/'+oid+'/files/'+final['id']+'/download',expected=404)
premature_final=upload_bytes(customer,b'FINAL BEFORE CUSTOMER CORRECTION',order_id=oid)
version=customer.call('/operator/orders/'+oid+'/final-files',

View File

@@ -95,6 +95,8 @@ main{padding:0 24px 24px}
.col-head .swatch{width:10px;height:10px;border-radius:3px;background:var(--c)}
.col-head .n{margin-left:auto;font-family:var(--mono);font-size:13.5px;color:var(--muted)}
.col-head small{font-size:13.5px;color:var(--faint)}
.col-head .col-sub{justify-content:space-between;min-height:30px}
.col-head .col-sub small{white-space:nowrap}
.col .empty{font-size:13.5px;color:var(--faint);padding:8px 2px}
.card{text-align:left;display:flex;flex-direction:column;gap:8px;padding:12px;border-radius:10px;border:1px solid var(--line2);background:var(--card);width:100%}
.card:hover,.card.open{border-color:var(--line3);background:#1E2226}

View File

@@ -172,6 +172,16 @@ function download(uid){return async()=>{
const result=await api('/uploads/'+uid+'/download');
const link=node('a');link.href=result.url;link.referrerPolicy='no-referrer';link.download=result.name;link.click();
};}
async function downloadQueue(){
const {files}=await api('/queue/finals');
if(!files.length){say('Nenhum arquivo final aprovado na fila.');return;}
say('Baixando '+files.length+(files.length>1?' arquivos':' arquivo')+' da fila… Se o navegador perguntar, permita vários downloads.',false,8000);
// One at a time: browsers drop clicks that come too close together.
for(const file of files){
const link=node('a');link.href=file.url;link.referrerPolicy='no-referrer';link.download=file.name;link.click();
await new Promise(r=>setTimeout(r,700));
}
}
function manifest(production){
const url=URL.createObjectURL(new Blob([JSON.stringify(production,null,2)],{type:'application/json'}));
const link=node('a');link.href=url;link.download='dtf-layout-'+production.sources[0].upload_id.slice(0,8)+'.json';
@@ -315,7 +325,13 @@ function renderBoard(){
// Finished orders are a recent window, not the whole history: say so.
const count=state==='fin'&&board.finished_total>orders.length?orders.length+' de '+board.finished_total:String(orders.length);
line.append(swatch,node('h2',title),node('span',count,'n'));
head.append(line,node('small',orders.length?metres(total)+' no total':'vazio'));
const sub=node('div',undefined,'col-sub');sub.append(node('small',orders.length?metres(total)+' no total':'vazio'));
// The print queue's files, all at once, to import into FlexiPRINT.
if(state==='fil'&&orders.length){
const all=downloadButton('Baixar todos',downloadQueue,'btn ghost small');all.title='Baixar os arquivos finais de todos os pedidos da fila';
sub.append(all);
}
head.append(line,sub);
column.append(head);
for(const order of orders)column.append(card(order));
if(state==='fin'&&finishedMore&&filter==='all')moreButton(column,true,loadOlderFinished);