-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
746 additions
and
771 deletions.
There are no files selected for viewing
80 changes: 0 additions & 80 deletions
80
packages/azure_file_storage/api/fileBrowser/azureFileBrowser.js
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
packages/azure_file_storage/api/fileDelete/azureFileDelete.js
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
packages/azure_file_storage/api/folderCreate/azureFolderCreate.js
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
packages/azure_file_storage/api/imageUpload/[multerFile]azureBlob.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const { addProcessor } = require('@evershop/evershop/src/lib/util/registry'); | ||
const { azureFileUploader } = require('./services/azureFileUploader'); | ||
const { azureFileDeleter } = require('./services/azureFileDeleter'); | ||
const { azureFolderCreator } = require('./services/azureFolderCreator'); | ||
const { azureFileBrowser } = require('./services/azureFileBrowser'); | ||
|
||
module.exports = () => { | ||
addProcessor('fileUploader', function (value) { | ||
const {config} = this; | ||
if (config === 'azure') { | ||
return azureFileUploader; | ||
} else { | ||
return value; | ||
} | ||
}); | ||
|
||
addProcessor('fileDeleter', function (value) { | ||
const {config} = this; | ||
if (config === 'azure') { | ||
return azureFileDeleter; | ||
} else { | ||
return value; | ||
} | ||
}); | ||
|
||
addProcessor('folderCreator', function (value) { | ||
const {config} = this; | ||
if (config === 'azure') { | ||
return azureFolderCreator; | ||
} else { | ||
return value; | ||
} | ||
}); | ||
|
||
addProcessor('fileBrowser', function (value) { | ||
const {config} = this; | ||
if (config === 'azure') { | ||
return azureFileBrowser; | ||
} else { | ||
return value; | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { BlobServiceClient } = require('@azure/storage-blob'); | ||
const { getEnv } = require('@evershop/evershop/src/lib/util/getEnv'); | ||
|
||
module.exports.azureFileBrowser = { | ||
list: async (path) => { | ||
const blobServiceClient = BlobServiceClient.fromConnectionString( | ||
getEnv('AZURE_STORAGE_CONNECTION_STRING') | ||
); | ||
const containerName = getEnv('AZURE_STORAGE_CONTAINER_NAME', 'images'); | ||
const containerClient = blobServiceClient.getContainerClient(containerName); | ||
// Create a container if it does not exist with access level set to public | ||
await containerClient.createIfNotExists({ | ||
access: 'blob' | ||
}); | ||
|
||
if (path !== '') { | ||
// eslint-disable-next-line no-param-reassign | ||
path = `${path}/`; | ||
} | ||
const blobs = containerClient.listBlobsFlat({ prefix: path }); | ||
const subfolders = new Set(); | ||
const files = []; | ||
// eslint-disable-next-line no-restricted-syntax | ||
for await (const blob of blobs) { | ||
const blobName = blob.name; | ||
const blobUrl = `${containerClient.url}/${blobName}`; | ||
const relativePath = blobName.substring(path.length); | ||
const slashIndex = relativePath.indexOf('/'); | ||
if (slashIndex === -1) { | ||
// It's a file | ||
if (blob.properties.contentLength) { | ||
files.push({ | ||
name: relativePath, | ||
url: blobUrl | ||
}); | ||
} | ||
} else { | ||
// It's a subfolder | ||
const subfolder = relativePath.substring(0, slashIndex); | ||
if (subfolder !== '') { | ||
subfolders.add(subfolder); | ||
} | ||
} | ||
} | ||
return { | ||
folders: Array.from(subfolders), | ||
files | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { BlobServiceClient } = require('@azure/storage-blob'); | ||
const { getEnv } = require('@evershop/evershop/src/lib/util/getEnv'); | ||
|
||
module.exports.azureFileDeleter = { | ||
delete: async (path) => { | ||
const blobServiceClient = BlobServiceClient.fromConnectionString( | ||
getEnv('AZURE_STORAGE_CONNECTION_STRING') | ||
); | ||
const containerName = getEnv('AZURE_STORAGE_CONTAINER_NAME', 'images'); | ||
const containerClient = blobServiceClient.getContainerClient(containerName); | ||
const blobClient = containerClient.getBlobClient(path); | ||
const blobProperties = await blobClient.getProperties(); | ||
|
||
if (blobProperties.contentType) { | ||
await blobClient.delete(); | ||
} else { | ||
throw new Error(`Path "${path}" does not exist.`); | ||
} | ||
} | ||
}; |
Oops, something went wrong.