Compare commits

..

6 Commits

Author SHA1 Message Date
4ee110c2d5 Merge remote-tracking branch 'remotes/origin/develop' into release/v7.2.0
# Conflicts:
#	web/documentserver-example/nodejs/views/config.ejs
#	web/documentserver-example/ruby/app/models/document_helper.rb
2022-09-15 17:17:24 +03:00
ad1d93dd20 Merge pull request #301 from ONLYOFFICE/bugfix/file-request
added request status check for file
2022-09-15 14:43:19 +03:00
7805f7dc91 added request status check for file 2022-09-01 09:34:30 +03:00
51ec27d67c nodejs: removed trailing comma 2022-08-25 15:47:10 +03:00
9e94716df0 nodejs: reorder config items 2022-08-16 10:15:39 +03:00
988a8339b1 ruby: ERB::Util.url instead URI::encode 2022-08-15 11:10:02 +03:00
5 changed files with 98 additions and 87 deletions

View File

@ -44,6 +44,7 @@ const cfgSignatureAuthorizationHeaderPrefix = configServer.get('token.authorizat
const cfgSignatureSecretExpiresIn = configServer.get('token.expiresIn');
const cfgSignatureSecret = configServer.get('token.secret');
const urllib = require("urllib");
const { emitWarning } = require("process");
const verifyPeerOff = configServer.get('verify_peer_off');
if(verifyPeerOff) {
@ -347,7 +348,7 @@ app.post("/convert", function (req, res) { // define a handler for converting f
response.end();
};
var callback = function (err, data) {
var callback = async function (err, res) {
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
@ -358,7 +359,7 @@ app.post("/convert", function (req, res) { // define a handler for converting f
}
try {
var responseUri = documentService.getResponseUri(data.toString());
var responseUri = documentService.getResponseUri(res.toString());
var result = responseUri.key;
var newFileUri = responseUri.value; // get the callback url
@ -369,10 +370,11 @@ app.post("/convert", function (req, res) { // define a handler for converting f
var correctName = req.docManager.getCorrectName(fileUtility.getFileName(fileName, true) + internalFileExt); // get the file name with a new extension
urllib.request(newFileUri, {method: "GET"},function(err, data) {
fileSystem.writeFileSync(req.docManager.storagePath(correctName), data); // write a file with a new extension, but with the content from the origin file
});
const {status, data} = await urllib.request(newFileUri, {method: "GET"});
if (status != 200) throw new Error("Conversion service returned status: " + status);
fileSystem.writeFileSync(req.docManager.storagePath(correctName), data); // write a file with a new extension, but with the content from the origin file
fileSystem.unlinkSync(req.docManager.storagePath(fileName)); // remove file with the origin extension
var userAddress = req.docManager.curUserHostAddress();
@ -467,7 +469,7 @@ 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("/track", function (req, res) { // define a handler for tracking file changes
app.post("/track", async function (req, res) { // define a handler for tracking file changes
req.docManager = new docManager(req, res);
@ -476,11 +478,15 @@ app.post("/track", function (req, res) { // define a handler for tracking file
var version = 0;
// track file changes
var processTrack = function (response, body, fileName, userAddress) {
var processTrack = async function (response, body, fileName, userAddress) {
// callback file saving process
var callbackProcessSave = function (downloadUri, body, fileName, userAddress, newFileName) {
var callbackProcessSave = async function (downloadUri, body, fileName, userAddress, newFileName) {
try {
const {status, data} = await urllib.request(downloadUri, {method: "GET"});
if (status != 200) throw new Error("Document editing service returned status: " + status);
var storagePath = req.docManager.storagePath(newFileName, userAddress);
var historyPath = req.docManager.historyPath(newFileName, userAddress); // get the path to the history data
@ -497,9 +503,12 @@ app.post("/track", function (req, res) { // define a handler for tracking file
var downloadZip = body.changesurl;
if (downloadZip) {
var path_changes = req.docManager.diffPath(newFileName, userAddress, version); // get the path to the file with document versions differences
urllib.request(downloadZip, {method: "GET"},function(err, data) {
const {status, data} = await urllib.request(downloadZip, {method: "GET"});
if (status == 200) {
fileSystem.writeFileSync(path_changes, data); // write the document version differences to the archive
});
} else {
emitWarning("Document editing service returned status: " + status);
}
}
var changeshistory = body.changeshistory || JSON.stringify(body.history);
@ -514,9 +523,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
var path_prev = path.join(versionPath, "prev" + fileUtility.getFileExtension(fileName)); // get the path to the previous file version
fileSystem.renameSync(req.docManager.storagePath(fileName, userAddress), path_prev); // and write it to the current path
urllib.request(downloadUri, {method: "GET"},function(err, data) {
fileSystem.writeFileSync(storagePath, data);
});
fileSystem.writeFileSync(storagePath, data);
var forcesavePath = req.docManager.forcesavePath(newFileName, userAddress, false); // get the path to the forcesaved file
if (forcesavePath != "") { // if this path is empty
@ -524,6 +531,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
}
} catch (ex) {
console.log(ex);
response.write("{\"error\":1}");
response.end();
return;
@ -534,7 +542,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
}
// file saving process
var processSave = function (downloadUri, body, fileName, userAddress) {
var processSave = async function (downloadUri, body, fileName, userAddress) {
if (!downloadUri) {
response.write("{\"error\":1}");
@ -555,18 +563,18 @@ app.post("/track", function (req, res) { // define a handler for tracking file
var key = documentService.generateRevisionId(downloadUri);
newFileName = req.docManager.getCorrectName(fileUtility.getFileName(fileName, true) + downloadExt, userAddress); // get the correct file name if it already exists
try {
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, function (err, data) {
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, async function (err, data) {
if (err) {
callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
return;
}
try {
var res = documentService.getResponseUri(data);
callbackProcessSave(res.value, body, fileName, userAddress, fileName);
await callbackProcessSave(res.value, body, fileName, userAddress, fileName);
return;
} catch (ex) {
console.log(ex);
callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
return;
}
});
@ -575,12 +583,16 @@ app.post("/track", function (req, res) { // define a handler for tracking file
console.log(ex);
}
}
callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
};
// callback file force saving process
var callbackProcessForceSave = function (downloadUri, body, fileName, userAddress, newFileName = false){
var callbackProcessForceSave = async function (downloadUri, body, fileName, userAddress, newFileName = false){
try {
const {status, data} = await urllib.request(downloadUri, {method: "GET"});
if (status != 200) throw new Error("Document editing service returned status: " + status);
var downloadExt = "." + body.fileType;
/// TODO [Delete in version 7.0 or higher]
@ -608,9 +620,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
}
}
urllib.request(downloadUri, {method: "GET"},function(err, data) {
fileSystem.writeFileSync(forcesavePath, data);
});
fileSystem.writeFileSync(forcesavePath, data);
if (isSubmitForm) {
var uid =body.actions[0].userid
@ -627,7 +637,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
}
// file force saving process
var processForceSave = function (downloadUri, body, fileName, userAddress) {
var processForceSave = async function (downloadUri, body, fileName, userAddress) {
if (!downloadUri) {
response.write("{\"error\":1}");
@ -645,18 +655,18 @@ app.post("/track", function (req, res) { // define a handler for tracking file
if (downloadExt != curExt) {
var key = documentService.generateRevisionId(downloadUri);
try {
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, function (err, data) {
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, async function (err, data) {
if (err) {
callbackProcessForceSave(downloadUri, body, fileName, userAddress, true);
await callbackProcessForceSave(downloadUri, body, fileName, userAddress, true);
return;
}
try {
var res = documentService.getResponseUri(data);
callbackProcessForceSave(res.value, body, fileName, userAddress, false);
await callbackProcessForceSave(res.value, body, fileName, userAddress, false);
return;
} catch (ex) {
console.log(ex);
callbackProcessForceSave(downloadUri, body, fileName, userAddress, true);
await callbackProcessForceSave(downloadUri, body, fileName, userAddress, true);
return;
}
});
@ -665,7 +675,7 @@ app.post("/track", function (req, res) { // define a handler for tracking file
console.log(ex);
}
}
callbackProcessForceSave (downloadUri, body, fileName, userAddress, false);
await callbackProcessForceSave (downloadUri, body, fileName, userAddress, false);
};
if (body.status == 1) { // editing
@ -681,10 +691,10 @@ app.post("/track", function (req, res) { // define a handler for tracking file
}
}
} else if (body.status == 2 || body.status == 3) { // MustSave, Corrupted
processSave(body.url, body, fileName, userAddress); // save file
await processSave(body.url, body, fileName, userAddress); // save file
return;
} else if (body.status == 6 || body.status == 7) { // MustForceSave, CorruptedForceSave
processForceSave(body.url, body, fileName, userAddress); // force save file
await processForceSave(body.url, body, fileName, userAddress); // force save file
return;
}
@ -693,14 +703,14 @@ app.post("/track", function (req, res) { // define a handler for tracking file
};
// read request body
var readbody = function (request, response, fileName, userAddress) {
var readbody = async function (request, response, fileName, userAddress) {
var content = "";
request.on('data', function (data) { // get data from the request
request.on('data', async function (data) { // get data from the request
content += data;
});
request.on('end', function () {
request.on('end', async function () {
var body = JSON.parse(content);
processTrack(response, body, fileName, userAddress); // and track file changes
await processTrack(response, body, fileName, userAddress); // and track file changes
});
};
@ -732,14 +742,14 @@ app.post("/track", function (req, res) { // define a handler for tracking file
res.end();
return;
}
processTrack(res, body, fileName, userAddress);
await processTrack(res, body, fileName, userAddress);
return;
}
if (req.body.hasOwnProperty("status")) { // if the request body has status parameter
processTrack(res, req.body, fileName, userAddress); // track file changes
await processTrack(res, req.body, fileName, userAddress); // track file changes
} else {
readbody(req, res, fileName, userAddress); // otherwise, read request body first
await readbody(req, res, fileName, userAddress); // otherwise, read request body first
}
});

View File

@ -1,54 +1,36 @@
"width": "100%",
"height": "100%",
"type": "<%- editor.type %>",
"documentType": "<%- editor.documentType %>",
"token": "<%- editor.token %>",
"document": {
"title": "<%- file.name %>",
"url": "<%- file.uri %>",
"document": {
"directUrl": "<%- file.directUrl %>",
"fileType": "<%- file.ext %>",
"key": "<%- editor.key %>",
"info": {
"owner": "Me",
"uploaded": "<%- file.created %>",
"favorite": <%- file.favorite %>
},
"key": "<%- editor.key %>",
"permissions": {
"chat": <%- editor.chat %>,
"comment": <%- editor.comment %>,
"copy": <%- editor.copy %>,
"download": <%- editor.download %>,
"edit": <%- editor.isEdit %>,
"print": <%- editor.print %>,
"fillForms": <%- editor.fillForms %>,
"modifyFilter": <%- editor.modifyFilter %>,
"modifyContentControl": <%- editor.modifyContentControl %>,
"modifyFilter": <%- editor.modifyFilter %>,
"print": <%- editor.print %>,
"review": <%- editor.review %>,
"reviewGroups": <%- editor.reviewGroups %>,
"commentGroups": <%- editor.commentGroups %>,
"userInfoGroups": <%- editor.userInfoGroups %>
}
},
"title": "<%- file.name %>",
"url": "<%- file.uri %>"
},
"documentType": "<%- editor.documentType %>",
"editorConfig": {
"actionLink": <%- editor.actionData %>,
"coEditing": <%- JSON.stringify(editor.coEditing) %>,
"mode": "<%- editor.mode %>",
"lang": "<%- editor.lang %>",
"callbackUrl": "<%- editor.callbackUrl %>",
"coEditing": <%- JSON.stringify(editor.coEditing) %>,
"createUrl": <%- JSON.stringify(editor.createUrl) %>,
"templates": <%- JSON.stringify(editor.templates) %>,
"user": {
"group": "<%- editor.userGroup %>",
"id": "<%- editor.userid %>",
"name": "<%- editor.name %>"
},
"embedded": {
"saveUrl": "<%- file.uriUser %>",
"embedUrl": "<%- file.uriUser %>",
"shareUrl": "<%- file.uriUser %>",
"toolbarDocked": "top"
},
"customization": {
"about": true,
"comments": true,
@ -59,6 +41,24 @@
},
"submitForm": <%- editor.submitForm %>
},
"embedded": {
"embedUrl": "<%- file.uriUser %>",
"saveUrl": "<%- file.uriUser %>",
"shareUrl": "<%- file.uriUser %>",
"toolbarDocked": "top"
},
"fileChoiceUrl": "<%- editor.fileChoiceUrl %>",
"plugins": <%- editor.plugins %>
}
"lang": "<%- editor.lang %>",
"mode": "<%- editor.mode %>",
"plugins": <%- editor.plugins %>,
"templates": <%- JSON.stringify(editor.templates) %>,
"user": {
"group": "<%- editor.userGroup %>",
"id": "<%- editor.userid %>",
"name": "<%- editor.name %>"
}
},
"height": "100%",
"token": "<%- editor.token %>",
"type": "<%- editor.type %>",
"width": "100%"

View File

@ -186,20 +186,21 @@
}
};
config = {<%- include("config") %>,
events: {
"onAppReady": onAppReady,
"onDocumentStateChange": onDocumentStateChange,
"onRequestEditRights": onRequestEditRights,
"onError": onError,
"onOutdatedVersion": onOutdatedVersion,
"onMakeActionLink": onMakeActionLink,
"onMetaChange": onMetaChange,
"onRequestInsertImage": onRequestInsertImage,
"onRequestCompareFile": onRequestCompareFile,
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
}
};
config = {
<%- include("config") %>
};
config.events = {
"onAppReady": onAppReady,
"onDocumentStateChange": onDocumentStateChange,
"onRequestEditRights": onRequestEditRights,
"onError": onError,
"onOutdatedVersion": onOutdatedVersion,
"onMakeActionLink": onMakeActionLink,
"onMetaChange": onMetaChange,
"onRequestInsertImage": onRequestInsertImage,
"onRequestCompareFile": onRequestCompareFile,
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
};
if (<%- JSON.stringify(editor.userid) %> != null) {
config.events.onRequestHistory = onRequestHistory;

View File

@ -230,7 +230,7 @@ class DocumentHelper
# get file url
def get_file_uri(file_name, for_document_server)
uri = get_server_url(for_document_server) + '/' + Rails.configuration.storagePath + '/' + cur_user_host_address(nil) + '/' + URI::encode(file_name)
uri = get_server_url(for_document_server) + '/' + Rails.configuration.storagePath + '/' + cur_user_host_address(nil) + '/' + ERB::Util.url_encode(file_name)
return uri
end
@ -239,7 +239,7 @@ class DocumentHelper
def get_historypath_uri(file_name,version,file,is_serverUrl=true)
# for redirection to my link
user_host = is_serverUrl ? '&userAddress=' + cur_user_host_address(nil) : ""
uri = get_server_url(is_serverUrl) + '/downloadhistory/?fileName=' + URI::encode(file_name) + '&ver='+ version.to_s + '&file='+ URI::encode(file) + user_host
uri = get_server_url(is_serverUrl) + '/downloadhistory/?fileName=' + ERB::Util.url_encode(file_name) + '&ver='+ version.to_s + '&file='+ ERB::Util.url_encode(file) + user_host
return uri
end
@ -255,7 +255,7 @@ class DocumentHelper
# get callback url
def get_callback(file_name)
get_server_url(true) + '/track?fileName=' + URI::encode(file_name) + '&userAddress=' + cur_user_host_address(nil)
get_server_url(true) + '/track?fileName=' + ERB::Util.url_encode(file_name) + '&userAddress=' + cur_user_host_address(nil)
end
@ -270,7 +270,7 @@ class DocumentHelper
def get_download_url(file_name, is_serverUrl=true)
user_host = is_serverUrl ? '&userAddress=' + cur_user_host_address(nil) : ""
get_server_url(is_serverUrl) + '/download?fileName=' + URI::encode(file_name) + user_host
get_server_url(is_serverUrl) + '/download?fileName=' + ERB::Util.url_encode(file_name) + user_host
end

View File

@ -128,7 +128,7 @@
<%
docs.each { |d|
isFillFormDoc = DocumentHelper.fill_forms_exts.include?(File.extname(d).downcase)
editUrl = "editor?fileName=#{URI::encode(d)}"
editUrl = "editor?fileName=#{ERB::Util.url_encode(d)}"
docType = FileUtility.get_file_type(d)
canEdit = DocumentHelper.edited_exts.include?(File.extname(d).downcase) %>
<tr class="tableRow" title="<%= d %> [<%= DocumentHelper.get_file_version(DocumentHelper.history_dir(DocumentHelper.storage_path(d, nil))) %>]">
@ -221,7 +221,7 @@
</a>
</td>
<td class="contentCells contentCells-shift contentCells-icon downloadContentCellShift">
<a href="<%= "download?fileName=#{URI::encode(d)}" %>">
<a href="<%= "download?fileName=#{ERB::Util.url_encode(d)}" %>">
<img class="icon-download" src="assets/download.svg" alt="Download" title="Download" />
</a>
</td>