From 9193a98bc49287797411c68f1761ea79b5ad1913 Mon Sep 17 00:00:00 2001 From: treamz Date: Sun, 22 Mar 2026 01:48:53 +0300 Subject: [PATCH] PDF sync: operations update all tabs (delete/rotate/reorder) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - After any page operation, result PDF re-uploaded as new working file - All grids (delete/rotate/reorder) refresh with updated pages - File list updates with new page count - Previews regenerated from modified PDF - Seamless workflow: delete pages → rotate remaining → reorder --- public/pdf.html | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/public/pdf.html b/public/pdf.html index 8e7259a..6706a16 100644 --- a/public/pdf.html +++ b/public/pdf.html @@ -1814,9 +1814,10 @@ const res = await fetch('/pdf/delete', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ fileId, pages: pages.join(',') }) }); const data = await res.json(); if (!res.ok) throw new Error(data.error); - showResult(data); + await syncAfterOperation(data); } catch(e) { showError(e.message); } document.getElementById('btnDeleteSelected').textContent = 'Удалить выбранные (0)'; + updateDeleteCount(); }; window.executeRotatePages = async function() { @@ -1828,7 +1829,7 @@ const res = await fetch('/pdf/rotate', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ fileId, pages: pages.length ? pages.join(',') : 'all', angle: state.rotateAngle || 90 }) }); const data = await res.json(); if (!res.ok) throw new Error(data.error); - showResult(data); + await syncAfterOperation(data); } catch(e) { showError(e.message); } }; @@ -1878,13 +1879,44 @@ const data = await res.json(); if (!res.ok) throw new Error(data.error); if (hint) hint.textContent = 'Порядок сохранён'; - showResult(data); + await syncAfterOperation(data); } catch(e) { if (hint) hint.textContent = 'Ошибка: ' + e.message; } }, 800); } + + // After any page operation, re-upload the result as the new working file + async function syncAfterOperation(data) { + if (!data.downloadUrl) return; + showResult(data); + + // Download the result and re-upload as new working file + try { + const res = await fetch(data.downloadUrl); + const blob = await res.blob(); + const formData = new FormData(); + const selFile = state.files.find(f => f.id === state.selectedFileId); + const fileName = selFile ? selFile.name : 'modified.pdf'; + formData.append('files', blob, fileName); + + const uploadRes = await fetch('/pdf/upload', { method: 'POST', body: formData }); + const uploadData = await uploadRes.json(); + if (uploadData.files && uploadData.files.length) { + const newFile = uploadData.files[0]; + // Replace the old file in state + const oldId = state.selectedFileId; + state.files = state.files.map(f => f.id === oldId ? newFile : f); + state.selectedFileId = newFile.id; + // Re-render everything + renderFileList(); + } + } catch(e) { + // Silent — result is still downloadable + } + } + })();