diff --git a/web/documentserver-example/nodejs/app.js b/web/documentserver-example/nodejs/app.js index fc9288d9..b1fdfb4c 100644 --- a/web/documentserver-example/nodejs/app.js +++ b/web/documentserver-example/nodejs/app.js @@ -346,6 +346,7 @@ app.post("/convert", function (req, res) { // define a handler for converting f }; var callback = function (err, data) { + if (err) { // if an error occurs if (err.name === "ConnectionTimeoutError" || err.name === "ResponseTimeoutError") { // check what type of error it is writeResult(fileName, 0, null); // despite the timeout errors, write the file to the result object @@ -969,6 +970,39 @@ app.get("/editor", function (req, res) { // define a handler for editing docume } }); +app.post("/rename", function (req, res) { //define a handler for renaming file + + var newfilename = req.body.newfilename; + var dockey = req.body.dockey; + var urlModule = require("url"); + + var params = { // create a parameter object with command method and the document key value in it + c: "meta", + key: dockey, + meta: { + title: newfilename + } + }; + + var uri = siteUrl + configServer.get('commandUrl'); // get the absolute command url + var headers = { // create a headers object + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }; + if (cfgSignatureEnable && cfgSignatureUseForRequest) { + headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params); + params.token = documentService.getToken(params); + } + + //parse url to allow request by relative url after https://github.com/node-modules/urllib/pull/321/commits/514de1924bf17a38a6c2db2a22a6bc3494c0a959 + urllib.request(urlModule.parse(uri), + { + method: "POST", + headers: headers, + data: params + }); +}); + wopiApp.registerRoutes(app); // "Not found" error with 404 status diff --git a/web/documentserver-example/nodejs/views/editor.ejs b/web/documentserver-example/nodejs/views/editor.ejs index e4ba87c7..c12e5ac8 100644 --- a/web/documentserver-example/nodejs/views/editor.ejs +++ b/web/documentserver-example/nodejs/views/editor.ejs @@ -56,10 +56,17 @@ }; var onMetaChange = function (event) { // the meta information of the document is changed via the meta command + if(event.data.title) { + var title = event.data.title; + document.title = title; + console.log(event.data); + } + else { var favorite = !!event.data.favorite; var title = document.title.replace(/^\☆/g, ""); document.title = (favorite ? "☆" : "") + title; docEditor.setFavorite(favorite); // change the Favorite icon state + } }; var onRequestEditRights = function () { // the user is trying to switch the document from the viewing into the editing mode @@ -163,6 +170,22 @@ } } + var onRequestRename = function(event) { // the user is trying to rename file by clicking Rename... button + var newfilename = event.data; + + var data = { + newfilename: newfilename, + dockey: config.document.key, + }; + let xhr = new XMLHttpRequest(); + xhr.open("POST", "rename"); + xhr.setRequestHeader( 'Content-Type', 'application/json'); + xhr.send(JSON.stringify(data)); + xhr.onload = function () { + innerAlert(xhr.responseText); + } + }; + var config = {<%- include("config") %>, events: { "onAppReady": onAppReady, @@ -178,6 +201,7 @@ "onRequestInsertImage": onRequestInsertImage, "onRequestCompareFile": onRequestCompareFile, "onRequestMailMergeRecipients": onRequestMailMergeRecipients, + "onRequestRename": onRequestRename } };