mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-04-07 14:04:35 +08:00
[wopi] Fix crash with postgres<9.5
This commit is contained in:
@ -1100,7 +1100,9 @@ let unlockWopiDoc = co.wrap(function*(ctx, docId, opt_userIndex) {
|
||||
if (getRes && getRes.wopiParams && getRes.wopiParams.userAuth && 'view' !== getRes.wopiParams.userAuth.mode) {
|
||||
yield wopiClient.unlock(ctx, getRes.wopiParams);
|
||||
let unlockInfo = wopiClient.getWopiUnlockMarker(getRes.wopiParams);
|
||||
yield canvasService.commandOpenStartPromise(ctx, docId, undefined, true, unlockInfo);
|
||||
if (unlockInfo) {
|
||||
yield canvasService.commandOpenStartPromise(ctx, docId, undefined, true, unlockInfo);
|
||||
}
|
||||
}
|
||||
});
|
||||
function* cleanDocumentOnExit(ctx, docId, deleteChanges, opt_userIndex) {
|
||||
@ -2345,8 +2347,8 @@ exports.install = function(server, callbackFunction) {
|
||||
cmd.setWopiParams(wopiParams);
|
||||
if (wopiParams) {
|
||||
documentCallback = null;
|
||||
if (!wopiParams.userAuth) {
|
||||
yield* sendFileErrorAuth(ctx, conn, data.sessionId, 'Wopi without userAuth');
|
||||
if (!wopiParams.userAuth || !wopiParams.commonInfo) {
|
||||
yield* sendFileErrorAuth(ctx, conn, data.sessionId, `invalid wopi callback (maybe postgres<9.5) ${JSON.stringify(wopiParams)}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -3505,7 +3507,7 @@ exports.install = function(server, callbackFunction) {
|
||||
let callback = selectRes[0].callback;
|
||||
let callbackUrl = sqlBase.UserCallback.prototype.getCallbackByUserIndex(ctx, callback);
|
||||
let wopiParams = wopiClient.parseWopiCallback(ctx, callbackUrl, callback);
|
||||
if (wopiParams) {
|
||||
if (wopiParams && wopiParams.commonInfo) {
|
||||
yield wopiClient.lock(ctx, 'REFRESH_LOCK', wopiParams.commonInfo.lockId,
|
||||
wopiParams.commonInfo.fileInfo, wopiParams.userAuth);
|
||||
}
|
||||
|
||||
@ -617,7 +617,7 @@ let commandSfctByCmd = co.wrap(function*(ctx, cmd, opt_priority, opt_expiration,
|
||||
yield* addRandomKeyTaskCmd(ctx, cmd);
|
||||
addPasswordToCmd(ctx, cmd, row.password);
|
||||
let userAuthStr = sqlBase.UserCallback.prototype.getCallbackByUserIndex(ctx, row.callback);
|
||||
cmd.setWopiParams(wopiClient.parseWopiCallback(ctx, userAuthStr));
|
||||
cmd.setWopiParams(wopiClient.parseWopiCallback(ctx, userAuthStr, row.callback));
|
||||
cmd.setOutputFormat(changeFormatByOrigin(ctx, row, cmd.getOutputFormat()));
|
||||
cmd.setJsonParams(getOpenedAtJSONParams(row));
|
||||
var queueData = getSaveTask(ctx, cmd);
|
||||
@ -1602,7 +1602,7 @@ exports.saveFromChanges = function(ctx, docId, statusInfo, optFormat, opt_userId
|
||||
cmd.setUserActionIndex(opt_userIndex);
|
||||
cmd.setJsonParams(getOpenedAtJSONParams(row));
|
||||
let userAuthStr = sqlBase.UserCallback.prototype.getCallbackByUserIndex(ctx, row.callback);
|
||||
cmd.setWopiParams(wopiClient.parseWopiCallback(ctx, userAuthStr));
|
||||
cmd.setWopiParams(wopiClient.parseWopiCallback(ctx, userAuthStr, row.callback));
|
||||
addPasswordToCmd(ctx, cmd, row && row.password);
|
||||
yield* addRandomKeyTaskCmd(ctx, cmd);
|
||||
var queueData = getSaveTask(ctx, cmd);
|
||||
|
||||
@ -235,6 +235,9 @@ function isWopiModifiedMarker(url) {
|
||||
}
|
||||
}
|
||||
function getWopiUnlockMarker(wopiParams) {
|
||||
if (!wopiParams.userAuth || !wopiParams.commonInfo) {
|
||||
return;
|
||||
}
|
||||
return JSON.stringify(Object.assign({unlockId: wopiParams.commonInfo.lockId}, wopiParams.userAuth));
|
||||
}
|
||||
function getWopiModifiedMarker(wopiParams, lastModifiedTime) {
|
||||
@ -265,10 +268,14 @@ function parseWopiCallback(ctx, userAuthStr, opt_url) {
|
||||
let commonInfoStr = sqlBase.UserCallback.prototype.getCallbackByUserIndex(ctx, opt_url, 1);
|
||||
if (isWopiCallback(commonInfoStr)) {
|
||||
commonInfo = JSON.parse(commonInfoStr);
|
||||
lastModifiedTime = commonInfo.fileInfo.LastModifiedTime;
|
||||
if (lastModifiedTime) {
|
||||
let callbacks = sqlBase.UserCallback.prototype.getCallbacks(ctx, opt_url);
|
||||
lastModifiedTime = getLastModifiedTimeFromCallbacks(callbacks);
|
||||
if (commonInfo.fileInfo) {
|
||||
lastModifiedTime = commonInfo.fileInfo.LastModifiedTime;
|
||||
if (lastModifiedTime) {
|
||||
let callbacks = sqlBase.UserCallback.prototype.getCallbacks(ctx, opt_url);
|
||||
lastModifiedTime = getLastModifiedTimeFromCallbacks(callbacks);
|
||||
}
|
||||
} else {
|
||||
commonInfo = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -488,7 +495,7 @@ function putFile(ctx, wopiParams, data, dataStream, dataSize, userLastChangeId,
|
||||
let postRes = null;
|
||||
try {
|
||||
ctx.logger.info('wopi PutFile start');
|
||||
if (!wopiParams.userAuth) {
|
||||
if (!wopiParams.userAuth || !wopiParams.commonInfo) {
|
||||
return postRes;
|
||||
}
|
||||
let fileInfo = wopiParams.commonInfo.fileInfo;
|
||||
@ -561,7 +568,7 @@ function renameFile(ctx, wopiParams, name) {
|
||||
let res = undefined;
|
||||
try {
|
||||
ctx.logger.info('wopi RenameFile start');
|
||||
if (!wopiParams.userAuth) {
|
||||
if (!wopiParams.userAuth || !wopiParams.commonInfo) {
|
||||
return res;
|
||||
}
|
||||
let fileInfo = wopiParams.commonInfo.fileInfo;
|
||||
@ -665,11 +672,11 @@ function unlock(ctx, wopiParams) {
|
||||
return co(function* () {
|
||||
try {
|
||||
ctx.logger.info('wopi Unlock start');
|
||||
if (!wopiParams.userAuth || !wopiParams.commonInfo) {
|
||||
return;
|
||||
}
|
||||
let fileInfo = wopiParams.commonInfo.fileInfo;
|
||||
if (fileInfo && fileInfo.SupportsLocks) {
|
||||
if (!wopiParams.userAuth) {
|
||||
return;
|
||||
}
|
||||
let wopiSrc = wopiParams.userAuth.wopiSrc;
|
||||
let lockId = wopiParams.commonInfo.lockId;
|
||||
let access_token = wopiParams.userAuth.access_token;
|
||||
|
||||
@ -896,16 +896,17 @@ function* ExecuteTask(ctx, task) {
|
||||
if (wopiParams) {
|
||||
withAuthorization = false;
|
||||
filterPrivate = false;
|
||||
let fileInfo = wopiParams.commonInfo.fileInfo;
|
||||
let fileInfo = wopiParams.commonInfo?.fileInfo;
|
||||
let userAuth = wopiParams.userAuth;
|
||||
fileSize = fileInfo.Size;
|
||||
if (fileInfo.FileUrl) {
|
||||
fileSize = fileInfo?.Size;
|
||||
if (fileInfo?.FileUrl) {
|
||||
//Requests to the FileUrl can not be signed using proof keys. The FileUrl is used exactly as provided by the host, so it does not necessarily include the access token, which is required to construct the expected proof.
|
||||
url = fileInfo.FileUrl;
|
||||
} else if (fileInfo.TemplateSource) {
|
||||
} else if (fileInfo?.TemplateSource) {
|
||||
url = fileInfo.TemplateSource;
|
||||
} else if (userAuth) {
|
||||
url = `${userAuth.wopiSrc}/contents?access_token=${userAuth.access_token}`;
|
||||
headers = {'X-WOPI-MaxExpectedSize': cfgDownloadMaxBytes, 'X-WOPI-ItemVersion': fileInfo.Version};
|
||||
headers = {'X-WOPI-MaxExpectedSize': cfgDownloadMaxBytes};
|
||||
wopiClient.fillStandardHeaders(headers, url, userAuth.access_token);
|
||||
}
|
||||
ctx.logger.debug('wopi url=%s; headers=%j', url, headers);
|
||||
|
||||
Reference in New Issue
Block a user