mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-02-10 18:05:10 +08:00
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:
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user