Skip to content

Commit

Permalink
Merge pull request #457 from ONLYOFFICE/feature/wopi-put-relative-fil…
Browse files Browse the repository at this point in the history
…e-save-as

Feature/wopi put relative file save as
  • Loading branch information
konovalovsergey authored Feb 21, 2024
2 parents 6fb2df4 + 92c16d1 commit 69ff2f3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
8 changes: 8 additions & 0 deletions Common/sources/commondefines.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function InputCommand(data, copyExplicit) {
this['status_info_in'] = data['status_info_in'];
this['attempt'] = data['attempt'];
this['convertToOrigin'] = data['convertToOrigin'];
this['isSaveAs'] = data['isSaveAs'];
if (copyExplicit) {
this['withAuthorization'] = data['withAuthorization'];
this['externalChangeInfo'] = data['externalChangeInfo'];
Expand Down Expand Up @@ -171,6 +172,7 @@ function InputCommand(data, copyExplicit) {
this['attempt'] = undefined;
this['convertToOrigin'] = undefined;
this['originformat'] = undefined;
this['isSaveAs'] = undefined;
}
}
InputCommand.prototype = {
Expand Down Expand Up @@ -503,6 +505,12 @@ InputCommand.prototype = {
},
setConvertToOrigin: function(data) {
this['convertToOrigin'] = data;
},
getIsSaveAs: function() {
return this['isSaveAs'];
},
setIsSaveAs: function(data) {
this['isSaveAs'] = data;
}
};

Expand Down
30 changes: 23 additions & 7 deletions DocService/sources/canvasservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,18 @@ exports.saveFromChanges = function(ctx, docId, statusInfo, optFormat, opt_userId
}
});
};

async function processWopiSaveAs(ctx, cmd) {
const info = await docsCoServer.getCallback(ctx, cmd.getDocId(), cmd.getUserIndex());
// info.wopiParams is null if it is not wopi
if (info.wopiParams) {
const suggestedTargetType = `.${formatChecker.getStringFromFormat(cmd.getOutputFormat())}`;
const storageFilePath = `${cmd.getSaveKey()}/${cmd.getOutputPath()}`;
const stream = await storage.createReadStream(ctx, storageFilePath);
const { wopiSrc, access_token } = info.wopiParams.userAuth;
await wopiClient.putRelativeFile(ctx, wopiSrc, access_token, null, stream.readStream, stream.ContentLength, suggestedTargetType, false);
}
}
exports.receiveTask = function(data, ack) {
return co(function* () {
let ctx = new operationContext.Context();
Expand All @@ -1741,17 +1753,21 @@ exports.receiveTask = function(data, ack) {
var outputData = new OutputData(cmd.getCommand());
var command = cmd.getCommand();
var additionalOutput = {needUrlKey: null, needUrlMethod: null, needUrlType: null, needUrlIsCorrectPassword: undefined, creationDate: undefined, openedAt: undefined};
if ('open' == command || 'reopen' == command) {
if ('open' === command || 'reopen' === command) {
yield getOutputData(ctx, cmd, outputData, cmd.getDocId(), null, additionalOutput);
} else if ('save' == command || 'savefromorigin' == command) {
yield getOutputData(ctx, cmd, outputData, cmd.getSaveKey(), null, additionalOutput);
} else if ('sfcm' == command) {
} else if ('save' === command || 'savefromorigin' === command) {
let status = yield getOutputData(ctx, cmd, outputData, cmd.getSaveKey(), null, additionalOutput);
if (commonDefines.FileStatus.Ok === status && cmd.getIsSaveAs()) {
yield processWopiSaveAs(ctx, cmd);
//todo in case of wopi no need to send url. send it to avoid stubs in sdk
}
} else if ('sfcm' === command) {
yield commandSfcCallback(ctx, cmd, true);
} else if ('sfc' == command) {
} else if ('sfc' === command) {
yield commandSfcCallback(ctx, cmd, false);
} else if ('sendmm' == command) {
} else if ('sendmm' === command) {
yield* commandSendMMCallback(ctx, cmd);
} else if ('conv' == command) {
} else if ('conv' === command) {
//nothing
}
if (outputData.getStatus()) {
Expand Down
6 changes: 4 additions & 2 deletions DocService/sources/wopiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,10 @@ function putRelativeFile(ctx, wopiSrc, access_token, data, dataStream, dataSize,
return postRes;
}

let headers = {'X-WOPI-Override': 'PUT_RELATIVE', 'X-WOPI-SuggestedTarget': utf7.encode(suggestedTarget),
'X-WOPI-FileConversion': isFileConversion};
let headers = {'X-WOPI-Override': 'PUT_RELATIVE', 'X-WOPI-SuggestedTarget': utf7.encode(suggestedTarget)};
if (isFileConversion) {
headers['X-WOPI-FileConversion'] = isFileConversion;
}
fillStandardHeaders(ctx, headers, uri, access_token);

ctx.logger.debug('wopi putRelativeFile request uri=%s headers=%j', uri, headers);
Expand Down

0 comments on commit 69ff2f3

Please sign in to comment.