Restore staged uploads after page reload
This commit is contained in:
@@ -205,12 +205,34 @@ async def upload_page(request: Request):
|
||||
SUM(CASE WHEN status='error' THEN 1 ELSE 0 END) AS errors
|
||||
FROM documents WHERE status != 'staged'"""
|
||||
).fetchone()
|
||||
staged_rows = conn.execute(
|
||||
"""SELECT id, image_path, page_number
|
||||
FROM documents
|
||||
WHERE status='staged'
|
||||
ORDER BY id"""
|
||||
).fetchall()
|
||||
|
||||
staged_documents = []
|
||||
for row in staged_rows:
|
||||
image_name = Path(row["image_path"]).name
|
||||
page_number = row["page_number"]
|
||||
if page_number:
|
||||
image_name = f"{image_name} (p{page_number})"
|
||||
staged_documents.append(
|
||||
{
|
||||
"id": row["id"],
|
||||
"image_path": row["image_path"],
|
||||
"name": image_name,
|
||||
}
|
||||
)
|
||||
|
||||
return render_template(
|
||||
templates,
|
||||
request,
|
||||
"index.html",
|
||||
{
|
||||
"stats": dict(stats) if stats else {},
|
||||
"staged_documents": staged_documents,
|
||||
"providers": get_available_providers(),
|
||||
"default_provider": get_default_provider(),
|
||||
},
|
||||
@@ -397,12 +419,16 @@ async def process_staged(
|
||||
provider = get_default_provider()
|
||||
|
||||
ids = [int(x) for x in doc_ids.split(",") if x.strip().isdigit()]
|
||||
if not ids:
|
||||
return RedirectResponse("/?staged=0", status_code=303)
|
||||
|
||||
with get_db() as conn:
|
||||
rows = conn.execute(
|
||||
f"SELECT id, image_path FROM documents WHERE id IN ({','.join('?' * len(ids))}) AND status='staged'",
|
||||
ids,
|
||||
).fetchall()
|
||||
if not rows:
|
||||
return RedirectResponse("/?staged=0", status_code=303)
|
||||
for row in rows:
|
||||
conn.execute(
|
||||
"UPDATE documents SET status='pending', provider=?, updated_at=CURRENT_TIMESTAMP WHERE id=?",
|
||||
|
||||
Reference in New Issue
Block a user