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
+ }
+ }
+
})();