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

Function getFileMetadata

apps/sim/lib/uploads/core/storage-client.ts:28–97  ·  view source on GitHub ↗
(
  key: string,
  customConfig?: StorageConfig
)

Source from the content-addressed store, hash-verified

26 * @returns File metadata object with userId, workspaceId, originalName, uploadedAt, etc.
27 */
28export async function getFileMetadata(
29 key: string,
30 customConfig?: StorageConfig
31): Promise<Record<string, string>> {
32 const { getFileMetadataByKey } = await import('../server/metadata')
33 const metadataRecord = await getFileMetadataByKey(key)
34
35 if (metadataRecord) {
36 return {
37 userId: metadataRecord.userId,
38 workspaceId: metadataRecord.workspaceId || '',
39 originalName: metadataRecord.originalName,
40 uploadedAt: metadataRecord.uploadedAt.toISOString(),
41 purpose: metadataRecord.context,
42 }
43 }
44
45 if (USE_BLOB_STORAGE) {
46 const { getBlobServiceClient } = await import('@/lib/uploads/providers/blob/client')
47 const { BLOB_CONFIG } = await import('@/lib/uploads/config')
48
49 let blobServiceClient = await getBlobServiceClient()
50 let containerName = BLOB_CONFIG.containerName
51
52 if (customConfig) {
53 const { BlobServiceClient, StorageSharedKeyCredential } = await import('@azure/storage-blob')
54 if (customConfig.connectionString) {
55 blobServiceClient = BlobServiceClient.fromConnectionString(customConfig.connectionString)
56 } else if (customConfig.accountName && customConfig.accountKey) {
57 const credential = new StorageSharedKeyCredential(
58 customConfig.accountName,
59 customConfig.accountKey
60 )
61 blobServiceClient = new BlobServiceClient(
62 `https://${customConfig.accountName}.blob.core.windows.net`,
63 credential
64 )
65 }
66 containerName = customConfig.containerName || containerName
67 }
68
69 const containerClient = blobServiceClient.getContainerClient(containerName)
70 const blockBlobClient = containerClient.getBlockBlobClient(key)
71 const properties = await blockBlobClient.getProperties()
72 return properties.metadata || {}
73 }
74
75 if (USE_S3_STORAGE) {
76 const { getS3Client } = await import('@/lib/uploads/providers/s3/client')
77 const { HeadObjectCommand } = await import('@aws-sdk/client-s3')
78 const { S3_CONFIG } = await import('@/lib/uploads/config')
79
80 const s3Client = getS3Client()
81 const bucket = customConfig?.bucket || S3_CONFIG.bucket
82
83 if (!bucket) {
84 throw new Error('S3 bucket not configured')
85 }

Callers 5

verifyCopilotFileAccessFunction · 0.90
verifyChatFileAccessFunction · 0.90
verifyRegularFileAccessFunction · 0.90

Calls 4

getFileMetadataByKeyFunction · 0.85
getBlobServiceClientFunction · 0.85
getS3ClientFunction · 0.85
sendMethod · 0.80

Tested by

no test coverage detected