fix: clear ONLYOFFICE internal cache after save + mtime-based download URL
This commit is contained in:
Binary file not shown.
@@ -6,6 +6,6 @@
|
|||||||
"originalName": "master_cv_template.docx",
|
"originalName": "master_cv_template.docx",
|
||||||
"path": "/root/workspace/cv-app/renderer/carbone-templates/433a0593-d3cf-414e-8763-ab5f87cbc75c.docx",
|
"path": "/root/workspace/cv-app/renderer/carbone-templates/433a0593-d3cf-414e-8763-ab5f87cbc75c.docx",
|
||||||
"uploadedAt": "2026-07-16T09:03:29.601Z",
|
"uploadedAt": "2026-07-16T09:03:29.601Z",
|
||||||
"updatedAt": "2026-07-16T11:17:19.354Z"
|
"updatedAt": "2026-07-16T11:21:01.888Z"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -146,10 +146,11 @@ router.get('/:templateId/config', (req, res) => {
|
|||||||
const docKey = generateDocKey(templateId, fileMtime);
|
const docKey = generateDocKey(templateId, fileMtime);
|
||||||
const fileName = template.originalName || template.name + '.docx';
|
const fileName = template.originalName || template.name + '.docx';
|
||||||
|
|
||||||
// Add cache-busting timestamp to the document URL so ONLYOFFICE
|
// Add file mtime as cache-buster to the document URL so ONLYOFFICE
|
||||||
// always fetches the latest version from our backend
|
// always fetches the latest version from our backend.
|
||||||
const cacheBuster = Date.now();
|
// The mtime changes every time the file is saved, so the URL is
|
||||||
const documentUrl = `${BACKEND_PUBLIC_URL}/api/onlyoffice/${templateId}/download?cb=${cacheBuster}`;
|
// different after each save, forcing ONLYOFFICE to re-download.
|
||||||
|
const documentUrl = `${BACKEND_PUBLIC_URL}/api/onlyoffice/${templateId}/download?mtime=${fileMtime}&cb=${Date.now()}`;
|
||||||
const callbackUrl = `${BACKEND_PUBLIC_URL}/api/onlyoffice/${templateId}/callback`;
|
const callbackUrl = `${BACKEND_PUBLIC_URL}/api/onlyoffice/${templateId}/callback`;
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
@@ -316,6 +317,17 @@ router.post('/:templateId/callback', async (req, res) => {
|
|||||||
|
|
||||||
console.log(`Template "${template.name}" updated successfully (${response.data.length} bytes)`);
|
console.log(`Template "${template.name}" updated successfully (${response.data.length} bytes)`);
|
||||||
|
|
||||||
|
// Clear ONLYOFFICE's internal document cache for this template
|
||||||
|
// so the next edit session fetches the fresh file
|
||||||
|
try {
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
execSync(`docker exec onlyoffice-server find /var/lib/onlyoffice/documentserver/App_Data/cache -name "cvtemplate_${templateId}*" -type d -exec rm -rf {} + 2>/dev/null || true`, { timeout: 5000 });
|
||||||
|
console.log('ONLYOFFICE cache cleared for template:', templateId);
|
||||||
|
} catch (cacheErr) {
|
||||||
|
// Non-fatal — cache will expire naturally
|
||||||
|
console.log('Cache clear skipped:', cacheErr.message.substring(0, 100));
|
||||||
|
}
|
||||||
|
|
||||||
// ONLYOFFICE expects a JSON response acknowledging the save
|
// ONLYOFFICE expects a JSON response acknowledging the save
|
||||||
return res.json({
|
return res.json({
|
||||||
error: 0,
|
error: 0,
|
||||||
|
|||||||
@@ -139,7 +139,7 @@
|
|||||||
<!-- Modals -->
|
<!-- Modals -->
|
||||||
<div class="modal-overlay" id="modal-overlay"></div>
|
<div class="modal-overlay" id="modal-overlay"></div>
|
||||||
|
|
||||||
<script src="/static/app.js?v=3"></script>
|
<script src="/static/app.js?v=4"></script>
|
||||||
<script src="/static/carbone.js?v=3"></script>
|
<script src="/static/carbone.js?v=4"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user