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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user