Skip to content

Commit

Permalink
Cloud storage for assets #256
Browse files Browse the repository at this point in the history
  • Loading branch information
treoden committed Nov 2, 2023
1 parent 0d0a6bf commit 4207bdd
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 16 deletions.
5 changes: 4 additions & 1 deletion packages/azure_file_storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ Edit the `config/default.json` file in the root directory of your EverShop insta
```json
{
...,
"file_storage": "azure"
"system": {
...,
"file_storage": "azure"
}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {

let blobServiceClient;
let containerName;
if (getConfig('file_storage') === 'azure') {
if (getConfig('system.file_storage') === 'azure') {
blobServiceClient = BlobServiceClient.fromConnectionString(
getEnv('AZURE_STORAGE_CONNECTION_STRING')
);
Expand All @@ -18,7 +18,7 @@ if (getConfig('file_storage') === 'azure') {

module.exports = async (request, response, delegate, next) => {
// If the file storage is not Azure, call the next middleware function
if (getConfig('file_storage') !== 'azure') {
if (getConfig('system.file_storage') !== 'azure') {
next();
} else {
try {
Expand Down
4 changes: 2 additions & 2 deletions packages/azure_file_storage/api/fileDelete/azureFileDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const {

let blobServiceClient;
let containerName;
if (getConfig('file_storage') === 'azure') {
if (getConfig('system.file_storage') === 'azure') {
blobServiceClient = BlobServiceClient.fromConnectionString(
getEnv('AZURE_STORAGE_CONNECTION_STRING')
);
containerName = getEnv('AZURE_STORAGE_CONTAINER_NAME', 'images');
}

module.exports = async (request, response, delegate, next) => {
if (getConfig('file_storage') !== 'azure') {
if (getConfig('system.file_storage') !== 'azure') {
next();
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {

let blobServiceClient;
let containerName;
if (getConfig('file_storage') === 'azure') {
if (getConfig('system.file_storage') === 'azure') {
blobServiceClient = BlobServiceClient.fromConnectionString(
getEnv('AZURE_STORAGE_CONNECTION_STRING')
);
Expand All @@ -19,7 +19,7 @@ if (getConfig('file_storage') === 'azure') {

module.exports = async (request, response, delegate, next) => {
// If the file storage is not Azure, call the next middleware function
if (getConfig('file_storage') !== 'azure') {
if (getConfig('system.file_storage') !== 'azure') {
next();
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { CONSTANTS } = require('@evershop/evershop/src/lib/helpers');
const { debug } = require('@evershop/evershop/src/lib/log/debuger');

module.exports = async function localGenerateProductImageVariant(data) {
if (getConfig('file_storage') === 'local') {
if (getConfig('system.file_storage') === 'local') {
try {
const imagePath = data.origin_image.replace('/assets', '');
const mediaPath = path.join(CONSTANTS.MEDIAPATH, imagePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig');

// eslint-disable-next-line no-unused-vars
module.exports = (request, response, delegate, next) => {
if (getConfig('file_storage') !== 'local') {
if (getConfig('system.file_storage') !== 'local') {
next();
} else {
const path = request.params[0] || '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig');

// eslint-disable-next-line no-unused-vars
module.exports = (request, response, delegate, next) => {
if (getConfig('file_storage') !== 'local') {
if (getConfig('system.file_storage') !== 'local') {
next();
} else {
const path = request.params[0] || '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig');

// eslint-disable-next-line no-unused-vars
module.exports = (request, response, delegate, next) => {
if (getConfig('file_storage') !== 'local') {
if (getConfig('system.file_storage') !== 'local') {
next();
} else {
const { path } = request.body || '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { getConfig } = require('@evershop/evershop/src/lib/util/getConfig');

// eslint-disable-next-line no-unused-vars
module.exports = (request, response, delegate, next) => {
if (getConfig('file_storage') !== 'local') {
if (getConfig('system.file_storage') !== 'local') {
next();
} else if (!request.files || request.files.length === 0) {
response.status(INVALID_PAYLOAD).json({
Expand Down
3 changes: 3 additions & 0 deletions packages/evershop/src/modules/cms/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ module.exports = () => {
copyRight: `© 2022 Evershop. All Rights Reserved.`
};
config.util.setModuleDefaults('themeConfig', themeConfig);
config.util.setModuleDefaults('system', {
file_storage: 'local'
});
};
3 changes: 1 addition & 2 deletions packages/evershop/src/modules/cms/services/getMulter.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ const diskStorage = multer.diskStorage({
});

module.exports.getMulter = () => {
const storageProvider = getConfig('file_storage', 'local');

const storageProvider = getConfig('system.file_storage', 'local');
if (storageProvider === 'local') {
return multer({ storage: diskStorage, fileFilter });
} else {
Expand Down
5 changes: 4 additions & 1 deletion packages/s3_file_storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ Edit the `config/default.json` file in the root directory of your EverShop insta
```json
{
...,
"file_storage": "s3"
"system": {
...,
"file_storage": "s3"
}
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const bucketName = getEnv('AWS_BUCKET_NAME');

module.exports = async (request, response, delegate, next) => {
// If the file storage is not S3, call the next middleware function
if (getConfig('file_storage') !== 's3') {
if (getConfig('system.file_storage') !== 's3') {
next();
} else {
try {
Expand Down

0 comments on commit 4207bdd

Please sign in to comment.