Skip to content

Commit

Permalink
Merge branch hotfix/v8.1.1 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
papacarlo committed Jul 15, 2024
2 parents 9ecd899 + 61b5e5d commit c990926
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Common/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"utils": {
"utils_common_fontdir": "null",
"utils_fonts_search_patterns": "*.ttf;*.ttc;*.otf",
"limits_image_types_upload": "jpg;jpeg;jpe;png;gif;bmp;svg"
"limits_image_types_upload": "jpg;jpeg;jpe;png;gif;bmp;svg;tiff;tif"
},
"sql": {
"type": "postgres",
Expand Down
4 changes: 4 additions & 0 deletions Common/sources/storage-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ async function getSignedUrl(ctx, storageCfg, baseUrl, strPath, urlType, optFilen
} else if (ctx.wopiSrc) {
wopiSrcCached = ctx.wopiSrc;
url += `&${constants.SHARD_KEY_WOPI_NAME}=${encodeURIComponent(ctx.wopiSrc)}`;
} else if (process.env.DEFAULT_SHARD_KEY) {
//Set DEFAULT_SHARD_KEY from environment as shardkey in case of integrator did not pass this param
url += `&${constants.SHARD_KEY_API_NAME}=${encodeURIComponent(process.env.DEFAULT_SHARD_KEY)}`;
} else if (shardKeyCached) {
//Add stubs for shardkey params until integrators pass these parameters to all requests
url += `&${constants.SHARD_KEY_API_NAME}=${encodeURIComponent(shardKeyCached)}`;
} else if (wopiSrcCached) {
url += `&${constants.SHARD_KEY_WOPI_NAME}=${encodeURIComponent(wopiSrcCached)}`;
Expand Down
16 changes: 13 additions & 3 deletions DocService/sources/DocsCoServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,8 @@ function* setForceSave(ctx, docId, forceSave, cmd, success, url) {
convertInfo.setResponseKey(undefined);
convertInfo.setFormData(undefined);
if (convertInfo.getForceSave()) {
convertInfo.getForceSave().setType(undefined);
//type must be saved to distinguish c_oAscForceSaveTypes.Form
//convertInfo.getForceSave().setType(undefined);
convertInfo.getForceSave().setAuthorUserId(undefined);
convertInfo.getForceSave().setAuthorUserIndex(undefined);
}
Expand Down Expand Up @@ -884,7 +885,13 @@ async function applyForceSaveCache(ctx, docId, forceSave, type, opt_userConnecti
let forceSaveCache = await checkForceSaveCache(ctx, forceSave.convertInfo);
if (forceSaveCache.hasCache || forceSave.ended) {
if (commonDefines.c_oAscForceSaveTypes.Form === type || commonDefines.c_oAscForceSaveTypes.Internal === type || !forceSave.ended) {
if (forceSaveCache.hasValidCache) {
//c_oAscForceSaveTypes.Form has uniqueue options {'documentLayout': {'isPrint': true}}; dont use it for other types
let forceSaveCached = forceSaveCache.cmd?.getForceSave()?.getType();
let cacheHasSameOptions = (commonDefines.c_oAscForceSaveTypes.Form === type &&
commonDefines.c_oAscForceSaveTypes.Form === forceSaveCached) ||
(commonDefines.c_oAscForceSaveTypes.Form !== type &&
commonDefines.c_oAscForceSaveTypes.Form !== forceSaveCached)
if (forceSaveCache.hasValidCache && cacheHasSameOptions) {
let cmd = forceSaveCache.cmd;
cmd.setUserConnectionDocId(opt_userConnectionDocId);
cmd.setUserConnectionId(opt_userConnectionId);
Expand All @@ -899,7 +906,7 @@ async function applyForceSaveCache(ctx, docId, forceSave, type, opt_userConnecti
await canvasService.commandSfcCallback(ctx, cmd, true, false);
res.ok = true;
} else {
await editorData.checkAndSetForceSave(ctx, docId, forceSave.getTime(), forceSave.getIndex(), false, false, null);
await editorData.checkAndSetForceSave(ctx, docId, forceSave.time, forceSave.index, false, false, null);
res.startedForceSave = await editorData.checkAndStartForceSave(ctx, docId);
res.ok = !!res.startedForceSave;
}
Expand Down Expand Up @@ -4316,6 +4323,9 @@ exports.commandFromServer = function (req, res) {
output.error = validateInputParams(ctx, authRes, params);
if (output.error === commonDefines.c_oAscServerCommandErrors.NoError) {
ctx.logger.debug('commandFromServer: c = %s', params.c);
if (params.key && !req.query[constants.SHARD_KEY_API_NAME] && !req.query[constants.SHARD_KEY_WOPI_NAME] && process.env.DEFAULT_SHARD_KEY) {
ctx.logger.warn('commandFromServer. Pass query string parameter "%s" to correctly process commands with "key" in sharded cluster', constants.SHARD_KEY_API_NAME);
}
yield *commandHandle(ctx, params, req, output);
}
} catch (err) {
Expand Down
65 changes: 34 additions & 31 deletions DocService/sources/canvasservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ function getOpenedAtJSONParams(row) {
return undefined;
}

var getOutputData = co.wrap(function* (ctx, cmd, outputData, key, optConn, optAdditionalOutput, opt_bIsRestore) {
async function getOutputData(ctx, cmd, outputData, key, optConn, optAdditionalOutput, opt_bIsRestore) {
const tenExpUpdateVersionStatus = ms(ctx.getCfg('services.CoAuthoring.expire.updateVersionStatus', cfgExpUpdateVersionStatus));

let status, statusInfo, password, creationDate, openedAt, row;
let selectRes = yield taskResult.select(ctx, key);
let selectRes = await taskResult.select(ctx, key);
if (selectRes.length > 0) {
row = selectRes[0];
status = row.status;
Expand All @@ -184,31 +184,29 @@ var getOutputData = co.wrap(function* (ctx, cmd, outputData, key, optConn, optAd
case commonDefines.FileStatus.SaveVersion:
case commonDefines.FileStatus.UpdateVersion:
case commonDefines.FileStatus.Ok:
if(commonDefines.FileStatus.Ok == status) {
if(commonDefines.FileStatus.Ok === status) {
outputData.setStatus('ok');
} else if (commonDefines.FileStatus.SaveVersion == status ||
} else if (optConn && (optConn.user.view || optConn.isCloseCoAuthoring)) {
outputData.setStatus('ok');
} else if (commonDefines.FileStatus.SaveVersion === status ||
(!opt_bIsRestore && commonDefines.FileStatus.UpdateVersion === status &&
Date.now() - statusInfo * 60000 > tenExpUpdateVersionStatus)) {
if (optConn && (optConn.user.view || optConn.isCloseCoAuthoring)) {
outputData.setStatus(constants.FILE_STATUS_UPDATE_VERSION);
if (commonDefines.FileStatus.UpdateVersion === status) {
ctx.logger.warn("UpdateVersion expired");
}
var updateMask = new taskResult.TaskResultData();
updateMask.tenant = ctx.tenant;
updateMask.key = key;
updateMask.status = status;
updateMask.statusInfo = statusInfo;
var updateTask = new taskResult.TaskResultData();
updateTask.status = commonDefines.FileStatus.Ok;
updateTask.statusInfo = constants.NO_ERROR;
var updateIfRes = await taskResult.updateIf(ctx, updateTask, updateMask);
if (updateIfRes.affectedRows > 0) {
outputData.setStatus('ok');
} else {
if (commonDefines.FileStatus.UpdateVersion === status) {
ctx.logger.warn("UpdateVersion expired");
}
var updateMask = new taskResult.TaskResultData();
updateMask.tenant = ctx.tenant;
updateMask.key = key;
updateMask.status = status;
updateMask.statusInfo = statusInfo;
var updateTask = new taskResult.TaskResultData();
updateTask.status = commonDefines.FileStatus.Ok;
updateTask.statusInfo = constants.NO_ERROR;
var updateIfRes = yield taskResult.updateIf(ctx, updateTask, updateMask);
if (updateIfRes.affectedRows > 0) {
outputData.setStatus('ok');
} else {
outputData.setStatus(constants.FILE_STATUS_UPDATE_VERSION);
}
outputData.setStatus(constants.FILE_STATUS_UPDATE_VERSION);
}
} else {
outputData.setStatus(constants.FILE_STATUS_UPDATE_VERSION);
Expand All @@ -219,9 +217,9 @@ var getOutputData = co.wrap(function* (ctx, cmd, outputData, key, optConn, optAd
if (optConn) {
let url;
if(cmd.getInline()) {
url = yield getPrintFileUrl(ctx, key, optConn.baseUrl, cmd.getTitle());
url = await getPrintFileUrl(ctx, key, optConn.baseUrl, cmd.getTitle());
} else {
url = yield storage.getSignedUrl(ctx, optConn.baseUrl, strPath, commonDefines.c_oAscUrlTypes.Temporary,
url = await storage.getSignedUrl(ctx, optConn.baseUrl, strPath, commonDefines.c_oAscUrlTypes.Temporary,
cmd.getTitle());
}
outputData.setData(url);
Expand All @@ -237,8 +235,8 @@ var getOutputData = co.wrap(function* (ctx, cmd, outputData, key, optConn, optAd
let decryptedPassword;
let isCorrectPassword;
if (password && encryptedUserPassword) {
decryptedPassword = yield utils.decryptPassword(ctx, password);
userPassword = yield utils.decryptPassword(ctx, encryptedUserPassword);
decryptedPassword = await utils.decryptPassword(ctx, password);
userPassword = await utils.decryptPassword(ctx, encryptedUserPassword);
isCorrectPassword = decryptedPassword === userPassword;
}
if(password && !isCorrectPassword) {
Expand All @@ -252,7 +250,7 @@ var getOutputData = co.wrap(function* (ctx, cmd, outputData, key, optConn, optAd
}
} else if (optConn) {
outputData.setOpenedAt(openedAt);
outputData.setData(yield storage.getSignedUrls(ctx, optConn.baseUrl, key, commonDefines.c_oAscUrlTypes.Session, creationDate));
outputData.setData(await storage.getSignedUrls(ctx, optConn.baseUrl, key, commonDefines.c_oAscUrlTypes.Session, creationDate));
} else if (optAdditionalOutput) {
optAdditionalOutput.needUrlKey = key;
optAdditionalOutput.needUrlMethod = 0;
Expand All @@ -267,7 +265,7 @@ var getOutputData = co.wrap(function* (ctx, cmd, outputData, key, optConn, optAd
outputData.setStatus('needparams');
var settingsPath = key + '/' + 'origin.' + cmd.getFormat();
if (optConn) {
let url = yield storage.getSignedUrl(ctx, optConn.baseUrl, settingsPath, commonDefines.c_oAscUrlTypes.Temporary);
let url = await storage.getSignedUrl(ctx, optConn.baseUrl, settingsPath, commonDefines.c_oAscUrlTypes.Temporary);
outputData.setData(url);
} else if (optAdditionalOutput) {
optAdditionalOutput.needUrlKey = settingsPath;
Expand All @@ -286,7 +284,7 @@ var getOutputData = co.wrap(function* (ctx, cmd, outputData, key, optConn, optAd
case commonDefines.FileStatus.ErrToReload:
outputData.setStatus('err');
outputData.setData(statusInfo);
yield cleanupErrToReload(ctx, key);
await cleanupErrToReload(ctx, key);
break;
case commonDefines.FileStatus.None:
//this status has no handler
Expand All @@ -300,7 +298,7 @@ var getOutputData = co.wrap(function* (ctx, cmd, outputData, key, optConn, optAd
break;
}
return status;
});
}
function* addRandomKeyTaskCmd(ctx, cmd) {
var task = yield* taskResult.addRandomKeyTask(ctx, cmd.getDocId());
cmd.setSaveKey(task.key);
Expand Down Expand Up @@ -771,6 +769,11 @@ function* commandImgurls(ctx, conn, cmd, outputData) {
}
}
if (isAllow) {
if (format === constants.AVS_OFFICESTUDIO_FILE_IMAGE_TIFF) {
data = yield utilsDocService.convertImageToPng(ctx, data);
format = constants.AVS_OFFICESTUDIO_FILE_IMAGE_PNG;
formatStr = formatChecker.getStringFromFormat(format);
}
let strLocalPath = 'media/' + crypto.randomBytes(16).toString("hex") + '_';
if (urlParsed) {
var urlBasename = pathModule.basename(urlParsed.pathname);
Expand Down
9 changes: 8 additions & 1 deletion DocService/sources/converterservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,10 @@ function convertRequest(req, res, isJson) {
cmd.setTitle(path.basename(params.title, path.extname(params.title)) + '.' + outputExt);
}
var async = (typeof params.async === 'string') ? 'true' == params.async : params.async;

if (async && !req.query[constants.SHARD_KEY_API_NAME] && !req.query[constants.SHARD_KEY_WOPI_NAME] && process.env.DEFAULT_SHARD_KEY) {
ctx.logger.warn('convertRequest set async=false. Pass query string parameter "%s" to correctly process request in sharded cluster', constants.SHARD_KEY_API_NAME);
async = false;
}
if (constants.AVS_OFFICESTUDIO_FILE_UNKNOWN !== cmd.getOutputFormat()) {
let fileTo = constants.OUTPUT_NAME + '.' + outputExt;
var status = yield* convertByCmd(ctx, cmd, async, fileTo, undefined, undefined, undefined, undefined, true);
Expand Down Expand Up @@ -466,6 +469,10 @@ function builderRequest(req, res) {
yield* docsCoServer.addTask(queueData, constants.QUEUE_PRIORITY_LOW);
}
let async = (typeof params.async === 'string') ? 'true' === params.async : params.async;
if (async && !req.query[constants.SHARD_KEY_API_NAME] && !req.query[constants.SHARD_KEY_WOPI_NAME] && process.env.DEFAULT_SHARD_KEY) {
ctx.logger.warn('builderRequest set async=false. Pass query string parameter "%s" to correctly process request in sharded cluster', constants.SHARD_KEY_API_NAME);
async = false;
}
let status = yield* convertByCmd(ctx, cmd, async, undefined, undefined, constants.QUEUE_PRIORITY_LOW);
end = status.end;
error = status.err;
Expand Down
5 changes: 5 additions & 0 deletions DocService/sources/fileuploaderservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ exports.uploadImageFile = function(req, res) {
var supportedFormats = tenTypesUpload || 'jpg';
let formatLimit = formatStr && -1 !== supportedFormats.indexOf(formatStr);
if (formatLimit) {
if (format === constants.AVS_OFFICESTUDIO_FILE_IMAGE_TIFF) {
buffer = yield utilsDocService.convertImageToPng(ctx, buffer);
format = constants.AVS_OFFICESTUDIO_FILE_IMAGE_PNG;
formatStr = formatChecker.getStringFromFormat(format);
}
//a hash is written at the beginning to avoid errors during parallel upload in co-editing
var strImageName = crypto.randomBytes(16).toString("hex");
var strPathRel = 'media/' + strImageName + '.' + formatStr;
Expand Down
35 changes: 23 additions & 12 deletions DocService/sources/utilsDocService.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,32 @@ async function fixImageExifRotation(ctx, buffer) {
let exif = parser.parse();
if (exif.tags?.Orientation > 1) {
ctx.logger.debug('fixImageExifRotation remove exif and rotate:%j', exif);
let image = await Jimp.read(buffer);
//remove exif
image.bitmap.exifBuffer = undefined;
//set jpeg and png quality
//https://www.imagemagick.org/script/command-line-options.php#quality
image.quality(90);
image.deflateLevel(7);
buffer = await image.getBufferAsync(Jimp.AUTO);
buffer = convertImageTo(ctx, buffer, Jimp.AUTO);
}
} catch (e) {
ctx.logger.debug('fixImageExifRotation error:%s', e.stack);
}
return buffer;
}
async function convertImageToPng(ctx, buffer) {
return await convertImageTo(ctx, buffer, Jimp.MIME_PNG);
}
async function convertImageTo(ctx, buffer, mime) {
try {
ctx.logger.debug('convertImageTo %s', mime);
let image = await Jimp.read(buffer);
//remove exif
image.bitmap.exifBuffer = undefined;
//set jpeg and png quality
//https://www.imagemagick.org/script/command-line-options.php#quality
image.quality(90);
image.deflateLevel(7);
buffer = await image.getBufferAsync(mime);
} catch (e) {
ctx.logger.debug('convertImageTo error:%s', e.stack);
}
return buffer;
}
/**
*
* @param {string} lang
Expand All @@ -70,7 +82,6 @@ function localeToLCID(lang) {
return elem && elem.id;
}

module.exports = {
fixImageExifRotation,
localeToLCID
};
module.exports.fixImageExifRotation = fixImageExifRotation;
module.exports.convertImageToPng = convertImageToPng;
module.exports.localeToLCID = localeToLCID;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"scripts": {
"perf-expired": "cd ./DocService&& cross-env NODE_ENV=development-windows NODE_CONFIG_DIR=../Common/config node ../tests/perf/checkFileExpire.js",
"perf-exif": "cd ./DocService&& cross-env NODE_ENV=development-windows NODE_CONFIG_DIR=../Common/config node ../tests/perf/fixImageExifRotation.js",
"perf-png": "cd ./DocService&& cross-env NODE_ENV=development-windows NODE_CONFIG_DIR=../Common/config node ../tests/perf/convertImageToPng.js",
"unit tests": "cd ./DocService && jest unit --inject-globals=false --config=../tests/jest.config.js",
"integration tests with server instance": "cd ./DocService && jest integration/withServerInstance --inject-globals=false --config=../tests/jest.config.js",
"integration database tests": "cd ./DocService && jest integration/databaseTests --inject-globals=false --config=../tests/jest.config.js",
Expand Down
Loading

0 comments on commit c990926

Please sign in to comment.