fix: force-reload ONLYOFFICE API.js each session + Date.now for truly unique doc key
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:23:15.854Z"
|
"updatedAt": "2026-07-16T11:52:26.701Z"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -143,7 +143,8 @@ router.get('/:templateId/config', (req, res) => {
|
|||||||
// Get file modification time for cache-busting doc key
|
// Get file modification time for cache-busting doc key
|
||||||
const fileStats = fs.statSync(template.path);
|
const fileStats = fs.statSync(template.path);
|
||||||
const fileMtime = fileStats.mtimeMs;
|
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';
|
const fileName = template.originalName || template.name + '.docx';
|
||||||
|
|
||||||
// Add file mtime as cache-buster to the document URL so ONLYOFFICE
|
// Add file mtime as cache-buster to the document URL so ONLYOFFICE
|
||||||
|
|||||||
@@ -324,10 +324,15 @@ async function openOnlyofficeEditor(templateId, templateName) {
|
|||||||
`;
|
`;
|
||||||
showModal(body, '', 'xlarge');
|
showModal(body, '', 'xlarge');
|
||||||
|
|
||||||
// Load ONLYOFFICE API script dynamically
|
// Load ONLYOFFICE API script - force fresh load each time
|
||||||
const scriptUrl = onlyofficeUrl + '/web-apps/apps/api/documents/api.js';
|
// Remove old script to force ONLYOFFICE to reload API.js from server
|
||||||
if (!document.getElementById('onlyoffice-api-script')) {
|
const oldScript = document.getElementById('onlyoffice-api-script');
|
||||||
await new Promise((resolve, reject) => {
|
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');
|
const script = document.createElement('script');
|
||||||
script.id = 'onlyoffice-api-script';
|
script.id = 'onlyoffice-api-script';
|
||||||
script.src = scriptUrl;
|
script.src = scriptUrl;
|
||||||
@@ -335,8 +340,7 @@ async function openOnlyofficeEditor(templateId, templateName) {
|
|||||||
script.onerror = () => reject(new Error('Failed to load ONLYOFFICE API from ' + scriptUrl));
|
script.onerror = () => reject(new Error('Failed to load ONLYOFFICE API from ' + scriptUrl));
|
||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the ONLYOFFICE editor
|
// Initialize the ONLYOFFICE editor
|
||||||
if (typeof DocsAPI === 'undefined' || !DocsAPI.DocEditor) {
|
if (typeof DocsAPI === 'undefined' || !DocsAPI.DocEditor) {
|
||||||
throw new Error('ONLYOFFICE API not loaded. Check that the server is running at ' + onlyofficeUrl);
|
throw new Error('ONLYOFFICE API not loaded. Check that the server is running at ' + onlyofficeUrl);
|
||||||
|
|||||||
@@ -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=5"></script>
|
<script src="/static/app.js?v=6"></script>
|
||||||
<script src="/static/carbone.js?v=5"></script>
|
<script src="/static/carbone.js?v=6"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user