From 111dc14f2b53306f46d3ffa4467f559dfdafcc24 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Fri, 3 Jun 2022 12:24:26 +0300 Subject: [PATCH 001/218] nodejs: referenceData --- CHANGELOG.md | 2 + web/documentserver-example/nodejs/app.js | 78 ++++++++++++++++++- .../nodejs/views/config.ejs | 1 + .../nodejs/views/editor.ejs | 15 ++++ 4 files changed, 95 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f63fd13e1..541fcebad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Change Log +- nodejs: referenceData + ## 1.4.0 - nodejs: option to send directUrl - opening file on client by directUrl diff --git a/web/documentserver-example/nodejs/app.js b/web/documentserver-example/nodejs/app.js index 012591139..0d86570dc 100755 --- a/web/documentserver-example/nodejs/app.js +++ b/web/documentserver-example/nodejs/app.js @@ -29,6 +29,7 @@ const config = require('config'); const configServer = config.get('server'); const storageFolder = configServer.get("storageFolder"); const mime = require("mime"); +const urlModule = require("url"); const docManager = require("./helpers/docManager"); const documentService = require("./helpers/documentService"); const fileUtility = require("./helpers/fileUtility"); @@ -469,6 +470,75 @@ app.get("/csv", function (req, res) { // define a handler for downloading csv f filestream.pipe(res); // send file information to the response by streams }) +app.post("/reference", function (req, res) { //define a handler for renaming file + + req.docManager = new docManager(req, res); + + var result = function(data) { + res.writeHead(200, {"Content-Type": "application/json" }); + res.write(JSON.stringify(data)); + res.end(); + }; + + var referenceData = req.body.referenceData; + if (!!referenceData) { + var portalName = referenceData.portalName; + + if (portalName != req.docManager.getServerUrl()) { + result({ "error": "You do not have access to this site" }); + return; + } + + var fileId = JSON.parse(referenceData.fileId); + var userAddress = fileId.userAddress; + if (userAddress != req.docManager.curUserHostAddress()) { + result({ "error": "You do not have access to this file" }); + return; + } + + var fileName = fileId.fileName; + if (!req.docManager.existsSync(req.docManager.storagePath(fileName, userAddress))) { + result({ "error": "File is not exist" }); + return; + } + } else if (!!req.body.link) { + if (req.body.link.indexOf(req.docManager.curUserHostAddress()) != -1) { + result({ "error": "You do not have access to this site" }); + return; + } + + var urlObj = urlModule.parse(req.body.link, true); + var fileName = urlObj.query.fileName; + if (!req.docManager.existsSync(req.docManager.storagePath(fileName, userAddress))) { + result({ "error": "File is not exist" }); + return; + } + } else if (!!req.body.path) { + var fileName = fileUtility.getFileName(req.body.path); + if (!req.docManager.existsSync(req.docManager.storagePath(fileName, userAddress))) { + result({ "error": "File is not exist" }); + return; + } + } + + if (!fileName) { + result({ "error": "File is not found" }); + return; + } + + result({ + key: req.docManager.getKey(fileName), + url: req.docManager.getDownloadUrl(fileName, true), + directUrl: req.docManager.getDownloadUrl(fileName), + referenceData: { + fileId: JSON.stringify({ fileName: fileName, userAddress: req.docManager.curUserHostAddress()}), + portalName: req.docManager.getServerUrl() + }, + link: req.docManager.getServerUrl() + "/editor?fileName=" + encodeURIComponent(fileName), + path: fileName, + }); +}); + app.post("/track", async function (req, res) { // define a handler for tracking file changes req.docManager = new docManager(req, res); @@ -779,6 +849,11 @@ app.get("/editor", function (req, res) { // define a handler for editing docume } } + var referenceData = { + fileId: JSON.stringify({ fileName: fileName, userAddress: req.docManager.curUserHostAddress()}), + portalName: req.docManager.getServerUrl() + }; + var templatesImageUrl = req.docManager.getTemplateImageUrl(fileUtility.getFileType(fileName)); var createUrl = req.docManager.getCreateUrl(fileUtility.getFileType(fileName), userid, type, lang); var templates = [ @@ -945,7 +1020,8 @@ app.get("/editor", function (req, res) { // define a handler for editing docume fileChoiceUrl: fileChoiceUrl, submitForm: submitForm, plugins: JSON.stringify(plugins), - actionData: actionData + actionData: actionData, + referenceData: userid != "uid-0" ? referenceData : null }, history: history, historyData: historyData, diff --git a/web/documentserver-example/nodejs/views/config.ejs b/web/documentserver-example/nodejs/views/config.ejs index 595abba69..a794fea2a 100755 --- a/web/documentserver-example/nodejs/views/config.ejs +++ b/web/documentserver-example/nodejs/views/config.ejs @@ -22,6 +22,7 @@ "commentGroups": <%- editor.commentGroups %>, "userInfoGroups": <%- editor.userInfoGroups %> }, + "referenceData": <%- JSON.stringify(editor.referenceData) %>, "title": "<%- file.name %>", "url": "<%- file.uri %>" }, diff --git a/web/documentserver-example/nodejs/views/editor.ejs b/web/documentserver-example/nodejs/views/editor.ejs index 0ca37bc90..3640cdc40 100644 --- a/web/documentserver-example/nodejs/views/editor.ejs +++ b/web/documentserver-example/nodejs/views/editor.ejs @@ -151,6 +151,20 @@ innerAlert("onRequestSendNotify: " + data); }; + var onRequestReferenceData = function(event) { // user refresh external data source + innerAlert("onRequestReferenceData"); + innerAlert(event.data); + + let xhr = new XMLHttpRequest(); + xhr.open("POST", "reference"); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.send(JSON.stringify(event.data)); + xhr.onload = function () { + innerAlert(xhr.responseText); + docEditor.setReferenceData(JSON.parse(xhr.responseText)); + } + }; + var onRequestSaveAs = function (event) { // the user is trying to save file by clicking Save Copy as... button var title = event.data.title; var url = event.data.url; @@ -209,6 +223,7 @@ config.events.onRequestRename = onRequestRename; config.events.onRequestUsers = onRequestUsers; config.events.onRequestSendNotify = onRequestSendNotify; + config.events.onRequestReferenceData = onRequestReferenceData; } if (config.editorConfig.createUrl) { From f27afe15355a2541740e72ad68f840ed2c14222e Mon Sep 17 00:00:00 2001 From: Vladimir Kurguzov Date: Tue, 25 Oct 2022 19:44:39 +0300 Subject: [PATCH 002/218] java-spring: option to send directUrl --- CHANGELOG.md | 3 ++ .../main/resources/static/css/stylesheet.css | 2 +- .../main/resources/static/scripts/jscript.js | 30 +++++++++++++++++-- .../src/main/resources/templates/index.html | 10 ++++++- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 541fcebad..6973f403c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Change Log +- java spring: option to send directUrl - nodejs: referenceData ## 1.4.0 @@ -14,6 +15,7 @@ - changed jwt implementation in csharp, csharp-mvc, php, ruby ## 1.2.0 + - ruby v3.0 - set filetype in setHistoryData - read filetype from input request @@ -29,6 +31,7 @@ - ignore certificate ## 1.1.0 + - creating docxf - opening docxf, oform diff --git a/web/documentserver-example/java-spring/src/main/resources/static/css/stylesheet.css b/web/documentserver-example/java-spring/src/main/resources/static/css/stylesheet.css index 5b6f03e17..485cfd41f 100755 --- a/web/documentserver-example/java-spring/src/main/resources/static/css/stylesheet.css +++ b/web/documentserver-example/java-spring/src/main/resources/static/css/stylesheet.css @@ -167,7 +167,7 @@ label .checkbox { background-image: url("img/file_docxf.svg"); } -.create-sample { +.side-option { color: #666666; line-height: 24px; } diff --git a/web/documentserver-example/java-spring/src/main/resources/static/scripts/jscript.js b/web/documentserver-example/java-spring/src/main/resources/static/scripts/jscript.js index 5393d3298..67eae87b0 100755 --- a/web/documentserver-example/java-spring/src/main/resources/static/scripts/jscript.js +++ b/web/documentserver-example/java-spring/src/main/resources/static/scripts/jscript.js @@ -16,11 +16,24 @@ * */ +var directUrl; + if (typeof jQuery !== "undefined") { jq = jQuery.noConflict(); + directUrl = getUrlVars()["directUrl"] == "true"; + mustReload = false; + if (directUrl) + jq("#directUrl").prop("checked", directUrl); + else + directUrl = jq("#directUrl").prop("checked"); + + jq("#directUrl").change(function() { + window.location = "?directUrl=" + jq(this).prop("checked"); + }); + jq(function () { jq("#fileupload").fileupload({ dataType: "json", @@ -228,7 +241,7 @@ if (typeof jQuery !== "undefined") { jq(document).on("click", "#beginEdit:not(.disable)", function () { var fileId = encodeURIComponent(jq("#hiddenFileName").val()); - var url = UrlEditor + "?action=edit&fileName=" + fileId; + var url = UrlEditor + "?action=edit&fileName=" + fileId + "&directUrl=" + directUrl; window.open(url, "_blank"); jq("#hiddenFileName").val(""); jq.unblockUI(); @@ -236,7 +249,7 @@ if (typeof jQuery !== "undefined") { jq(document).on("click", "#beginView:not(.disable)", function () { var fileId = encodeURIComponent(jq("#hiddenFileName").val()); - var url = UrlEditor + "?action=view&fileName=" + fileId; + var url = UrlEditor + "?action=view&fileName=" + fileId + "&directUrl=" + directUrl; window.open(url, "_blank"); jq("#hiddenFileName").val(""); jq.unblockUI(); @@ -244,7 +257,7 @@ if (typeof jQuery !== "undefined") { jq(document).on("click", "#beginEmbedded:not(.disable)", function () { var fileId = encodeURIComponent(jq("#hiddenFileName").val()); - var url = UrlEditor + "?type=embedded&action=embedded&fileName=" + fileId; + var url = UrlEditor + "?type=embedded&action=embedded&fileName=" + fileId + "&directUrl=" + directUrl; jq("#mainProgress").addClass("embedded"); jq("#beginEmbedded").addClass("disable"); @@ -300,6 +313,17 @@ if (typeof jQuery !== "undefined") { } }; + function getUrlVars() { + var vars = [], hash; + var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); + for (var i = 0; i < hashes.length; i++) { + hash = hashes[i].split('='); + vars.push(hash[0]); + vars[hash[0]] = hash[1]; + } + return vars; + }; + jq("#portal-info")[0].innerHTML += jq("#portal-info")[0].attributes.tooltip.value; var fileList = jq("tr.tableRow"); diff --git a/web/documentserver-example/java-spring/src/main/resources/templates/index.html b/web/documentserver-example/java-spring/src/main/resources/templates/index.html index 17b988d72..505d1b9a7 100755 --- a/web/documentserver-example/java-spring/src/main/resources/templates/index.html +++ b/web/documentserver-example/java-spring/src/main/resources/templates/index.html @@ -59,7 +59,7 @@ Form template -