* The canonical `images` root ancestor of an image path, if any. Images are * often nested in per-camera subdirectories (e.g. `images/cam_1/00.png`), so * the images directory is the `images` ancestor, not the file's immediate * parent. Returns null when no `images` segment is an ancestor.
(path: string)
| 206 | * parent. Returns null when no `images` segment is an ancestor. |
| 207 | */ |
| 208 | function findImagesRootDir(path: string): string | null { |
| 209 | const segments = path.replace(/\\/g, '/').split('/'); |
| 210 | // Skip the filename (last segment); search ancestor directory segments. |
| 211 | for (let i = segments.length - 2; i >= 0; i -= 1) { |
| 212 | if (segments[i].toLowerCase() === 'images') { |
| 213 | return segments.slice(0, i + 1).join('/'); |
| 214 | } |
| 215 | } |
| 216 | return null; |
| 217 | } |
| 218 | |
| 219 | export function resolveImagesDir( |
| 220 | paths: Iterable<string>, |