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",
|
||||
"path": "/root/workspace/cv-app/renderer/carbone-templates/433a0593-d3cf-414e-8763-ab5f87cbc75c.docx",
|
||||
"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 fileName = template.originalName || template.name + '.docx';
|
||||
|
||||
// Add cache-busting timestamp to the document URL so ONLYOFFICE
|
||||
// always fetches the latest version from our backend
|
||||
const cacheBuster = Date.now();
|
||||
const documentUrl = `${BACKEND_PUBLIC_URL}/api/onlyoffice/${templateId}/download?cb=${cacheBuster}`;
|
||||
// Add file mtime as cache-buster to the document URL so ONLYOFFICE
|
||||
// always fetches the latest version from our backend.
|
||||
// The mtime changes every time the file is saved, so the URL is
|
||||
// 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 config = {
|
||||
@@ -316,6 +317,17 @@ router.post('/:templateId/callback', async (req, res) => {
|
||||
|
||||
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
|
||||
return res.json({
|
||||
error: 0,
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
<!-- Modals -->
|
||||
<div class="modal-overlay" id="modal-overlay"></div>
|
||||
|
||||
<script src="/static/app.js?v=3"></script>
|
||||
<script src="/static/carbone.js?v=3"></script>
|
||||
<script src="/static/app.js?v=4"></script>
|
||||
<script src="/static/carbone.js?v=4"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user