MCPcopy
hub / github.com/simstudioai/sim / extractStorageKey

Function extractStorageKey

apps/sim/lib/uploads/utils/file-utils.ts:517–539  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

515 * Handles URLs like /api/files/serve/s3/key or /api/files/serve/blob/key
516 */
517export function extractStorageKey(filePath: string): string {
518 let pathWithoutQuery = filePath.split('?')[0]
519
520 try {
521 if (pathWithoutQuery.startsWith('http://') || pathWithoutQuery.startsWith('https://')) {
522 const url = new URL(pathWithoutQuery)
523 pathWithoutQuery = url.pathname
524 }
525 } catch {
526 // If URL parsing fails, use the original path
527 }
528
529 if (pathWithoutQuery.startsWith('/api/files/serve/')) {
530 let key = decodeURIComponent(pathWithoutQuery.substring('/api/files/serve/'.length))
531 if (key.startsWith('s3/')) {
532 key = key.substring(3)
533 } else if (key.startsWith('blob/')) {
534 key = key.substring(5)
535 }
536 return key
537 }
538 return pathWithoutQuery
539}
540
541/**
542 * Whether a URL targets the internal file-serve endpoint (`/api/files/serve/`).

Callers 10

addDocumentFunction · 0.90
updateDocumentFunction · 0.90
downloadFileFromUrlFunction · 0.90
resolveInternalFileUrlFunction · 0.90
handleCloudFileFunction · 0.90
handleLocalFileFunction · 0.90
parseInternalFileUrlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected