| 1 | import fs from 'fs' |
| 2 | import path from 'path' |
| 3 | |
| 4 | const dynamicAllowedRoots = new Set<string>() |
| 5 | |
| 6 | export const normalizeExistingPath = (filePath: string): string => { |
| 7 | const resolved = path.resolve(filePath) |
| 8 | try { |
| 9 | return fs.realpathSync(resolved) |
| 10 | } catch { |
| 11 | return resolved |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | export function allowLocalAssetRoot(rootPath: string): void { |
| 16 | if (!rootPath.trim()) return |
| 17 | dynamicAllowedRoots.add(normalizeExistingPath(rootPath)) |
| 18 | } |
| 19 | |
| 20 | export function getDynamicAllowedLocalAssetRoots(): string[] { |
| 21 | return [...dynamicAllowedRoots] |
| 22 | } |
| 23 |