[fix] Add tenant support for static router; Fix bug 79463

This commit is contained in:
PauI Ostrovckij
2026-01-29 08:03:11 +03:00
parent 90601ac670
commit f422402b45

View File

@ -83,6 +83,11 @@ function createCacheMiddleware(prefix, rootPath, cfgStorage, secret, rout) {
} }
try { try {
const ctx = new operationContext.Context();
ctx.initFromRequest(req);
await ctx.initTenantCache();
const tenantStorageCfg = ctx.getCfg('storage', cfgStorage);
const urlParsed = urlModule.parse(req.url, true); const urlParsed = urlModule.parse(req.url, true);
const {md5, expires} = urlParsed.query; const {md5, expires} = urlParsed.query;
const numericExpires = parseInt(expires); const numericExpires = parseInt(expires);
@ -111,7 +116,7 @@ function createCacheMiddleware(prefix, rootPath, cfgStorage, secret, rout) {
const filename = urlParsed.pathname && decodeURIComponent(path.basename(urlParsed.pathname)); const filename = urlParsed.pathname && decodeURIComponent(path.basename(urlParsed.pathname));
let filePath = decodeURI(req.url.substring(1, index)); let filePath = decodeURI(req.url.substring(1, index));
if (cfgStorage.name === 'storage-fs') { if (tenantStorageCfg.name === 'storage-fs') {
const sendFileOptions = { const sendFileOptions = {
root: rootPath, root: rootPath,
dotfiles: 'deny', dotfiles: 'deny',
@ -127,10 +132,7 @@ function createCacheMiddleware(prefix, rootPath, cfgStorage, secret, rout) {
res.status(400).end(); res.status(400).end();
} }
}); });
} else if (['storage-s3', 'storage-az'].includes(cfgStorage.name)) { } else if (['storage-s3', 'storage-az'].includes(tenantStorageCfg.name)) {
const ctx = new operationContext.Context();
ctx.initFromRequest(req);
await ctx.initTenantCache();
if (tenantManager.isMultitenantMode(ctx) && filePath.startsWith(ctx.tenant + '/')) { if (tenantManager.isMultitenantMode(ctx) && filePath.startsWith(ctx.tenant + '/')) {
filePath = filePath.substring(ctx.tenant.length + 1); filePath = filePath.substring(ctx.tenant.length + 1);
} }
@ -155,7 +157,7 @@ for (const i in cfgStaticContent) {
router.use(i, express.static(cfgStaticContent[i]['path'], cfgStaticContent[i]['options'])); router.use(i, express.static(cfgStaticContent[i]['path'], cfgStaticContent[i]['options']));
} }
} }
if (storage.needServeStatic()) { if (storage.needServeStatic() || tenantManager.isMultitenantMode()) {
initCacheRouter(cfgCacheStorage, [cfgCacheStorage.cacheFolderName]); initCacheRouter(cfgCacheStorage, [cfgCacheStorage.cacheFolderName]);
} }
if (storage.needServeStatic(cfgForgottenFiles)) { if (storage.needServeStatic(cfgForgottenFiles)) {