(filePath: string)
| 515 | * Handles URLs like /api/files/serve/s3/key or /api/files/serve/blob/key |
| 516 | */ |
| 517 | export 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/`). |
no outgoing calls
no test coverage detected