MCPcopy Index your code
hub / github.com/simstudioai/sim / getPresignedUrlWithConfig

Function getPresignedUrlWithConfig

apps/sim/lib/uploads/providers/blob/client.ts:204–258  ·  view source on GitHub ↗
(
  key: string,
  customConfig: BlobConfig,
  expiresIn = 3600
)

Source from the content-addressed store, hash-verified

202 * @returns Presigned URL
203 */
204export async function getPresignedUrlWithConfig(
205 key: string,
206 customConfig: BlobConfig,
207 expiresIn = 3600
208) {
209 const {
210 BlobServiceClient,
211 BlobSASPermissions,
212 generateBlobSASQueryParameters,
213 StorageSharedKeyCredential,
214 } = await import('@azure/storage-blob')
215 let tempBlobServiceClient: BlobServiceClientType
216 let accountName: string
217 let accountKey: string
218
219 if (customConfig.connectionString) {
220 tempBlobServiceClient = BlobServiceClient.fromConnectionString(customConfig.connectionString)
221 const credentials = parseConnectionString(customConfig.connectionString)
222 accountName = credentials.accountName
223 accountKey = credentials.accountKey
224 } else if (customConfig.accountName && customConfig.accountKey) {
225 const sharedKeyCredential = new StorageSharedKeyCredential(
226 customConfig.accountName,
227 customConfig.accountKey
228 )
229 tempBlobServiceClient = new BlobServiceClient(
230 `https://${customConfig.accountName}.blob.core.windows.net`,
231 sharedKeyCredential
232 )
233 accountName = customConfig.accountName
234 accountKey = customConfig.accountKey
235 } else {
236 throw new Error(
237 'Custom blob config must include either connectionString or accountName + accountKey'
238 )
239 }
240
241 const containerClient = tempBlobServiceClient.getContainerClient(customConfig.containerName)
242 const blockBlobClient = containerClient.getBlockBlobClient(key)
243
244 const sasOptions = {
245 containerName: customConfig.containerName,
246 blobName: key,
247 permissions: BlobSASPermissions.parse('r'), // Read permission
248 startsOn: new Date(),
249 expiresOn: new Date(Date.now() + expiresIn * 1000),
250 }
251
252 const sasToken = generateBlobSASQueryParameters(
253 sasOptions,
254 new StorageSharedKeyCredential(accountName, accountKey)
255 ).toString()
256
257 return `${blockBlobClient.url}?${sasToken}`
258}
259
260/**
261 * Download a file from Azure Blob Storage

Callers

nothing calls this directly

Calls 3

parseConnectionStringFunction · 0.85
parseMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected