mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-02-10 18:05:10 +08:00
Merge pull request #534 from ONLYOFFICE/feature/nodejs-forced-conversion
Feature/nodejs forced conversion
This commit is contained in:
@ -330,9 +330,8 @@ app.post('/convert', (req, res) => { // define a handler for converting files
|
||||
const lang = req.body.lang ? req.body.lang : null;
|
||||
const fileUri = req.DocManager.getDownloadUrl(fileName, true);
|
||||
const fileExt = fileUtility.getFileExtension(fileName, true);
|
||||
const internalFileExt = 'ooxml';
|
||||
let convExt = req.body.fileExt ? req.body.fileExt : internalFileExt;
|
||||
if (req.body.forceConv) convExt = req.body.forceConv;
|
||||
const conversionExtension = req.body.fileExt ? req.body.fileExt : 'ooxml';
|
||||
const { keepOriginal } = req.body;
|
||||
const response = res;
|
||||
|
||||
const writeResult = function writeResult(filename, step, error) {
|
||||
@ -387,14 +386,14 @@ app.post('/convert', (req, res) => { // define a handler for converting files
|
||||
return;
|
||||
}
|
||||
// remove file with the origin extension
|
||||
if (!('fileExt' in req.body)) fileSystem.unlinkSync(req.DocManager.storagePath(fileName));
|
||||
if (!keepOriginal) fileSystem.unlinkSync(req.DocManager.storagePath(fileName));
|
||||
|
||||
const userAddress = req.DocManager.curUserHostAddress();
|
||||
const historyPath = req.DocManager.historyPath(fileName, userAddress, true);
|
||||
// get the history path to the file with a new extension
|
||||
const correctHistoryPath = req.DocManager.historyPath(correctName, userAddress, true);
|
||||
|
||||
if (!('fileExt' in req.body)) {
|
||||
if (!keepOriginal) {
|
||||
fileSystem.renameSync(historyPath, correctHistoryPath); // change the previous history path
|
||||
|
||||
fileSystem.renameSync(
|
||||
@ -423,7 +422,7 @@ app.post('/convert', (req, res) => { // define a handler for converting files
|
||||
|
||||
key = documentService.generateRevisionId(key); // get document key
|
||||
// get the url to the converted file
|
||||
documentService.getConvertedUri(fileUri, fileExt, convExt, key, true, callback, filePass, lang);
|
||||
documentService.getConvertedUri(fileUri, fileExt, conversionExtension, key, true, callback, filePass, lang);
|
||||
} else {
|
||||
// if the file with such an extension can't be converted, write the origin file to the result object
|
||||
writeResult(fileName, null, null);
|
||||
|
||||
@ -121,7 +121,7 @@ if (typeof jQuery != "undefined") {
|
||||
});
|
||||
|
||||
var timer = null;
|
||||
var checkConvert = function (filePass, forceConvert) {
|
||||
var checkConvert = function (filePass, fileType) {
|
||||
filePass = filePass ? filePass : null;
|
||||
if (timer != null) {
|
||||
clearTimeout(timer);
|
||||
@ -143,16 +143,13 @@ if (typeof jQuery != "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
var convData = {filename: fileName, filePass: filePass, lang: language};
|
||||
if (forceConvert) convData.forceConv = forceConvert;
|
||||
|
||||
timer = setTimeout(function () {
|
||||
jq.ajaxSetup({ cache: false });
|
||||
jq.ajax({
|
||||
async: true,
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
data: convData,
|
||||
data: {filename: fileName, filePass: filePass, lang: language, fileExt: fileType},
|
||||
url: UrlConverter,
|
||||
complete: function (data) {
|
||||
var responseText = data.responseText;
|
||||
@ -173,7 +170,7 @@ if (typeof jQuery != "undefined") {
|
||||
return;
|
||||
} else {
|
||||
if (response.error.includes("-9")){
|
||||
jq("#xmlError").removeClass("invisible");
|
||||
jq("#select-file-type").removeClass("invisible");
|
||||
jq("#step2").removeClass("current");
|
||||
jq("#hiddenFileName").attr("placeholder",filePass);
|
||||
return;
|
||||
@ -189,7 +186,7 @@ if (typeof jQuery != "undefined") {
|
||||
jq("#hiddenFileName").val(response.filename);
|
||||
|
||||
if (typeof response.step != "undefined" && response.step < 100) {
|
||||
checkConvert(filePass, forceConvert);
|
||||
checkConvert(filePass, fileType);
|
||||
} else {
|
||||
jq("#step2").addClass("done").removeClass("current");
|
||||
loadScripts();
|
||||
@ -232,11 +229,11 @@ if (typeof jQuery != "undefined") {
|
||||
}
|
||||
};
|
||||
|
||||
jq(document).on("click", "#forceConvert:not(.disable)", function () {
|
||||
jq(document).on("click", ".file-type:not(.disable)", function () {
|
||||
const currentElement = jq(this);
|
||||
var fileType = currentElement.attr("data");
|
||||
var filePass = jq("#hiddenFileName").attr("placeholder");
|
||||
jq("div[id='forceConvert']").addClass("disable, pale");
|
||||
jq(".file-type").addClass(["disable", "pale"]);
|
||||
currentElement.removeClass("pale");
|
||||
checkConvert(filePass, fileType);
|
||||
});
|
||||
@ -423,7 +420,7 @@ if (typeof jQuery != "undefined") {
|
||||
async: true,
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
data: {filename: fileName, filePass: filePass, lang: language, fileExt: fileExt},
|
||||
data: {filename: fileName, filePass: filePass, lang: language, fileExt: fileExt, keepOriginal: true},
|
||||
url: UrlConverter,
|
||||
complete: function (data) {
|
||||
try {
|
||||
|
||||
@ -551,8 +551,8 @@
|
||||
margin-bottom: 0;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
.button.forceConvert:hover,
|
||||
.button.forceConvert {
|
||||
.button.file-type:hover,
|
||||
.button.file-type {
|
||||
height: 28px;
|
||||
width: 100px;
|
||||
margin-bottom: 10px !important;
|
||||
|
||||
@ -274,30 +274,30 @@ label .checkbox {
|
||||
opacity: 100%;
|
||||
}
|
||||
|
||||
.button.forceConvert {
|
||||
.button.file-type {
|
||||
font-size: 11px;
|
||||
color: #FFFFFF;
|
||||
padding: 8px 8px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.button.forceConvert.disable {
|
||||
.button.file-type.disable {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.button.forceConvert.pale {
|
||||
.button.file-type.pale {
|
||||
opacity: 30%;
|
||||
}
|
||||
|
||||
.button.forceConvert.document {
|
||||
.button.file-type.document {
|
||||
background: #446995;
|
||||
}
|
||||
|
||||
.button.forceConvert.spreadsheet {
|
||||
.button.file-type.spreadsheet {
|
||||
background: #40865C;
|
||||
}
|
||||
|
||||
.button.forceConvert.presentation {
|
||||
.button.file-type.presentation {
|
||||
background: #AA5252;
|
||||
}
|
||||
|
||||
|
||||
@ -274,13 +274,13 @@
|
||||
<div class="describeUpload">After these steps are completed, you can work with your document.</div>
|
||||
<span id="step1" class="step">1. Loading the file.</span>
|
||||
<span class="step-descr">The loading speed depends on file size and additional elements it contains.</span>
|
||||
<div id="xmlError" class="invisible">
|
||||
<div id="select-file-type" class="invisible">
|
||||
<br />
|
||||
<span class="step">Please select the current document type</span>
|
||||
<div class="buttonsMobile indent">
|
||||
<div id="forceConvert" class="button forceConvert document" data="docx">Document</div>
|
||||
<div id="forceConvert" class="button forceConvert spreadsheet" data="xlsx">Spreadsheet</div>
|
||||
<div id="forceConvert" class="button forceConvert presentation" data="pptx">Presentation</div>
|
||||
<div class="button file-type document" data="docx">Document</div>
|
||||
<div class="button file-type spreadsheet" data="xlsx">Spreadsheet</div>
|
||||
<div class="button file-type presentation" data="pptx">Presentation</div>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
|
||||
Reference in New Issue
Block a user