Merge branch release/v7.5.0 into develop

This commit is contained in:
papacarlo
2023-10-25 10:29:43 +00:00
8 changed files with 147 additions and 59 deletions

View File

@ -898,7 +898,7 @@ async function applyForceSaveCache(ctx, docId, forceSave, type, opt_userConnecti
}
return res;
}
async function startForceSave(ctx, docId, type, opt_userdata, opt_formdata, opt_userId, opt_userConnectionId, opt_userConnectionDocId, opt_userIndex, opt_responseKey, opt_baseUrl, opt_queue, opt_pubsub) {
async function startForceSave(ctx, docId, type, opt_userdata, opt_formdata, opt_userId, opt_userConnectionId, opt_userConnectionDocId, opt_userIndex, opt_responseKey, opt_baseUrl, opt_queue, opt_pubsub, opt_conn) {
ctx.logger.debug('startForceSave start');
let res = {code: commonDefines.c_oAscServerCommandErrors.NoError, time: null, inProgress: false};
let startedForceSave;
@ -910,6 +910,16 @@ async function startForceSave(ctx, docId, type, opt_userdata, opt_formdata, opt_
});
if (!hasEncrypted) {
let forceSave = await editorData.getForceSave(ctx, docId);
if (!forceSave && commonDefines.c_oAscForceSaveTypes.Form === type && opt_conn) {
//stub to send forms without changes
let newChangesLastDate = new Date();
newChangesLastDate.setMilliseconds(0);//remove milliseconds avoid issues with MySQL datetime rounding
let newChangesLastTime = newChangesLastDate.getTime();
let baseUrl = utils.getBaseUrlByConnection(ctx, opt_conn);
let changeInfo = getExternalChangeInfo(opt_conn.user, newChangesLastTime);
await editorData.setForceSave(ctx, docId, newChangesLastTime, 0, baseUrl, changeInfo, null);
forceSave = await editorData.getForceSave(ctx, docId);
}
let applyCacheRes = await applyForceSaveCache(ctx, docId, forceSave, type, opt_userConnectionId, opt_userConnectionDocId, opt_responseKey, opt_formdata);
startedForceSave = applyCacheRes.startedForceSave;
if (applyCacheRes.notModified) {
@ -1008,7 +1018,9 @@ function* startRPC(ctx, conn, responseKey, data) {
case 'sendForm': {
let forceSaveRes;
if (conn.user) {
forceSaveRes = yield startForceSave(ctx, docId, commonDefines.c_oAscForceSaveTypes.Form, undefined, data.formdata, conn.user.idOriginal, conn.user.id, undefined, conn.user.indexUser, responseKey);
forceSaveRes = yield startForceSave(ctx, docId, commonDefines.c_oAscForceSaveTypes.Form, undefined,
data.formdata, conn.user.idOriginal, conn.user.id, undefined, conn.user.indexUser,
responseKey, undefined, undefined, undefined, conn);
}
if (!forceSaveRes || commonDefines.c_oAscServerCommandErrors.NoError !== forceSaveRes.code || forceSaveRes.inProgress) {
sendDataRpc(ctx, conn, responseKey, forceSaveRes);
@ -2548,7 +2560,7 @@ exports.install = function(server, callbackFunction) {
aggregationCtx.init(tenantManager.getDefautTenant(), ctx.docId, ctx.userId);
//yield ctx.initTenantCache(); //no need
licenseInfoAggregation = tenantManager.getServerLicense();
licenseType = yield* _checkLicenseAuth(aggregationCtx, licenseInfoAggregation, conn.user.idOriginal, isLiveViewer, logPrefixServer);
licenseType = yield* _checkLicenseAuth(aggregationCtx, licenseInfoAggregation, `${ctx.tenant}:${ conn.user.idOriginal}`, isLiveViewer, logPrefixServer);
}
conn.licenseType = licenseType;
if ((c_LR.Success !== licenseType && c_LR.SuccessLimit !== licenseType) || (!tenIsAnonymousSupport && data.IsAnonymousUser)) {
@ -2562,7 +2574,7 @@ exports.install = function(server, callbackFunction) {
yield* updateEditUsers(ctx, licenseInfo, conn.user.idOriginal, !!data.IsAnonymousUser, isLiveViewer);
if (aggregationCtx && licenseInfoAggregation) {
//update server aggregation license
yield* updateEditUsers(aggregationCtx, licenseInfoAggregation, conn.user.idOriginal, !!data.IsAnonymousUser, isLiveViewer);
yield* updateEditUsers(aggregationCtx, licenseInfoAggregation, `${ctx.tenant}:${ conn.user.idOriginal}`, !!data.IsAnonymousUser, isLiveViewer);
}
}
}
@ -3793,10 +3805,10 @@ exports.install = function(server, callbackFunction) {
}
yield addPresence(ctx, conn, false);
if (utils.isLiveViewer(conn)) {
countViewByShard++;
countLiveViewByShard++;
tenant.countLiveViewByShard++;
} else if(conn.isCloseCoAuthoring || (conn.user && conn.user.view)) {
countLiveViewByShard++;
countViewByShard++;
tenant.countViewByShard++;
} else {
countEditByShard++;
@ -3827,9 +3839,9 @@ exports.install = function(server, callbackFunction) {
let aggregationCtx = new operationContext.Context();
aggregationCtx.init(tenantManager.getDefautTenant(), ctx.docId, ctx.userId);
//yield ctx.initTenantCache();//no need
yield editorData.setEditorConnectionsCountByShard(ctx, SHARD_ID, countEditByShard);
yield editorData.setLiveViewerConnectionsCountByShard(ctx, SHARD_ID, countLiveViewByShard);
yield editorData.setViewerConnectionsCountByShard(ctx, SHARD_ID, countViewByShard);
yield editorData.setEditorConnectionsCountByShard(aggregationCtx, SHARD_ID, countEditByShard);
yield editorData.setLiveViewerConnectionsCountByShard(aggregationCtx, SHARD_ID, countLiveViewByShard);
yield editorData.setViewerConnectionsCountByShard(aggregationCtx, SHARD_ID, countViewByShard);
}
ctx.initDefault();
} catch (err) {
@ -3985,9 +3997,12 @@ exports.healthCheck = function(req, res) {
exports.licenseInfo = function(req, res) {
return co(function*() {
let isError = false;
let serverDate = new Date();
//security risk of high-precision time
serverDate.setMilliseconds(0);
let output = {
connectionsStat: {}, licenseInfo: {}, serverInfo: {
buildVersion: commonDefines.buildVersion, buildNumber: commonDefines.buildNumber,
buildVersion: commonDefines.buildVersion, buildNumber: commonDefines.buildNumber, date: serverDate.toISOString()
}, quota: {
edit: {
connectionsCount: 0,

View File

@ -52,6 +52,7 @@ var statsDClient = require('./../../Common/sources/statsdclient');
var operationContext = require('./../../Common/sources/operationContext');
var tenantManager = require('./../../Common/sources/tenantManager');
var config = require('config');
//const sharp = require("sharp");
const cfgTypesUpload = config.get('services.CoAuthoring.utils.limits_image_types_upload');
const cfgImageSize = config.get('services.CoAuthoring.server.limits_image_size');
@ -347,12 +348,14 @@ function* saveParts(ctx, cmd, filename) {
}
if (cmd.getUrl()) {
result = true;
} else {
} else if (cmd.getData() && cmd.getData().length > 0) {
var buffer = cmd.getData();
yield storage.putObject(ctx, cmd.getSaveKey() + '/' + filename, buffer, buffer.length);
//delete data to prevent serialize into json
cmd.data = null;
result = (SAVE_TYPE_COMPLETE_ALL === saveType || SAVE_TYPE_COMPLETE === saveType);
} else {
result = true;
}
return result;
}
@ -725,6 +728,13 @@ function* commandImgurls(ctx, conn, cmd, outputData) {
const filterPrivate = !authorizations[i] || !tenAllowPrivateIPAddressForSignedRequests;
let getRes = yield utils.downloadUrlPromise(ctx, urlSource, tenImageDownloadTimeout, tenImageSize, authorizations[i], filterPrivate);
data = getRes.body;
// //fix exif rotation
// //todo move to commons
// let sharpTransform = sharp(data);
// let metadata = yield sharpTransform.metadata();
// if (undefined !== metadata.orientation && metadata.orientation > 1) {
// data = yield sharpTransform.rotate().toBuffer();
// }
urlParsed = urlModule.parse(urlSource);
} catch (e) {
data = undefined;
@ -818,14 +828,17 @@ function* commandPathUrl(ctx, conn, cmd, outputData) {
}
}
function* commandSaveFromOrigin(ctx, cmd, outputData, password) {
let docPassword = sqlBase.DocumentPassword.prototype.getDocPassword(ctx, password);
if (docPassword.initial) {
cmd.setPassword(docPassword.initial);
var completeParts = yield* saveParts(ctx, cmd, "changes0.json");
if (completeParts) {
let docPassword = sqlBase.DocumentPassword.prototype.getDocPassword(ctx, password);
if (docPassword.initial) {
cmd.setPassword(docPassword.initial);
}
var queueData = getSaveTask(ctx, cmd);
queueData.setFromOrigin(true);
queueData.setFromChanges(true);
yield* docsCoServer.addTask(queueData, constants.QUEUE_PRIORITY_LOW);
}
yield* addRandomKeyTaskCmd(ctx, cmd);
var queueData = getSaveTask(ctx, cmd);
queueData.setFromOrigin(true);
yield* docsCoServer.addTask(queueData, constants.QUEUE_PRIORITY_LOW);
outputData.setStatus('ok');
outputData.setData(cmd.getSaveKey());
}

View File

@ -43,7 +43,7 @@ var storageBase = require('./../../Common/sources/storage-base');
var formatChecker = require('./../../Common/sources/formatchecker');
const commonDefines = require('./../../Common/sources/commondefines');
const operationContext = require('./../../Common/sources/operationContext');
//const sharp = require("sharp");
var config = require('config');
const cfgImageSize = config.get('services.CoAuthoring.server.limits_image_size');
@ -101,7 +101,8 @@ function checkJwtUploadTransformRes(ctx, errorName, checkJwtRes){
if (checkJwtRes.decoded) {
var doc = checkJwtRes.decoded.document;
var edit = checkJwtRes.decoded.editorConfig;
if (!edit.ds_view && !edit.ds_isCloseCoAuthoring) {
//todo check view and pdf editor (temporary fix)
if (!edit.ds_isCloseCoAuthoring) {
res.err = false;
res.docId = doc.key;
res.encrypted = doc.ds_encrypted;
@ -255,6 +256,14 @@ exports.uploadImageFile = function(req, res) {
var strImageName = crypto.randomBytes(16).toString("hex");
var strPathRel = 'media/' + strImageName + '.' + formatStr;
var strPath = docId + '/' + strPathRel;
// //fix exif rotation
// //todo move to commons
// let sharpTransform = sharp(buffer);
// let metadata = yield sharpTransform.metadata();
// if (undefined !== metadata.orientation && metadata.orientation > 1) {
// buffer = yield sharpTransform.rotate().toBuffer();
// }
yield storageBase.putObject(ctx, strPath, buffer, buffer.length);
output[strPathRel] = yield storageBase.getSignedUrl(ctx, utils.getBaseUrlByRequest(ctx, req), strPath,
commonDefines.c_oAscUrlTypes.Session);