1
- import type { ContainerClient } from '@azure/storage-blob'
2
1
import type {
3
2
Adapter ,
4
3
PluginOptions as CloudStoragePluginOptions ,
@@ -7,13 +6,13 @@ import type {
7
6
} from '@payloadcms/plugin-cloud-storage/types'
8
7
import type { Config , Plugin } from 'payload'
9
8
10
- import { BlobServiceClient } from '@azure/storage-blob'
11
9
import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'
12
10
13
11
import { getGenerateURL } from './generateURL.js'
14
12
import { getHandleDelete } from './handleDelete.js'
15
13
import { getHandleUpload } from './handleUpload.js'
16
14
import { getHandler } from './staticHandler.js'
15
+ import { getStorageClient as getStorageClientFunc } from './utils/getStorageClient.js'
17
16
18
17
export type AzureStorageOptions = {
19
18
/**
@@ -105,19 +104,14 @@ function azureStorageInternal({
105
104
connectionString,
106
105
containerName,
107
106
} : AzureStorageOptions ) : Adapter {
108
- let storageClient : ContainerClient | null = null
109
- const getStorageClient = ( ) => {
110
- if ( storageClient ) return storageClient
111
-
112
- const blobServiceClient = BlobServiceClient . fromConnectionString ( connectionString )
113
- storageClient = blobServiceClient . getContainerClient ( containerName )
114
- return storageClient
115
- }
116
-
117
107
const createContainerIfNotExists = ( ) => {
118
- void getStorageClient ( ) . createIfNotExists ( { access : 'blob' } )
108
+ void getStorageClientFunc ( { connectionString, containerName } ) . createIfNotExists ( {
109
+ access : 'blob' ,
110
+ } )
119
111
}
120
112
113
+ const getStorageClient = ( ) => getStorageClientFunc ( { connectionString, containerName } )
114
+
121
115
return ( { collection, prefix } ) : GeneratedAdapter => {
122
116
return {
123
117
name : 'azure' ,
@@ -133,3 +127,5 @@ function azureStorageInternal({
133
127
}
134
128
}
135
129
}
130
+
131
+ export { getStorageClientFunc as getStorageClient }
0 commit comments