@payloadcms/storage-azure 3.0.0-alpha.63 → 3.0.0-alpha.64
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/package.json +4 -4
- package/src/index.ts +0 -106
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-azure",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.64",
|
|
4
4
|
"description": "Payload storage adapter for Azure Blob Storage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"@azure/abort-controller": "^1.1.0",
|
|
25
25
|
"@azure/storage-blob": "^12.11.0",
|
|
26
26
|
"range-parser": "^1.2.1",
|
|
27
|
-
"@payloadcms/plugin-cloud-storage": "3.0.0-alpha.
|
|
27
|
+
"@payloadcms/plugin-cloud-storage": "3.0.0-alpha.64"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/range-parser": "^1.2.7",
|
|
31
|
-
"payload": "3.0.0-alpha.
|
|
31
|
+
"payload": "3.0.0-alpha.64"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"payload": "3.0.0-alpha.
|
|
34
|
+
"payload": "3.0.0-alpha.64"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=18.20.2"
|
package/src/index.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { ContainerClient } from '@azure/storage-blob'
|
|
2
|
-
import type {
|
|
3
|
-
Adapter,
|
|
4
|
-
PluginOptions as CloudStoragePluginOptions,
|
|
5
|
-
CollectionOptions,
|
|
6
|
-
GeneratedAdapter,
|
|
7
|
-
} from '@payloadcms/plugin-cloud-storage/types'
|
|
8
|
-
import type { Config, Plugin } from 'payload/config'
|
|
9
|
-
|
|
10
|
-
import { BlobServiceClient } from '@azure/storage-blob'
|
|
11
|
-
import { cloudStorage } from '@payloadcms/plugin-cloud-storage'
|
|
12
|
-
|
|
13
|
-
import { getGenerateURL } from './generateURL.js'
|
|
14
|
-
import { getHandleDelete } from './handleDelete.js'
|
|
15
|
-
import { getHandleUpload } from './handleUpload.js'
|
|
16
|
-
import { getHandler } from './staticHandler.js'
|
|
17
|
-
|
|
18
|
-
export type AzureStorageOptions = {
|
|
19
|
-
allowContainerCreate: boolean
|
|
20
|
-
baseURL: string
|
|
21
|
-
/**
|
|
22
|
-
* Collection options to apply the Azure Blob adapter to.
|
|
23
|
-
*/
|
|
24
|
-
collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Azure Blob storage connection string
|
|
28
|
-
*/
|
|
29
|
-
connectionString: string
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Azure Blob storage container name
|
|
33
|
-
*/
|
|
34
|
-
containerName: string
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Whether or not to enable the plugin
|
|
38
|
-
*
|
|
39
|
-
* Default: true
|
|
40
|
-
*/
|
|
41
|
-
enabled?: boolean
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type AzureStoragePlugin = (azureStorageArgs: AzureStorageOptions) => Plugin
|
|
45
|
-
|
|
46
|
-
export const azureStorage: AzureStoragePlugin =
|
|
47
|
-
(azureStorageOptions: AzureStorageOptions) =>
|
|
48
|
-
(incomingConfig: Config): Config => {
|
|
49
|
-
if (azureStorageOptions.enabled === false) {
|
|
50
|
-
return incomingConfig
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const adapter = azureStorageInternal(azureStorageOptions)
|
|
54
|
-
|
|
55
|
-
// Add adapter to each collection option object
|
|
56
|
-
const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(
|
|
57
|
-
azureStorageOptions.collections,
|
|
58
|
-
).reduce(
|
|
59
|
-
(acc, [slug, collOptions]) => ({
|
|
60
|
-
...acc,
|
|
61
|
-
[slug]: {
|
|
62
|
-
...(collOptions === true ? {} : collOptions),
|
|
63
|
-
adapter,
|
|
64
|
-
},
|
|
65
|
-
}),
|
|
66
|
-
{} as Record<string, CollectionOptions>,
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
return cloudStorage({
|
|
70
|
-
collections: collectionsWithAdapter,
|
|
71
|
-
})(incomingConfig)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function azureStorageInternal({
|
|
75
|
-
allowContainerCreate,
|
|
76
|
-
baseURL,
|
|
77
|
-
connectionString,
|
|
78
|
-
containerName,
|
|
79
|
-
}: AzureStorageOptions): Adapter {
|
|
80
|
-
let storageClient: ContainerClient | null = null
|
|
81
|
-
const getStorageClient = () => {
|
|
82
|
-
if (storageClient) return storageClient
|
|
83
|
-
|
|
84
|
-
const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString)
|
|
85
|
-
storageClient = blobServiceClient.getContainerClient(containerName)
|
|
86
|
-
return storageClient
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const createContainerIfNotExists = () => {
|
|
90
|
-
void getStorageClient().createIfNotExists({ access: 'blob' })
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return ({ collection, prefix }): GeneratedAdapter => {
|
|
94
|
-
return {
|
|
95
|
-
generateURL: getGenerateURL({ baseURL, containerName }),
|
|
96
|
-
handleDelete: getHandleDelete({ collection, getStorageClient }),
|
|
97
|
-
handleUpload: getHandleUpload({
|
|
98
|
-
collection,
|
|
99
|
-
getStorageClient,
|
|
100
|
-
prefix,
|
|
101
|
-
}),
|
|
102
|
-
staticHandler: getHandler({ collection, getStorageClient }),
|
|
103
|
-
...(allowContainerCreate && { onInit: createContainerIfNotExists }),
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|