mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-04-07 14:04:35 +08:00
[feature] Use WOPISrc param to make local urls
# Conflicts: # Common/sources/storage-fs.js # DocService/sources/DocsCoServer.js # DocService/sources/connectorUtilities.js # DocService/sources/gc.js
This commit is contained in:
@ -50,6 +50,7 @@ exports.VIEWER_ONLY = /^(?:(pdf|djvu|xps|oxps))$/;
|
||||
exports.DEFAULT_DOC_ID = 'docId';
|
||||
exports.DEFAULT_USER_ID = 'userId';
|
||||
exports.ALLOWED_PROTO = /^https?$/i;
|
||||
exports.SHARED_KEY_NAME = 'WOPISrc';
|
||||
|
||||
exports.RIGHTS = {
|
||||
None : 0,
|
||||
|
||||
@ -41,17 +41,18 @@ function Context(){
|
||||
this.logger = logger.getLogger('nodeJS');
|
||||
this.initDefault();
|
||||
}
|
||||
Context.prototype.init = function(tenant, docId, userId) {
|
||||
Context.prototype.init = function(tenant, docId, userId, opt_shardKey) {
|
||||
this.setTenant(tenant);
|
||||
this.setDocId(docId);
|
||||
this.setUserId(userId);
|
||||
this.setShardKey(opt_shardKey);
|
||||
|
||||
this.config = null;
|
||||
this.secret = null;
|
||||
this.license = null;
|
||||
};
|
||||
Context.prototype.initDefault = function() {
|
||||
this.init(tenantManager.getDefautTenant(), constants.DEFAULT_DOC_ID, constants.DEFAULT_USER_ID);
|
||||
this.init(tenantManager.getDefautTenant(), constants.DEFAULT_DOC_ID, constants.DEFAULT_USER_ID, undefined);
|
||||
};
|
||||
Context.prototype.initFromConnection = function(conn) {
|
||||
let tenant = tenantManager.getTenantByConnection(this, conn);
|
||||
@ -64,19 +65,21 @@ Context.prototype.initFromConnection = function(conn) {
|
||||
}
|
||||
}
|
||||
let userId = conn.user?.id;
|
||||
this.init(tenant, docId || this.docId, userId || this.userId);
|
||||
let shardKey = utils.getShardByConnection(this, conn);
|
||||
this.init(tenant, docId || this.docId, userId || this.userId, shardKey);
|
||||
};
|
||||
Context.prototype.initFromRequest = function(req) {
|
||||
let tenant = tenantManager.getTenantByRequest(this, req);
|
||||
this.init(tenant, this.docId, this.userId);
|
||||
let shardKey = utils.getShardKeyByRequest(this, req);
|
||||
this.init(tenant, this.docId, this.userId, shardKey);
|
||||
};
|
||||
Context.prototype.initFromTaskQueueData = function(task) {
|
||||
let ctx = task.getCtx();
|
||||
this.init(ctx.tenant, ctx.docId, ctx.userId);
|
||||
this.init(ctx.tenant, ctx.docId, ctx.userId, ctx.shardKey);
|
||||
};
|
||||
Context.prototype.initFromPubSub = function(data) {
|
||||
let ctx = data.ctx;
|
||||
this.init(ctx.tenant, ctx.docId, ctx.userId);
|
||||
this.init(ctx.tenant, ctx.docId, ctx.userId, ctx.shardKey);
|
||||
};
|
||||
Context.prototype.initTenantCache = async function() {
|
||||
this.config = await tenantManager.getTenantConfig(this);
|
||||
@ -95,11 +98,15 @@ Context.prototype.setUserId = function(userId) {
|
||||
this.userId = userId;
|
||||
this.logger.addContext('USERID', userId);
|
||||
};
|
||||
Context.prototype.setShardKey = function(shardKey) {
|
||||
this.shardKey = shardKey;
|
||||
};
|
||||
Context.prototype.toJSON = function() {
|
||||
return {
|
||||
tenant: this.tenant,
|
||||
docId: this.docId,
|
||||
userId: this.userId
|
||||
userId: this.userId,
|
||||
shardKey: this.shardKey
|
||||
}
|
||||
};
|
||||
Context.prototype.getCfg = function(property, defaultValue) {
|
||||
|
||||
@ -40,6 +40,7 @@ var utils = require("./utils");
|
||||
var crypto = require('crypto');
|
||||
const ms = require('ms');
|
||||
const commonDefines = require('./../../Common/sources/commondefines');
|
||||
const constants = require('./../../Common/sources/constants');
|
||||
|
||||
var config = require('config');
|
||||
var configStorage = config.get('storage');
|
||||
@ -202,6 +203,9 @@ exports.getSignedUrl = function(ctx, baseUrl, strPath, urlType, optFilename, opt
|
||||
|
||||
url += '?md5=' + encodeURIComponent(md5);
|
||||
url += '&expires=' + encodeURIComponent(expires);
|
||||
if (ctx.shardKey) {
|
||||
url += `&${constants.SHARED_KEY_NAME}=${encodeURIComponent(ctx.shardKey)}`;
|
||||
}
|
||||
url += '&filename=' + userFriendlyName;
|
||||
resolve(url);
|
||||
});
|
||||
|
||||
@ -731,6 +731,14 @@ function getDomainByRequest(ctx, req) {
|
||||
}
|
||||
exports.getDomainByConnection = getDomainByConnection;
|
||||
exports.getDomainByRequest = getDomainByRequest;
|
||||
function getShardByConnection(ctx, conn) {
|
||||
return conn?.handshake?.query?.[constants.SHARED_KEY_NAME];
|
||||
}
|
||||
function getShardKeyByRequest(ctx, req) {
|
||||
return req.query[constants.SHARED_KEY_NAME];
|
||||
}
|
||||
exports.getShardByConnection = getShardByConnection;
|
||||
exports.getShardKeyByRequest = getShardKeyByRequest;
|
||||
function stream2Buffer(stream) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (!stream.readable) {
|
||||
|
||||
Reference in New Issue
Block a user