Merge pull request 'feature/refresh-file' from feature/refresh-file into develop

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/document-server-integration/pulls/20
This commit is contained in:
Sergey Linnik
2024-12-05 11:40:54 +00:00
3 changed files with 62 additions and 0 deletions

View File

@ -1,5 +1,6 @@
# Change Log
- nodejs: refresh config
- nodejs: support vsdx in visio editor
- nodejs: support pages, numbers, key formats
- golang: new integration example

View File

@ -1012,6 +1012,54 @@ app.post('/track', async (req, res) => { // define a handler for tracking file c
}
});
app.get('/config', async (req, res) => {
try {
req.DocManager = new DocManager(req, res);
const fileName = fileUtility.getFileName(req.query.fileName);
const userAddress = req.DocManager.curUserHostAddress();
// if the file with a given name doesn't exist
if (!req.DocManager.existsSync(req.DocManager.storagePath(fileName, userAddress))) {
throw new Error(`File not found: ${fileName}`); // display error message
}
// file config data
const data = {
document: {
key: req.DocManager.getKey(fileName),
title: fileName,
url: req.DocManager.getDownloadUrl(fileName, true),
permissions: JSON.parse(req.query.permissions || '{}'),
referenceData: {
fileKey: JSON.stringify({ fileName, userAddress: req.DocManager.curUserHostAddress() }),
instanceId: req.DocManager.getInstanceId(),
},
},
editorConfig: {
callbackUrl: req.DocManager.getCallback(fileName),
mode: 'edit',
},
};
if (req.query.directUrl === 'true') {
data.document.directUrl = req.DocManager.getDownloadUrl(fileName);
}
if (cfgSignatureEnable) {
// sign token with given data using signature secret
data.token = jwt.sign(data, cfgSignatureSecret, { expiresIn: cfgSignatureSecretExpiresIn });
}
res.setHeader('Content-Type', 'application/json');
res.write(JSON.stringify(data));
} catch (ex) {
console.log(ex);
res.status(500);
res.write('error');
}
res.end();
});
app.get('/editor', (req, res) => { // define a handler for editing document
try {
req.DocManager = new DocManager(req, res);

View File

@ -353,6 +353,18 @@
}
};
var onRequestRefreshFile = function(event) {
let xhr = new XMLHttpRequest();
xhr.open("GET", "config?fileName=" + encodeURIComponent(config.document.title) +
"&directUrl=" + !!config.document.directUrl +
"&permissions=" + encodeURIComponent(JSON.stringify(config.document.permissions)));
xhr.send();
xhr.onload = function () {
innerAlert(xhr.responseText);
docEditor.refreshFile(JSON.parse(xhr.responseText));
};
};
var onDocumentReady = function(){
fixSize();
};
@ -372,6 +384,7 @@
"onRequestSelectDocument": onRequestSelectDocument,
"onRequestSelectSpreadsheet": onRequestSelectSpreadsheet,
"onRequestOpen": onRequestOpen,
"onRequestRefreshFile": onRequestRefreshFile,
};
if (<%- JSON.stringify(editor.userid) %> != null) {