(src: string)
| 29 | * URLs (e.g. public `profile-pictures/` assets), which render as-is. |
| 30 | */ |
| 31 | export function extractEmbeddedFileRef(src: string): EmbeddedFileRef { |
| 32 | try { |
| 33 | const parsed = new URL(src, 'http://placeholder') |
| 34 | if (parsed.origin !== 'http://placeholder') return null |
| 35 | const segs = parsed.pathname.split('/') |
| 36 | if (segs[1] === 'api' && segs[2] === 'files' && segs[3] === 'serve') { |
| 37 | let keySegs = segs.slice(4) |
| 38 | if (keySegs[0] === 's3' || keySegs[0] === 'blob') keySegs = keySegs.slice(1) |
| 39 | const raw = keySegs.join('/') |
| 40 | if (!raw) return null |
| 41 | const key = decodeURIComponent(raw) |
| 42 | return key.startsWith('workspace/') ? { key } : null |
| 43 | } |
| 44 | if (segs[1] === 'api' && segs[2] === 'files' && segs[3] === 'view' && segs[4]) { |
| 45 | return { fileId: segs[4] } |
| 46 | } |
| 47 | if (segs[1] === 'workspace' && segs[3] === 'files' && segs[4]) { |
| 48 | return { fileId: segs[4] } |
| 49 | } |
| 50 | return null |
| 51 | } catch { |
| 52 | return null |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * The de-duplicated keys and ids embedded in `content`, bounded to {@link MAX_EMBEDDED_IMAGES} unique |
no test coverage detected