Skip to content

Commit

Permalink
[wopi] Add 'usid' param to requests as user session id
Browse files Browse the repository at this point in the history
  • Loading branch information
konovalovsergey committed Jul 11, 2024
1 parent ad1eb87 commit 362d506
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 25 deletions.
4 changes: 2 additions & 2 deletions common/Drawings/Format/Format.js
Original file line number Diff line number Diff line change
Expand Up @@ -10849,12 +10849,12 @@
return;
}
var _this = this;
AscCommon.ShowImageFileDialog(Api.documentId, Api.documentUserId, Api.CoAuthoringApi.get_jwt(), Api.documentShardKey, Api.documentWopiSrc, function (error, files) {
AscCommon.ShowImageFileDialog(Api.documentId, Api.documentUserId, Api.CoAuthoringApi.get_jwt(), Api.documentShardKey, Api.documentWopiSrc, Api.documentUserSessionId, function (error, files) {
if (Asc.c_oAscError.ID.No !== error) {
Api.sendEvent("asc_onError", error, Asc.c_oAscError.Level.NoCritical);
} else {
Api.sync_StartAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.UploadImage);
AscCommon.UploadImageFiles(files, Api.documentId, Api.documentUserId, Api.CoAuthoringApi.get_jwt(), Api.documentShardKey, Api.documentWopiSrc, function (error, urls) {
AscCommon.UploadImageFiles(files, Api.documentId, Api.documentUserId, Api.CoAuthoringApi.get_jwt(), Api.documentShardKey, Api.documentWopiSrc, Api.documentUserSessionId, function (error, urls) {
if (Asc.c_oAscError.ID.No !== error) {
Api.sendEvent("asc_onError", error, Asc.c_oAscError.Level.NoCritical);
Api.sync_EndAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.UploadImage);
Expand Down
14 changes: 5 additions & 9 deletions common/apiBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
this.documentShardKey = undefined;
this.documentWopiSrc = undefined;
this.documentIsWopi = false;
this.documentUserSessionId = undefined;

this.documentOpenOptions = undefined; // Опции при открытии (пока только опции для CSV)

Expand Down Expand Up @@ -488,6 +489,7 @@
if (this.DocInfo.get_Wopi())
{
this.documentShardKey = this.DocInfo.get_Wopi()["WOPISrc"];
this.documentUserSessionId = this.DocInfo.get_Wopi()["UserSessionId"];
this.documentIsWopi = true;
}
if (this.documentOpenOptions)
Expand All @@ -503,12 +505,6 @@
window["Asc"]["Addons"]["forms"] = false;
AscCommon.g_oTableId.InitOFormClasses();
}

if (this.documentOpenOptions[Asc.c_sWopiSrcName])
{
this.documentWopiSrc = this.documentOpenOptions[Asc.c_sWopiSrcName];
this.documentIsWopi = true;
}
}
if (!this.documentWopiSrc) {
//todo add tenant in origin?
Expand Down Expand Up @@ -1922,7 +1918,7 @@
this._coAuthoringInitEnd();

let openCmd = this._getOpenCmd();
this.CoAuthoringApi.init(this.User, this.documentId, this.documentCallbackUrl, 'fghhfgsjdgfjs', this.editorId, this.documentFormatSave, this.DocInfo, this.documentShardKey, this.documentWopiSrc, openCmd);
this.CoAuthoringApi.init(this.User, this.documentId, this.documentCallbackUrl, 'fghhfgsjdgfjs', this.editorId, this.documentFormatSave, this.DocInfo, this.documentShardKey, this.documentWopiSrc, this.documentUserSessionId, openCmd);
};
baseEditorsApi.prototype._coAuthoringInitEnd = function()
{
Expand Down Expand Up @@ -2373,7 +2369,7 @@
var t = this;
if (this.WordControl) // после показа диалога может не прийти mouseUp
this.WordControl.m_bIsMouseLock = false;
AscCommon.ShowImageFileDialog(this.documentId, this.documentUserId, this.CoAuthoringApi.get_jwt(), this.documentShardKey, this.documentWopiSrc, function(error, files)
AscCommon.ShowImageFileDialog(this.documentId, this.documentUserId, this.CoAuthoringApi.get_jwt(), this.documentShardKey, this.documentWopiSrc, this.documentUserSessionId, function(error, files)
{
t._uploadCallback(error, files, obj);
}, function(error)
Expand Down Expand Up @@ -2406,7 +2402,7 @@
}
obj && obj.fStartUploadImageCallback && obj.fStartUploadImageCallback();
this.sync_StartAction(c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.UploadImage);
AscCommon.UploadImageFiles(files, this.documentId, this.documentUserId, this.CoAuthoringApi.get_jwt(), this.documentShardKey, this.documentWopiSrc, function(error, urls)
AscCommon.UploadImageFiles(files, this.documentId, this.documentUserId, this.CoAuthoringApi.get_jwt(), this.documentShardKey, this.documentWopiSrc, this.documentUserSessionId, function(error, urls)
{
if (c_oAscError.ID.No !== error)
{
Expand Down
2 changes: 2 additions & 0 deletions common/commonDefines.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ window.AscCommon.g_cIsBeta = "false";
var c_sNativeViewerFormats = '.pdf.xps.oxps.djvu';
var c_sShardKeyName = 'shardkey';
var c_sWopiSrcName = 'WOPISrc';
var c_sUserSessionIdName = 'usid';

//files type for Saving & DownloadAs
var c_oAscFileType = {
Expand Down Expand Up @@ -4493,6 +4494,7 @@ window.AscCommon.g_cIsBeta = "false";
window['Asc']['c_sNativeViewerFormats'] = window['Asc'].c_sNativeViewerFormats = c_sNativeViewerFormats;
window['Asc']['c_sShardKeyName'] = window['Asc'].c_sShardKeyName = c_sShardKeyName;
window['Asc']['c_sWopiSrcName'] = window['Asc'].c_sWopiSrcName = c_sWopiSrcName;
window['Asc']['c_sUserSessionIdName'] = window['Asc'].c_sUserSessionIdName = c_sUserSessionIdName;
window['Asc']['c_oAscFileType'] = window['Asc'].c_oAscFileType = c_oAscFileType;
window['Asc'].g_oLcidNameToIdMap = g_oLcidNameToIdMap;
window['Asc'].availableIdeographLanguages = availableIdeographLanguages;
Expand Down
11 changes: 7 additions & 4 deletions common/docscoapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
this._onlineWork = false;
}

CDocsCoApi.prototype.init = function(user, docid, documentCallbackUrl, token, editorType, documentFormatSave, docInfo, shardKey, wopiSrc, openCmd) {
CDocsCoApi.prototype.init = function(user, docid, documentCallbackUrl, token, editorType, documentFormatSave, docInfo, shardKey, wopiSrc, userSessionId, openCmd) {
if (this._CoAuthoringApi && this._CoAuthoringApi.isRightURL()) {
var t = this;
this._CoAuthoringApi.onAuthParticipantsChanged = function(e, id) {
Expand Down Expand Up @@ -145,7 +145,7 @@
t.callback_OnLicenseChanged(res);
};

this._CoAuthoringApi.init(user, docid, documentCallbackUrl, token, editorType, documentFormatSave, docInfo, shardKey, wopiSrc, openCmd);
this._CoAuthoringApi.init(user, docid, documentCallbackUrl, token, editorType, documentFormatSave, docInfo, shardKey, wopiSrc, userSessionId, openCmd);
this._onlineWork = true;
} else {
// Фиктивные вызовы
Expand Down Expand Up @@ -1641,7 +1641,7 @@
this._authOtherChanges = [];
};

DocsCoApi.prototype.init = function(user, docid, documentCallbackUrl, token, editorType, documentFormatSave, docInfo, shardKey, wopiSrc, openCmd) {
DocsCoApi.prototype.init = function(user, docid, documentCallbackUrl, token, editorType, documentFormatSave, docInfo, shardKey, wopiSrc, userSessionId, openCmd) {
this._user = user;
this._docid = null;
this._documentCallbackUrl = documentCallbackUrl;
Expand All @@ -1662,7 +1662,7 @@
this.IsAnonymousUser = docInfo.get_IsAnonymousUser();
this.coEditingMode = docInfo.asc_getCoEditingMode();
this.shardKey = shardKey;
this.wopiSrc = wopiSrc;
this.userSessionId = userSessionId;

this.setDocId(docid);
this._initSocksJs();
Expand Down Expand Up @@ -1796,6 +1796,9 @@
if (this.wopiSrc) {
options["query"][Asc.c_sWopiSrcName] = this.wopiSrc;
}
if (this.userSessionId) {
options["query"][Asc.c_sUserSessionIdName] = this.userSessionId;
}

if (window['IS_NATIVE_EDITOR']) {
socket = this.sockjs = new CNativeSocket(options);
Expand Down
27 changes: 21 additions & 6 deletions common/editorscommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,9 @@
if (editor.documentWopiSrc) {
url += '&' + Asc.c_sWopiSrcName + '=' + encodeURIComponent(editor.documentWopiSrc);
}
if (editor.documentUserSessionId) {
url += '&' + Asc.c_sUserSessionIdName + '=' + encodeURIComponent(editor.documentUserSessionId);
}
asc_ajax({
type: 'POST',
url: url,
Expand All @@ -994,7 +997,7 @@
});
}

function sendSaveFile(docId, userId, title, jwt, shardKey, wopiSrc, data, fError, fsuccess)
function sendSaveFile(docId, userId, title, jwt, shardKey, wopiSrc, userSessionId, data, fError, fsuccess)
{
let cmd = {'id': docId, "userid": userId, "tokenSession": jwt, 'outputpath': title};
let url =sSaveFileLocalUrl + '/' + docId;
Expand All @@ -1005,6 +1008,9 @@
if (wopiSrc) {
url += '&' + Asc.c_sWopiSrcName + '=' + encodeURIComponent(wopiSrc);
}
if (userSessionId) {
url += '&' + Asc.c_sUserSessionIdName + '=' + encodeURIComponent(userSessionId);
}
asc_ajax({
type: 'POST',
url: url,
Expand Down Expand Up @@ -2214,7 +2220,7 @@
return false;
}
}
function ShowImageFileDialog(documentId, documentUserId, jwt, shardKey, wopiSrc, callback, callbackOld)
function ShowImageFileDialog(documentId, documentUserId, jwt, shardKey, wopiSrc, userSessionId, callback, callbackOld)
{
if (false === _ShowFileDialog(getAcceptByArray(c_oAscImageUploadProp.SupportedFormats), true, true, ValidateUploadImage, callback)) {
//todo remove this compatibility
Expand All @@ -2227,6 +2233,9 @@
if (wopiSrc) {
queryParams.push(Asc.c_sWopiSrcName + '=' + encodeURIComponent(wopiSrc));
}
if (userSessionId) {
queryParams.push(Asc.c_sUserSessionIdName + '=' + encodeURIComponent(userSessionId));
}
if (jwt) {
queryParams.push('token=' + encodeURIComponent(jwt));
}
Expand Down Expand Up @@ -2440,7 +2449,7 @@
callback(nError, [file], obj);
}

function UploadImageFiles(files, documentId, documentUserId, jwt, shardKey, wopiSrc, callback)
function UploadImageFiles(files, documentId, documentUserId, jwt, shardKey, wopiSrc, userSessionId, callback)
{
if (files.length > 0)
{
Expand All @@ -2452,6 +2461,9 @@
if (wopiSrc) {
queryParams.push(Asc.c_sWopiSrcName + '=' + encodeURIComponent(wopiSrc));
}
if (userSessionId) {
queryParams.push(Asc.c_sUserSessionIdName + '=' + encodeURIComponent(userSessionId));
}
if (queryParams.length > 0) {
url += '?' + queryParams.join('&');
}
Expand Down Expand Up @@ -2513,7 +2525,7 @@
}
}

function UploadImageUrls(files, documentId, documentUserId, jwt, shardKey, wopiSrc, callback)
function UploadImageUrls(files, documentId, documentUserId, jwt, shardKey, wopiSrc, userSessionId, callback)
{
if (files.length > 0)
{
Expand All @@ -2525,6 +2537,9 @@
if (wopiSrc) {
queryParams.push(Asc.c_sWopiSrcName + '=' + encodeURIComponent(wopiSrc));
}
if (userSessionId) {
queryParams.push(Asc.c_sUserSessionIdName + '=' + encodeURIComponent(userSessionId));
}
if (queryParams.length > 0) {
url += '?' + queryParams.join('&');
}
Expand Down Expand Up @@ -11418,7 +11433,7 @@
obj.options.callback(Asc.c_oAscError.ID.No, data);
else
{
AscCommon.UploadImageUrls(data, obj.options.api.documentId, obj.options.api.documentUserId, obj.options.api.CoAuthoringApi.get_jwt(), obj.options.api.documentShardKey, obj.options.api.documentWopiSrc, function(urls)
AscCommon.UploadImageUrls(data, obj.options.api.documentId, obj.options.api.documentUserId, obj.options.api.CoAuthoringApi.get_jwt(), obj.options.api.documentShardKey, obj.options.api.documentWopiSrc, obj.options.api.documentUserSessionId, function(urls)
{
obj.options.api.sync_EndAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.UploadImage);

Expand Down Expand Up @@ -14305,7 +14320,7 @@ window["buildCryptoFile_End"] = function(url, error, hash, password)
ext = ".docxf";
}

AscCommon.sendSaveFile(_editor.documentId, _editor.documentUserId, "output" + ext, _editor.asc_getSessionToken(), _editor.documentShardKey, _editor.documentWopiSrc, fileData, function(err) {
AscCommon.sendSaveFile(_editor.documentId, _editor.documentUserId, "output" + ext, _editor.asc_getSessionToken(), _editor.documentShardKey, _editor.documentWopiSrc, _editor.documentUserSessionId, fileData, function(err) {

_editor.sync_EndAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.Save);
_editor.sendEvent("asc_onError", Asc.c_oAscError.ID.ConvertationSaveError, Asc.c_oAscError.Level.Critical);
Expand Down
2 changes: 1 addition & 1 deletion pdf/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@
if (this.WordControl) // после показа диалога может не прийти mouseUp
this.WordControl.m_bIsMouseLock = false;

AscCommon.ShowImageFileDialog(this.documentId, this.documentUserId, this.CoAuthoringApi.get_jwt(), this.documentShardKey, this.documentWopiSrc, function(error, files)
AscCommon.ShowImageFileDialog(this.documentId, this.documentUserId, this.CoAuthoringApi.get_jwt(), this.documentShardKey, this.documentWopiSrc, this.documentUserSessionId, function(error, files)
{
// ошибка может быть объектом в случае отмены добавления картинки в форму
if (typeof(error) == "object")
Expand Down
2 changes: 1 addition & 1 deletion pdf/src/forms/pushbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@
});
}
else {
AscCommon.ShowImageFileDialog(Api.documentId, Api.documentUserId, undefined, Api.documentShardKey, Api.documentWopiSrc, function(error, files)
AscCommon.ShowImageFileDialog(Api.documentId, Api.documentUserId, undefined, Api.documentShardKey, Api.documentWopiSrc, Api.documentUserSessionId, function(error, files)
{
if (error.canceled == true) {
let oDoc = oThis.GetDocument();
Expand Down
4 changes: 2 additions & 2 deletions word/apiCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@
}
var t = this.Api;
var _this = this;
AscCommon.ShowImageFileDialog(t.documentId, t.documentUserId, t.CoAuthoringApi.get_jwt(), t.documentShardKey, t.documentWopiSrc, function(error, files)
AscCommon.ShowImageFileDialog(t.documentId, t.documentUserId, t.CoAuthoringApi.get_jwt(), t.documentShardKey, t.documentWopiSrc, t.documentUserSessionId, function(error, files)
{
if (Asc.c_oAscError.ID.No !== error)
{
Expand All @@ -2187,7 +2187,7 @@
else
{
t.sync_StartAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.UploadImage);
AscCommon.UploadImageFiles(files, t.documentId, t.documentUserId, t.CoAuthoringApi.get_jwt(), t.documentShardKey, t.documentWopiSrc, function(error, urls)
AscCommon.UploadImageFiles(files, t.documentId, t.documentUserId, t.CoAuthoringApi.get_jwt(), t.documentShardKey, t.documentWopiSrc, t.documentUserSessionId, function(error, urls)
{
if (Asc.c_oAscError.ID.No !== error)
{
Expand Down

0 comments on commit 362d506

Please sign in to comment.