@payloadcms/storage-azure 3.0.0-alpha.69 → 3.0.0-beta.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/generateURL.js.map +1 -1
- package/dist/handleDelete.d.ts +1 -1
- package/dist/handleDelete.d.ts.map +1 -1
- package/dist/handleDelete.js.map +1 -1
- package/dist/handleUpload.d.ts +1 -1
- package/dist/handleUpload.d.ts.map +1 -1
- package/dist/handleUpload.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/staticHandler.d.ts +1 -1
- package/dist/staticHandler.d.ts.map +1 -1
- package/dist/staticHandler.js +0 -1
- package/dist/staticHandler.js.map +1 -1
- package/dist/utils/getRangeFromHeader.d.ts.map +1 -1
- package/dist/utils/getRangeFromHeader.js.map +1 -1
- package/dist/utils/getStorageClient.d.ts +4 -0
- package/dist/utils/getStorageClient.d.ts.map +1 -0
- package/dist/utils/getStorageClient.js +13 -0
- package/dist/utils/getStorageClient.js.map +1 -0
- package/package.json +12 -10
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ pnpm add @payloadcms/storage-azure
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
- Configure the `collections` object to specify which collections should use the
|
|
15
|
+
- Configure the `collections` object to specify which collections should use the Azure Blob Storage adapter. The slug _must_ match one of your existing collection slugs.
|
|
16
16
|
- When enabled, this package will automatically set `disableLocalStorage` to `true` for each collection.
|
|
17
17
|
|
|
18
18
|
```ts
|
package/dist/generateURL.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ninterface Args {\n baseURL: string\n containerName: string\n}\n\nexport const getGenerateURL =\n ({ baseURL, containerName }: Args): GenerateURL =>\n ({ filename, prefix = '' }) => {\n return `${baseURL}/${containerName}/${path.posix.join(prefix, filename)}`\n }\n"],"names":["path","getGenerateURL","baseURL","containerName","filename","prefix","posix","join"],"
|
|
1
|
+
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ninterface Args {\n baseURL: string\n containerName: string\n}\n\nexport const getGenerateURL =\n ({ baseURL, containerName }: Args): GenerateURL =>\n ({ filename, prefix = '' }) => {\n return `${baseURL}/${containerName}/${path.posix.join(prefix, filename)}`\n }\n"],"names":["path","getGenerateURL","baseURL","containerName","filename","prefix","posix","join"],"mappings":"AAEA,OAAOA,UAAU,OAAM;AAOvB,OAAO,MAAMC,iBACX,CAAC,EAAEC,OAAO,EAAEC,aAAa,EAAQ,GACjC,CAAC,EAAEC,QAAQ,EAAEC,SAAS,EAAE,EAAE;QACxB,OAAO,CAAC,EAAEH,QAAQ,CAAC,EAAEC,cAAc,CAAC,EAAEH,KAAKM,KAAK,CAACC,IAAI,CAACF,QAAQD,UAAU,CAAC;IAC3E,EAAC"}
|
package/dist/handleDelete.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ContainerClient } from '@azure/storage-blob';
|
|
2
2
|
import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types';
|
|
3
|
-
import type { CollectionConfig } from 'payload
|
|
3
|
+
import type { CollectionConfig } from 'payload';
|
|
4
4
|
interface Args {
|
|
5
5
|
collection: CollectionConfig;
|
|
6
6
|
getStorageClient: () => ContainerClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleDelete.d.ts","sourceRoot":"","sources":["../src/handleDelete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"handleDelete.d.ts","sourceRoot":"","sources":["../src/handleDelete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI/C,UAAU,IAAI;IACZ,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,EAAE,MAAM,eAAe,CAAA;CACxC;AAED,eAAO,MAAM,eAAe,yBAA0B,IAAI,KAAG,YAK5D,CAAA"}
|
package/dist/handleDelete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport path from 'path'\n\ninterface Args {\n collection: CollectionConfig\n getStorageClient: () => ContainerClient\n}\n\nexport const getHandleDelete = ({ getStorageClient }: Args): HandleDelete => {\n return async ({ doc: { prefix = '' }, filename }) => {\n const blockBlobClient = getStorageClient().getBlockBlobClient(path.posix.join(prefix, filename))\n await blockBlobClient.deleteIfExists()\n }\n}\n"],"names":["path","getHandleDelete","getStorageClient","doc","prefix","filename","blockBlobClient","getBlockBlobClient","posix","join","deleteIfExists"],"mappings":"AAIA,OAAOA,UAAU,OAAM;AAOvB,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,gBAAgB,EAAQ;IACxD,OAAO,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAE,EAAE,EAAEC,QAAQ,EAAE;QAC9C,MAAMC,kBAAkBJ,mBAAmBK,kBAAkB,CAACP,KAAKQ,KAAK,CAACC,IAAI,CAACL,QAAQC;QACtF,MAAMC,gBAAgBI,cAAc;IACtC;AACF,EAAC"}
|
package/dist/handleUpload.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ContainerClient } from '@azure/storage-blob';
|
|
2
2
|
import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types';
|
|
3
|
-
import type { CollectionConfig } from 'payload
|
|
3
|
+
import type { CollectionConfig } from 'payload';
|
|
4
4
|
interface Args {
|
|
5
5
|
collection: CollectionConfig;
|
|
6
6
|
getStorageClient: () => ContainerClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAO/C,UAAU,IAAI;IACZ,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,EAAE,MAAM,eAAe,CAAA;IACvC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAGD,eAAO,MAAM,eAAe,iCAAuC,IAAI,KAAG,YAyBzE,CAAA"}
|
package/dist/handleUpload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { AbortController } from '@azure/abort-controller'\nimport fs from 'fs'\nimport path from 'path'\nimport { Readable } from 'stream'\n\ninterface Args {\n collection: CollectionConfig\n getStorageClient: () => ContainerClient\n prefix?: string\n}\n\nconst multipartThreshold = 1024 * 1024 * 50 // 50MB\nexport const getHandleUpload = ({ getStorageClient, prefix = '' }: Args): HandleUpload => {\n return async ({ data, file }) => {\n const fileKey = path.posix.join(data.prefix || prefix, file.filename)\n\n const blockBlobClient = getStorageClient().getBlockBlobClient(fileKey)\n\n // when there are no temp files, or the upload is less than the threshold size, do not stream files\n if (!file.tempFilePath && file.buffer.length > 0 && file.buffer.length < multipartThreshold) {\n await blockBlobClient.upload(file.buffer, file.buffer.byteLength, {\n blobHTTPHeaders: { blobContentType: file.mimeType },\n })\n\n return data\n }\n\n const fileBufferOrStream: Readable = file.tempFilePath\n ? fs.createReadStream(file.tempFilePath)\n : Readable.from(file.buffer)\n\n await blockBlobClient.uploadStream(fileBufferOrStream, 4 * 1024 * 1024, 4, {\n abortSignal: AbortController.timeout(30 * 60 * 1000),\n })\n\n return data\n }\n}\n"],"names":["AbortController","fs","path","Readable","multipartThreshold","getHandleUpload","getStorageClient","prefix","data","file","fileKey","posix","join","filename","blockBlobClient","getBlockBlobClient","tempFilePath","buffer","length","upload","byteLength","blobHTTPHeaders","blobContentType","mimeType","fileBufferOrStream","createReadStream","from","uploadStream","abortSignal","timeout"],"mappings":"AAIA,SAASA,eAAe,QAAQ,0BAAyB;AACzD,OAAOC,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,QAAQ,QAAQ,SAAQ;AAQjC,MAAMC,qBAAqB,OAAO,OAAO,GAAG,OAAO;;AACnD,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,gBAAgB,EAAEC,SAAS,EAAE,EAAQ;IACrE,OAAO,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAE;QAC1B,MAAMC,UAAUR,KAAKS,KAAK,CAACC,IAAI,CAACJ,KAAKD,MAAM,IAAIA,QAAQE,KAAKI,QAAQ;QAEpE,MAAMC,kBAAkBR,mBAAmBS,kBAAkB,CAACL;QAE9D,mGAAmG;QACnG,IAAI,CAACD,KAAKO,YAAY,IAAIP,KAAKQ,MAAM,CAACC,MAAM,GAAG,KAAKT,KAAKQ,MAAM,CAACC,MAAM,GAAGd,oBAAoB;YAC3F,MAAMU,gBAAgBK,MAAM,CAACV,KAAKQ,MAAM,EAAER,KAAKQ,MAAM,CAACG,UAAU,EAAE;gBAChEC,iBAAiB;oBAAEC,iBAAiBb,KAAKc,QAAQ;gBAAC;YACpD;YAEA,OAAOf;QACT;QAEA,MAAMgB,qBAA+Bf,KAAKO,YAAY,GAClDf,GAAGwB,gBAAgB,CAAChB,KAAKO,YAAY,IACrCb,SAASuB,IAAI,CAACjB,KAAKQ,MAAM;QAE7B,MAAMH,gBAAgBa,YAAY,CAACH,oBAAoB,IAAI,OAAO,MAAM,GAAG;YACzEI,aAAa5B,gBAAgB6B,OAAO,CAAC,KAAK,KAAK;QACjD;QAEA,OAAOrB;IACT;AACF,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
-
import type { Plugin } from 'payload
|
|
2
|
+
import type { Plugin } from 'payload';
|
|
3
|
+
import { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js';
|
|
3
4
|
export type AzureStorageOptions = {
|
|
4
5
|
/**
|
|
5
6
|
* Whether or not to allow the container to be created if it does not exist
|
|
@@ -32,5 +33,5 @@ export type AzureStorageOptions = {
|
|
|
32
33
|
};
|
|
33
34
|
type AzureStoragePlugin = (azureStorageArgs: AzureStorageOptions) => Plugin;
|
|
34
35
|
export declare const azureStorage: AzureStoragePlugin;
|
|
35
|
-
export {};
|
|
36
|
+
export { getStorageClientFunc as getStorageClient };
|
|
36
37
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,SAAS,CAAA;AAQ7C,OAAO,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAEtF,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,oBAAoB,EAAE,OAAO,CAAA;IAE7B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IAEtE;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,kBAAkB,GAAG,CAAC,gBAAgB,EAAE,mBAAmB,KAAK,MAAM,CAAA;AAE3E,eAAO,MAAM,YAAY,EAAE,kBA4CxB,CAAA;AAgCH,OAAO,EAAE,oBAAoB,IAAI,gBAAgB,EAAE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { BlobServiceClient } from '@azure/storage-blob';
|
|
2
1
|
import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
|
|
3
2
|
import { getGenerateURL } from './generateURL.js';
|
|
4
3
|
import { getHandleDelete } from './handleDelete.js';
|
|
5
4
|
import { getHandleUpload } from './handleUpload.js';
|
|
6
5
|
import { getHandler } from './staticHandler.js';
|
|
6
|
+
import { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js';
|
|
7
7
|
export const azureStorage = (azureStorageOptions)=>(incomingConfig)=>{
|
|
8
8
|
if (azureStorageOptions.enabled === false) {
|
|
9
9
|
return incomingConfig;
|
|
@@ -38,18 +38,18 @@ export const azureStorage = (azureStorageOptions)=>(incomingConfig)=>{
|
|
|
38
38
|
})(config);
|
|
39
39
|
};
|
|
40
40
|
function azureStorageInternal({ allowContainerCreate, baseURL, connectionString, containerName }) {
|
|
41
|
-
let storageClient = null;
|
|
42
|
-
const getStorageClient = ()=>{
|
|
43
|
-
if (storageClient) return storageClient;
|
|
44
|
-
const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString);
|
|
45
|
-
storageClient = blobServiceClient.getContainerClient(containerName);
|
|
46
|
-
return storageClient;
|
|
47
|
-
};
|
|
48
41
|
const createContainerIfNotExists = ()=>{
|
|
49
|
-
void
|
|
42
|
+
void getStorageClientFunc({
|
|
43
|
+
connectionString,
|
|
44
|
+
containerName
|
|
45
|
+
}).createIfNotExists({
|
|
50
46
|
access: 'blob'
|
|
51
47
|
});
|
|
52
48
|
};
|
|
49
|
+
const getStorageClient = ()=>getStorageClientFunc({
|
|
50
|
+
connectionString,
|
|
51
|
+
containerName
|
|
52
|
+
});
|
|
53
53
|
return ({ collection, prefix })=>{
|
|
54
54
|
return {
|
|
55
55
|
name: 'azure',
|
|
@@ -76,5 +76,6 @@ function azureStorageInternal({ allowContainerCreate, baseURL, connectionString,
|
|
|
76
76
|
};
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
+
export { getStorageClientFunc as getStorageClient };
|
|
79
80
|
|
|
80
81
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\nimport { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js'\n\nexport type AzureStorageOptions = {\n /**\n * Whether or not to allow the container to be created if it does not exist\n *\n * @default false\n */\n allowContainerCreate: boolean\n\n /**\n * Base URL for the Azure Blob storage account\n */\n baseURL: string\n\n /**\n * Collection options to apply the Azure Blob adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n\n /**\n * Azure Blob storage connection string\n */\n connectionString: string\n\n /**\n * Azure Blob storage container name\n */\n containerName: string\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n}\n\ntype AzureStoragePlugin = (azureStorageArgs: AzureStorageOptions) => Plugin\n\nexport const azureStorage: AzureStoragePlugin =\n (azureStorageOptions: AzureStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (azureStorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = azureStorageInternal(azureStorageOptions)\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n azureStorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStoragePlugin({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction azureStorageInternal({\n allowContainerCreate,\n baseURL,\n connectionString,\n containerName,\n}: AzureStorageOptions): Adapter {\n const createContainerIfNotExists = () => {\n void getStorageClientFunc({ connectionString, containerName }).createIfNotExists({\n access: 'blob',\n })\n }\n\n const getStorageClient = () => getStorageClientFunc({ connectionString, containerName })\n\n return ({ collection, prefix }): GeneratedAdapter => {\n return {\n name: 'azure',\n generateURL: getGenerateURL({ baseURL, containerName }),\n handleDelete: getHandleDelete({ collection, getStorageClient }),\n handleUpload: getHandleUpload({\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ collection, getStorageClient }),\n ...(allowContainerCreate && { onInit: createContainerIfNotExists }),\n }\n }\n}\n\nexport { getStorageClientFunc as getStorageClient }\n"],"names":["cloudStoragePlugin","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","getStorageClient","getStorageClientFunc","azureStorage","azureStorageOptions","incomingConfig","enabled","adapter","azureStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","allowContainerCreate","baseURL","connectionString","containerName","createContainerIfNotExists","createIfNotExists","access","prefix","name","generateURL","handleDelete","handleUpload","staticHandler","onInit"],"mappings":"AAQA,SAASA,kBAAkB,QAAQ,mCAAkC;AAErE,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,oBAAoBC,oBAAoB,QAAQ,8BAA6B;AAwCtF,OAAO,MAAMC,eACX,CAACC,sBACD,CAACC;QACC,IAAID,oBAAoBE,OAAO,KAAK,OAAO;YACzC,OAAOD;QACT;QAEA,MAAME,UAAUC,qBAAqBJ;QAErC,+CAA+C;QAC/C,MAAMK,yBAAmEC,OAAOC,OAAO,CACrFP,oBAAoBQ,WAAW,EAC/BC,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CT;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMU,SAAS;YACb,GAAGZ,cAAc;YACjBO,aAAa,AAACP,CAAAA,eAAeO,WAAW,IAAI,EAAE,AAAD,EAAGM,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACV,sBAAsB,CAACU,WAAWJ,IAAI,CAAC,EAAE;oBAC5C,OAAOI;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbC,QAAQ;wBACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAOzB,mBAAmB;YACxBgB,aAAaH;QACf,GAAGQ;IACL,EAAC;AAEH,SAAST,qBAAqB,EAC5Bc,oBAAoB,EACpBC,OAAO,EACPC,gBAAgB,EAChBC,aAAa,EACO;IACpB,MAAMC,6BAA6B;QACjC,KAAKxB,qBAAqB;YAAEsB;YAAkBC;QAAc,GAAGE,iBAAiB,CAAC;YAC/EC,QAAQ;QACV;IACF;IAEA,MAAM3B,mBAAmB,IAAMC,qBAAqB;YAAEsB;YAAkBC;QAAc;IAEtF,OAAO,CAAC,EAAEN,UAAU,EAAEU,MAAM,EAAE;QAC5B,OAAO;YACLC,MAAM;YACNC,aAAalC,eAAe;gBAAE0B;gBAASE;YAAc;YACrDO,cAAclC,gBAAgB;gBAAEqB;gBAAYlB;YAAiB;YAC7DgC,cAAclC,gBAAgB;gBAC5BoB;gBACAlB;gBACA4B;YACF;YACAK,eAAelC,WAAW;gBAAEmB;gBAAYlB;YAAiB;YACzD,GAAIqB,wBAAwB;gBAAEa,QAAQT;YAA2B,CAAC;QACpE;IACF;AACF;AAEA,SAASxB,wBAAwBD,gBAAgB,GAAE"}
|
package/dist/staticHandler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ContainerClient } from '@azure/storage-blob';
|
|
2
2
|
import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types';
|
|
3
|
-
import type { CollectionConfig } from 'payload
|
|
3
|
+
import type { CollectionConfig } from 'payload';
|
|
4
4
|
interface Args {
|
|
5
5
|
collection: CollectionConfig;
|
|
6
6
|
getStorageClient: () => ContainerClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAO/C,UAAU,IAAI;IACZ,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,EAAE,MAAM,eAAe,CAAA;CACxC;AAED,eAAO,MAAM,UAAU,qCAAsC,IAAI,KAAG,aA8CnE,CAAA"}
|
package/dist/staticHandler.js
CHANGED
|
@@ -12,7 +12,6 @@ export const getHandler = ({ collection, getStorageClient })=>{
|
|
|
12
12
|
const blockBlobClient = getStorageClient().getBlockBlobClient(path.posix.join(prefix, filename));
|
|
13
13
|
const { end, start } = await getRangeFromHeader(blockBlobClient, String(req.headers.get('range')));
|
|
14
14
|
const blob = await blockBlobClient.download(start, end);
|
|
15
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
16
15
|
const response = blob._response;
|
|
17
16
|
// Manually create a ReadableStream for the web from a Node.js stream.
|
|
18
17
|
const readableStream = new ReadableStream({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\nimport type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport path from 'path'\n\nimport { getRangeFromHeader } from './utils/getRangeFromHeader.js'\n\ninterface Args {\n collection: CollectionConfig\n getStorageClient: () => ContainerClient\n}\n\nexport const getHandler = ({ collection, getStorageClient }: Args): StaticHandler => {\n return async (req, { params: { filename } }) => {\n try {\n const prefix = await getFilePrefix({ collection, filename, req })\n const blockBlobClient = getStorageClient().getBlockBlobClient(\n path.posix.join(prefix, filename),\n )\n\n const { end, start } = await getRangeFromHeader(\n blockBlobClient,\n String(req.headers.get('range')),\n )\n\n const blob = await blockBlobClient.download(start, end)\n\n const response = blob._response\n\n // Manually create a ReadableStream for the web from a Node.js stream.\n const readableStream = new ReadableStream({\n start(controller) {\n const nodeStream = blob.readableStreamBody\n if (!nodeStream) {\n throw new Error('No readable stream body')\n }\n\n nodeStream.on('data', (chunk) => {\n controller.enqueue(new Uint8Array(chunk))\n })\n nodeStream.on('end', () => {\n controller.close()\n })\n nodeStream.on('error', (err) => {\n controller.error(err)\n })\n },\n })\n\n return new Response(readableStream, {\n headers: response.headers.rawHeaders(),\n status: response.status,\n })\n } catch (err: unknown) {\n req.payload.logger.error(err)\n return new Response('Internal Server Error', { status: 500 })\n }\n }\n}\n"],"names":["getFilePrefix","path","getRangeFromHeader","getHandler","collection","getStorageClient","req","params","filename","prefix","blockBlobClient","getBlockBlobClient","posix","join","end","start","String","headers","get","blob","download","response","_response","readableStream","ReadableStream","controller","nodeStream","readableStreamBody","Error","on","chunk","enqueue","Uint8Array","close","err","error","Response","rawHeaders","status","payload","logger"],"mappings":"AAIA,SAASA,aAAa,QAAQ,6CAA4C;AAC1E,OAAOC,UAAU,OAAM;AAEvB,SAASC,kBAAkB,QAAQ,gCAA+B;AAOlE,OAAO,MAAMC,aAAa,CAAC,EAAEC,UAAU,EAAEC,gBAAgB,EAAQ;IAC/D,OAAO,OAAOC,KAAK,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,EAAE;QACzC,IAAI;YACF,MAAMC,SAAS,MAAMT,cAAc;gBAAEI;gBAAYI;gBAAUF;YAAI;YAC/D,MAAMI,kBAAkBL,mBAAmBM,kBAAkB,CAC3DV,KAAKW,KAAK,CAACC,IAAI,CAACJ,QAAQD;YAG1B,MAAM,EAAEM,GAAG,EAAEC,KAAK,EAAE,GAAG,MAAMb,mBAC3BQ,iBACAM,OAAOV,IAAIW,OAAO,CAACC,GAAG,CAAC;YAGzB,MAAMC,OAAO,MAAMT,gBAAgBU,QAAQ,CAACL,OAAOD;YAEnD,MAAMO,WAAWF,KAAKG,SAAS;YAE/B,sEAAsE;YACtE,MAAMC,iBAAiB,IAAIC,eAAe;gBACxCT,OAAMU,UAAU;oBACd,MAAMC,aAAaP,KAAKQ,kBAAkB;oBAC1C,IAAI,CAACD,YAAY;wBACf,MAAM,IAAIE,MAAM;oBAClB;oBAEAF,WAAWG,EAAE,CAAC,QAAQ,CAACC;wBACrBL,WAAWM,OAAO,CAAC,IAAIC,WAAWF;oBACpC;oBACAJ,WAAWG,EAAE,CAAC,OAAO;wBACnBJ,WAAWQ,KAAK;oBAClB;oBACAP,WAAWG,EAAE,CAAC,SAAS,CAACK;wBACtBT,WAAWU,KAAK,CAACD;oBACnB;gBACF;YACF;YAEA,OAAO,IAAIE,SAASb,gBAAgB;gBAClCN,SAASI,SAASJ,OAAO,CAACoB,UAAU;gBACpCC,QAAQjB,SAASiB,MAAM;YACzB;QACF,EAAE,OAAOJ,KAAc;YACrB5B,IAAIiC,OAAO,CAACC,MAAM,CAACL,KAAK,CAACD;YACzB,OAAO,IAAIE,SAAS,yBAAyB;gBAAEE,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRangeFromHeader.d.ts","sourceRoot":"","sources":["../../src/utils/getRangeFromHeader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAI1D,eAAO,MAAM,kBAAkB,oBACZ,eAAe,gBAClB,MAAM,KACnB,
|
|
1
|
+
{"version":3,"file":"getRangeFromHeader.d.ts","sourceRoot":"","sources":["../../src/utils/getRangeFromHeader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAI1D,eAAO,MAAM,kBAAkB,oBACZ,eAAe,gBAClB,MAAM,KACnB,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAkBpD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/getRangeFromHeader.ts"],"sourcesContent":["import type { BlockBlobClient } from '@azure/storage-blob'\n\nimport parseRange from 'range-parser'\n\nexport const getRangeFromHeader = async (\n blockBlobClient: BlockBlobClient,\n rangeHeader?: string,\n): Promise<{ end: number | undefined; start: number }> => {\n const fullRange = { end: undefined, start: 0 }\n\n if (!rangeHeader) {\n return fullRange\n }\n\n const size = await blockBlobClient.getProperties().then((props) => props.contentLength)\n if (size === undefined) {\n return fullRange\n }\n\n const range = parseRange(size, rangeHeader)\n if (range === -1 || range === -2 || range.type !== 'bytes' || range.length !== 1) {\n return fullRange\n }\n\n return range[0]\n}\n"],"names":["parseRange","getRangeFromHeader","blockBlobClient","rangeHeader","fullRange","end","undefined","start","size","getProperties","then","props","contentLength","range","type","length"],"
|
|
1
|
+
{"version":3,"sources":["../../src/utils/getRangeFromHeader.ts"],"sourcesContent":["import type { BlockBlobClient } from '@azure/storage-blob'\n\nimport parseRange from 'range-parser'\n\nexport const getRangeFromHeader = async (\n blockBlobClient: BlockBlobClient,\n rangeHeader?: string,\n): Promise<{ end: number | undefined; start: number }> => {\n const fullRange = { end: undefined, start: 0 }\n\n if (!rangeHeader) {\n return fullRange\n }\n\n const size = await blockBlobClient.getProperties().then((props) => props.contentLength)\n if (size === undefined) {\n return fullRange\n }\n\n const range = parseRange(size, rangeHeader)\n if (range === -1 || range === -2 || range.type !== 'bytes' || range.length !== 1) {\n return fullRange\n }\n\n return range[0]\n}\n"],"names":["parseRange","getRangeFromHeader","blockBlobClient","rangeHeader","fullRange","end","undefined","start","size","getProperties","then","props","contentLength","range","type","length"],"mappings":"AAEA,OAAOA,gBAAgB,eAAc;AAErC,OAAO,MAAMC,qBAAqB,OAChCC,iBACAC;IAEA,MAAMC,YAAY;QAAEC,KAAKC;QAAWC,OAAO;IAAE;IAE7C,IAAI,CAACJ,aAAa;QAChB,OAAOC;IACT;IAEA,MAAMI,OAAO,MAAMN,gBAAgBO,aAAa,GAAGC,IAAI,CAAC,CAACC,QAAUA,MAAMC,aAAa;IACtF,IAAIJ,SAASF,WAAW;QACtB,OAAOF;IACT;IAEA,MAAMS,QAAQb,WAAWQ,MAAML;IAC/B,IAAIU,UAAU,CAAC,KAAKA,UAAU,CAAC,KAAKA,MAAMC,IAAI,KAAK,WAAWD,MAAME,MAAM,KAAK,GAAG;QAChF,OAAOX;IACT;IAEA,OAAOS,KAAK,CAAC,EAAE;AACjB,EAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ContainerClient } from '@azure/storage-blob';
|
|
2
|
+
import type { AzureStorageOptions } from '../index.js';
|
|
3
|
+
export declare function getStorageClient(options: Pick<AzureStorageOptions, 'connectionString' | 'containerName'>): ContainerClient;
|
|
4
|
+
//# sourceMappingURL=getStorageClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getStorageClient.d.ts","sourceRoot":"","sources":["../../src/utils/getStorageClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAI1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAItD,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,kBAAkB,GAAG,eAAe,CAAC,GACvE,eAAe,CAUjB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BlobServiceClient } from '@azure/storage-blob';
|
|
2
|
+
let storageClient = null;
|
|
3
|
+
export function getStorageClient(options) {
|
|
4
|
+
if (storageClient) {
|
|
5
|
+
return storageClient;
|
|
6
|
+
}
|
|
7
|
+
const { connectionString, containerName } = options;
|
|
8
|
+
const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString);
|
|
9
|
+
storageClient = blobServiceClient.getContainerClient(containerName);
|
|
10
|
+
return storageClient;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=getStorageClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/getStorageClient.ts"],"sourcesContent":["import type { ContainerClient } from '@azure/storage-blob'\n\nimport { BlobServiceClient } from '@azure/storage-blob'\n\nimport type { AzureStorageOptions } from '../index.js'\n\nlet storageClient: ContainerClient | null = null\n\nexport function getStorageClient(\n options: Pick<AzureStorageOptions, 'connectionString' | 'containerName'>,\n): ContainerClient {\n if (storageClient) {\n return storageClient\n }\n\n const { connectionString, containerName } = options\n\n const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString)\n storageClient = blobServiceClient.getContainerClient(containerName)\n return storageClient\n}\n"],"names":["BlobServiceClient","storageClient","getStorageClient","options","connectionString","containerName","blobServiceClient","fromConnectionString","getContainerClient"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,sBAAqB;AAIvD,IAAIC,gBAAwC;AAE5C,OAAO,SAASC,iBACdC,OAAwE;IAExE,IAAIF,eAAe;QACjB,OAAOA;IACT;IAEA,MAAM,EAAEG,gBAAgB,EAAEC,aAAa,EAAE,GAAGF;IAE5C,MAAMG,oBAAoBN,kBAAkBO,oBAAoB,CAACH;IACjEH,gBAAgBK,kBAAkBE,kBAAkB,CAACH;IACrD,OAAOJ;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-azure",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.100",
|
|
4
4
|
"description": "Payload storage adapter for Azure Blob Storage",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"main": "./dist/index.js",
|
|
@@ -27,23 +27,25 @@
|
|
|
27
27
|
"@azure/abort-controller": "^1.1.0",
|
|
28
28
|
"@azure/storage-blob": "^12.11.0",
|
|
29
29
|
"range-parser": "^1.2.1",
|
|
30
|
-
"@payloadcms/plugin-cloud-storage": "3.0.0-
|
|
30
|
+
"@payloadcms/plugin-cloud-storage": "3.0.0-beta.100"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/range-parser": "^1.2.7",
|
|
34
|
-
"payload": "3.0.0-
|
|
34
|
+
"payload": "3.0.0-beta.100"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"payload": "3.0.0-
|
|
37
|
+
"payload": "3.0.0-beta.100"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
|
-
"node": "
|
|
40
|
+
"node": "^18.20.2 || >=20.9.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
|
-
"build": "pnpm build:
|
|
43
|
+
"build": "pnpm build:types && pnpm build:swc",
|
|
44
44
|
"build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
|
|
45
|
-
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
45
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
46
46
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
47
|
-
"clean": "rimraf {dist,*.tsbuildinfo}"
|
|
47
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
48
|
+
"lint": "eslint .",
|
|
49
|
+
"lint:fix": "eslint . --fix"
|
|
48
50
|
}
|
|
49
51
|
}
|