PDF sync: operations update all tabs (delete/rotate/reorder)

- 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
This commit is contained in:
treamz 2026-03-22 01:48:53 +03:00
parent 93952d0844
commit 9193a98bc4

View File

@ -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 res = await fetch('/pdf/delete', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ fileId, pages: pages.join(',') }) });
const data = await res.json(); const data = await res.json();
if (!res.ok) throw new Error(data.error); if (!res.ok) throw new Error(data.error);
showResult(data); await syncAfterOperation(data);
} catch(e) { showError(e.message); } } catch(e) { showError(e.message); }
document.getElementById('btnDeleteSelected').textContent = 'Удалить выбранные (0)'; document.getElementById('btnDeleteSelected').textContent = 'Удалить выбранные (0)';
updateDeleteCount();
}; };
window.executeRotatePages = async function() { 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 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(); const data = await res.json();
if (!res.ok) throw new Error(data.error); if (!res.ok) throw new Error(data.error);
showResult(data); await syncAfterOperation(data);
} catch(e) { showError(e.message); } } catch(e) { showError(e.message); }
}; };
@ -1878,13 +1879,44 @@
const data = await res.json(); const data = await res.json();
if (!res.ok) throw new Error(data.error); if (!res.ok) throw new Error(data.error);
if (hint) hint.textContent = 'Порядок сохранён'; if (hint) hint.textContent = 'Порядок сохранён';
showResult(data); await syncAfterOperation(data);
} catch(e) { } catch(e) {
if (hint) hint.textContent = 'Ошибка: ' + e.message; if (hint) hint.textContent = 'Ошибка: ' + e.message;
} }
}, 800); }, 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
}
}
})(); })();
</script> </script>