Skip to content

Commit

Permalink
[bug] For bug 67908
Browse files Browse the repository at this point in the history
  • Loading branch information
konovalovsergey committed May 10, 2024
1 parent d8d2caa commit adc44fa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
35 changes: 20 additions & 15 deletions Common/sources/storage-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function getStoragePath(ctx, strPath, opt_specialDir) {
opt_specialDir = opt_specialDir || cfgCacheStorage.cacheFolderName;
return opt_specialDir + '/' + tenantManager.getTenantPathPrefix(ctx) + strPath.replace(/\\/g, '/');
}
function getStorage(ctx, opt_specialDir) {
function getStorage(opt_specialDir) {
return opt_specialDir ? persistentStorage : cacheStorage;
}
function getStorageCfg(ctx, opt_specialDir) {
Expand All @@ -63,40 +63,40 @@ function isDiffrentPersistentStorage() {
}

async function headObject(ctx, strPath, opt_specialDir) {
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
return await storage.headObject(storageCfg, getStoragePath(storageCfg, strPath, opt_specialDir));
}
async function getObject(ctx, strPath, opt_specialDir) {
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
return await storage.getObject(storageCfg, getStoragePath(storageCfg, strPath, opt_specialDir));
}
async function createReadStream(ctx, strPath, opt_specialDir) {
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
return await storage.createReadStream(storageCfg, getStoragePath(storageCfg, strPath, opt_specialDir));
}
async function putObject(ctx, strPath, buffer, contentLength, opt_specialDir) {
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
return await storage.putObject(storageCfg, getStoragePath(ctx, strPath, opt_specialDir), buffer, contentLength);
}
async function uploadObject(ctx, strPath, filePath, opt_specialDir) {
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
return await storage.uploadObject(storageCfg, getStoragePath(ctx, strPath, opt_specialDir), filePath);
}
async function copyObject(ctx, sourceKey, destinationKey, opt_specialDirSrc, opt_specialDirDst) {
let storageSrc = getStorage(ctx, opt_specialDirSrc);
let storageSrc = getStorage(opt_specialDirSrc);
let storagePathSrc = getStoragePath(ctx, sourceKey, opt_specialDirSrc);
let storagePathDst = getStoragePath(ctx, destinationKey, opt_specialDirDst);
let storageCfgSrc = getStorageCfg(ctx, opt_specialDirSrc);
let storageCfgDst = getStorageCfg(ctx, opt_specialDirDst);
if (canCopyBetweenStorage(storageCfgSrc, storageCfgDst)){
return await storageSrc.copyObject(storageCfgSrc, storageCfgDst, storagePathSrc, storagePathDst);
} else {
let storageDst = getStorage(ctx, opt_specialDirDst);
let storageDst = getStorage(opt_specialDirDst);
//todo stream
let buffer = await storageSrc.getObject(storageCfgSrc, storagePathSrc);
return await storageDst.putObject(storageCfgDst, storagePathDst, buffer, buffer.length);
Expand All @@ -109,7 +109,7 @@ async function copyPath(ctx, sourcePath, destinationPath, opt_specialDirSrc, opt
}));
}
async function listObjects(ctx, strPath, opt_specialDir) {
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
let prefix = getStoragePath(ctx, "", opt_specialDir);
try {
Expand All @@ -123,23 +123,23 @@ async function listObjects(ctx, strPath, opt_specialDir) {
}
}
async function deleteObject(ctx, strPath, opt_specialDir) {
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
return await storage.deleteObject(storageCfg, getStoragePath(ctx, strPath, opt_specialDir));
}
async function deletePath(ctx, strPath, opt_specialDir) {
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
return await storage.deletePath(storageCfg, getStoragePath(ctx, strPath, opt_specialDir));
}
async function getSignedUrl(ctx, baseUrl, strPath, urlType, optFilename, opt_creationDate, opt_specialDir) {
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
return await storage.getSignedUrl(ctx, storageCfg, baseUrl, getStoragePath(ctx, strPath, opt_specialDir), urlType, optFilename, opt_creationDate);
}
async function getSignedUrls(ctx, baseUrl, strPath, urlType, opt_creationDate, opt_specialDir) {
let storagePathSrc = getStoragePath(ctx, strPath, opt_specialDir);
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
let list = await storage.listObjects(storageCfg, storagePathSrc, storageCfg);
let urls = await Promise.all(list.map(function(curValue) {
Expand All @@ -153,7 +153,7 @@ async function getSignedUrls(ctx, baseUrl, strPath, urlType, opt_creationDate, o
}
async function getSignedUrlsArrayByArray(ctx, baseUrl, list, urlType, opt_specialDir) {
return await Promise.all(list.map(function (curValue) {
let storage = getStorage(ctx, opt_specialDir);
let storage = getStorage(opt_specialDir);
let storageCfg = getStorageCfg(ctx, opt_specialDir);
let storagePathSrc = getStoragePath(ctx, curValue, opt_specialDir);
return storage.getSignedUrl(ctx, storageCfg, baseUrl, storagePathSrc, urlType, undefined);
Expand Down Expand Up @@ -188,6 +188,10 @@ async function healthCheck(ctx, opt_specialDir) {
ctx.logger.warn('healthCheck storage(%s) error %s', opt_specialDir, err.stack);
}
}
function needServeStatic(opt_specialDir) {
let storage = getStorage(opt_specialDir);
return storage.needServeStatic();
}

module.exports = {
headObject,
Expand All @@ -206,5 +210,6 @@ module.exports = {
getSignedUrlsByArray,
getRelativePath,
isDiffrentPersistentStorage,
healthCheck
healthCheck,
needServeStatic
};
7 changes: 6 additions & 1 deletion Common/sources/storage-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ async function getSignedUrl(ctx, storageCfg, baseUrl, strPath, urlType, optFilen
return url;
}

function needServeStatic() {
return true;
}

module.exports = {
headObject,
getObject,
Expand All @@ -161,5 +165,6 @@ module.exports = {
listObjects,
deleteObject,
deletePath,
getSignedUrl
getSignedUrl,
needServeStatic
};
7 changes: 6 additions & 1 deletion Common/sources/storage-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ async function getSignedUrlWrapper(ctx, storageCfg, baseUrl, strPath, urlType, o
// return utils.changeOnlyOfficeUrl(url, strPath, optFilename);
}

function needServeStatic() {
return false;
}

module.exports = {
headObject,
getObject,
Expand All @@ -246,5 +250,6 @@ module.exports = {
listObjects,
deleteObject,
deletePath,
getSignedUrl: getSignedUrlWrapper
getSignedUrl: getSignedUrlWrapper,
needServeStatic
};
5 changes: 3 additions & 2 deletions DocService/sources/routes/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const express = require('express');
const config = require("config");
const operationContext = require('./../../../Common/sources/operationContext');
const utils = require('./../../../Common/sources/utils');
const storage = require('./../../../Common/sources/storage-base');
const urlModule = require("url");
const path = require("path");
const mime = require("mime");
Expand Down Expand Up @@ -85,10 +86,10 @@ for (let i in cfgStaticContent) {
router.use(i, express.static(cfgStaticContent[i]['path'], cfgStaticContent[i]['options']));
}
}
if (cfgCacheStorage.name === "storage-fs") {
if (storage.needServeStatic()) {
initCacheRouter(cfgCacheStorage, [cfgCacheStorage.cacheFolderName]);
}
if (cfgPersistentStorage.name === "storage-fs") {
if (storage.needServeStatic(cfgForgottenFiles)) {
let persistentRouts = [cfgForgottenFiles, cfgErrorFiles];
persistentRouts.filter((rout) => {return rout && rout.length > 0;});
if (persistentRouts.length > 0) {
Expand Down

0 comments on commit adc44fa

Please sign in to comment.