()
| 68 | } |
| 69 | |
| 70 | export async function getBlobServiceClient(): Promise<BlobServiceClientType> { |
| 71 | if (_blobServiceClient) return _blobServiceClient |
| 72 | |
| 73 | const { BlobServiceClient, StorageSharedKeyCredential } = await import('@azure/storage-blob') |
| 74 | const { accountName, accountKey, connectionString } = BLOB_CONFIG |
| 75 | |
| 76 | if (connectionString) { |
| 77 | _blobServiceClient = BlobServiceClient.fromConnectionString(connectionString) |
| 78 | } else if (accountName && accountKey) { |
| 79 | const sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey) |
| 80 | _blobServiceClient = new BlobServiceClient( |
| 81 | `https://${accountName}.blob.core.windows.net`, |
| 82 | sharedKeyCredential |
| 83 | ) |
| 84 | } else { |
| 85 | throw new Error( |
| 86 | 'Azure Blob Storage credentials are missing – set AZURE_STORAGE_CONNECTION_STRING or both AZURE_STORAGE_ACCOUNT_NAME and AZURE_STORAGE_ACCOUNT_KEY in your environment.' |
| 87 | ) |
| 88 | } |
| 89 | |
| 90 | return _blobServiceClient |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Upload a file to Azure Blob Storage |
no outgoing calls
no test coverage detected