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

Function getFileMetadataByKey

apps/sim/lib/uploads/server/metadata.ts:156–182  ·  view source on GitHub ↗
(
  key: string,
  context?: StorageContext,
  options?: { includeDeleted?: boolean }
)

Source from the content-addressed store, hash-verified

154 * Get file metadata by key with optional context filter
155 */
156export async function getFileMetadataByKey(
157 key: string,
158 context?: StorageContext,
159 options?: { includeDeleted?: boolean }
160): Promise<FileMetadataRecord | null> {
161 const { includeDeleted = false } = options ?? {}
162 const conditions = [eq(workspaceFiles.key, key)]
163
164 if (context) {
165 conditions.push(eq(workspaceFiles.context, context))
166 }
167
168 if (!includeDeleted) {
169 conditions.push(isNull(workspaceFiles.deletedAt))
170 }
171
172 const [record] = await db
173 .select()
174 .from(workspaceFiles)
175 .where(conditions.length > 1 ? and(...conditions) : conditions[0])
176 // Prefer the active row when includeDeleted lets both an active and a
177 // soft-deleted row for the same key match.
178 .orderBy(sql`${workspaceFiles.deletedAt} IS NULL DESC`)
179 .limit(1)
180
181 return record ?? null
182}
183
184/**
185 * Get active (non-deleted) file metadata for multiple keys in a single query.

Callers 12

uploadWorkspaceFileFunction · 0.90
route.tsFile · 0.90
lookupWorkspaceFileByKeyFunction · 0.90
verifyCopilotFileAccessFunction · 0.90
verifyKBFileAccessFunction · 0.90
verifyKBFileWriteAccessFunction · 0.90
handleCloudFileFunction · 0.90
getFileMetadataFunction · 0.85

Calls 2

eqFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected