fix: force-reload ONLYOFFICE API.js each session + Date.now for truly unique doc key

This commit is contained in:
root
2026-07-16 12:02:45 +00:00
parent 46d2bf4931
commit 8b6b083d3d
5 changed files with 15 additions and 10 deletions

View File

@@ -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:23:15.854Z"
"updatedAt": "2026-07-16T11:52:26.701Z"
}
]

View File

@@ -143,7 +143,8 @@ router.get('/:templateId/config', (req, res) => {
// Get file modification time for cache-busting doc key
const fileStats = fs.statSync(template.path);
const fileMtime = fileStats.mtimeMs;
const docKey = generateDocKey(templateId, fileMtime);
// Use Date.now() as the primary uniqueness driver — guaranteed fresh every time
const docKey = generateDocKey(templateId, Date.now());
const fileName = template.originalName || template.name + '.docx';
// Add file mtime as cache-buster to the document URL so ONLYOFFICE

View File

@@ -324,10 +324,15 @@ async function openOnlyofficeEditor(templateId, templateName) {
`;
showModal(body, '', 'xlarge');
// Load ONLYOFFICE API script dynamically
const scriptUrl = onlyofficeUrl + '/web-apps/apps/api/documents/api.js';
if (!document.getElementById('onlyoffice-api-script')) {
await new Promise((resolve, reject) => {
// Load ONLYOFFICE API script - force fresh load each time
// Remove old script to force ONLYOFFICE to reload API.js from server
const oldScript = document.getElementById('onlyoffice-api-script');
if (oldScript) oldScript.remove();
// Reload with cache-buster so ONLYOFFICE gets fresh API state
const scriptBuster = Date.now();
const scriptUrl = onlyofficeUrl + '/web-apps/apps/api/documents/api.js?cb=' + scriptBuster;
await new Promise((resolve, reject) => {
const script = document.createElement('script');
script.id = 'onlyoffice-api-script';
script.src = scriptUrl;
@@ -335,7 +340,6 @@ async function openOnlyofficeEditor(templateId, templateName) {
script.onerror = () => reject(new Error('Failed to load ONLYOFFICE API from ' + scriptUrl));
document.head.appendChild(script);
});
}
// Initialize the ONLYOFFICE editor
if (typeof DocsAPI === 'undefined' || !DocsAPI.DocEditor) {

View File

@@ -139,7 +139,7 @@
<!-- Modals -->
<div class="modal-overlay" id="modal-overlay"></div>
<script src="/static/app.js?v=5"></script>
<script src="/static/carbone.js?v=5"></script>
<script src="/static/app.js?v=6"></script>
<script src="/static/carbone.js?v=6"></script>
</body>
</html>