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=?",
|
||||
|
||||
+12
-1
@@ -124,7 +124,7 @@
|
||||
{% block scripts %}
|
||||
<script>
|
||||
// ─── Unified staging workflow ─────────────────────────────────
|
||||
const stagedItems = []; // {id, image_path, name}
|
||||
const stagedItems = {{ staged_documents|tojson }}; // {id, image_path, name}
|
||||
let uploading = false;
|
||||
|
||||
const cameraInput = document.getElementById('cameraInput');
|
||||
@@ -209,6 +209,14 @@ function finishThumb(thumb, item) {
|
||||
`;
|
||||
}
|
||||
|
||||
function renderExistingStaged() {
|
||||
gallery.innerHTML = '';
|
||||
for (const item of stagedItems) {
|
||||
const thumb = addPlaceholder(item.name);
|
||||
finishThumb(thumb, item);
|
||||
}
|
||||
}
|
||||
|
||||
async function removeStagedItem(id, btn) {
|
||||
const thumb = btn.closest('.staging-thumb');
|
||||
thumb.classList.add('removing');
|
||||
@@ -266,5 +274,8 @@ async function clearStaged() {
|
||||
gallery.innerHTML = '';
|
||||
refreshUI();
|
||||
}
|
||||
|
||||
renderExistingStaged();
|
||||
refreshUI();
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user