Skip to content

Commit

Permalink
[wopi] Add wopi_RefreshFile command; Stub for validateAuthToken
Browse files Browse the repository at this point in the history
  • Loading branch information
konovalovsergey committed Sep 26, 2024
1 parent b46e0ab commit ac8fda7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
20 changes: 19 additions & 1 deletion DocService/sources/DocsCoServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,23 @@ function* startRPC(ctx, conn, responseKey, data) {
}
sendDataRpc(ctx, conn, responseKey, renameRes);
break;
case 'wopi_RefreshFile': {
let renameRes;
let selectRes = yield taskResult.select(ctx, docId);
let row = selectRes.length > 0 ? selectRes[0] : null;
if (row) {
if (row.callback) {
let userIndex = utils.getIndexFromUserId(conn.user.id, conn.user.idOriginal);
let uri = sqlBase.UserCallback.prototype.getCallbackByUserIndex(ctx, row.callback, userIndex);
let wopiParams = wopiClient.parseWopiCallback(ctx, uri, row.callback);
if (wopiParams) {
renameRes = yield wopiClient.refreshFile(ctx, wopiParams, data.name);
}
}
}
sendDataRpc(ctx, conn, responseKey, renameRes);
break;
}
case 'pathurls':
let outputData = new canvasService.OutputData(data.type);
yield* canvasService.commandPathUrls(ctx, conn, data.data, outputData);
Expand Down Expand Up @@ -2358,7 +2375,8 @@ exports.install = function(server, callbackFunction) {
} else if (data.mode && 'view' !== data.mode && !decoded?.editorConfig?.mode) {//allow to restrict rights to 'view'
res = "editorConfig.mode";
}
return res;
//todo
return "";
}
function fillDataFromJwt(ctx, decoded, data) {
let res = true;
Expand Down
21 changes: 21 additions & 0 deletions DocService/sources/wopiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,26 @@ function renameFile(ctx, wopiParams, name) {
return res;
});
}

async function refreshFile(ctx, wopiParams) {
let fileInfo = {};
try {
ctx.logger.info('wopi RefreshFile start');
if (!wopiParams.userAuth) {
return res;
}
let userAuth = wopiParams.userAuth;

fileInfo = await checkFileInfo(ctx, userAuth.wopiSrc, userAuth.access_token);
//todo jwt token

} catch (err) {
ctx.logger.error('wopi error RefreshFile:%s', err.stack);
} finally {
utils.fillResponseSimple(res, JSON.stringify(fileInfo), "application/json");
ctx.logger.info('wopi RefreshFile end');
}
}
function checkFileInfo(ctx, wopiSrc, access_token, opt_sc) {
return co(function* () {
let fileInfo = undefined;
Expand Down Expand Up @@ -1072,6 +1092,7 @@ exports.putFile = putFile;
exports.parsePutFileResponse = parsePutFileResponse;
exports.putRelativeFile = putRelativeFile;
exports.renameFile = renameFile;
exports.refreshFile = refreshFile;
exports.lock = lock;
exports.unlock = unlock;
exports.fillStandardHeaders = fillStandardHeaders;
Expand Down

0 comments on commit ac8fda7

Please sign in to comment.