(text: string, cwd: string)
| 316 | * Returns the resolved path and whether it's a directory, or null. |
| 317 | */ |
| 318 | export function getFileOrFolderPathFromText(text: string, cwd: string): { path: string; isDirectory: boolean } | null { |
| 319 | // Must be single line |
| 320 | if (text.includes('\n') || text.includes('\r')) return null |
| 321 | |
| 322 | let trimmed = text.trim() |
| 323 | if (!trimmed) return null |
| 324 | |
| 325 | // Handle file:// URLs |
| 326 | if (trimmed.startsWith('file://')) { |
| 327 | trimmed = decodeURIComponent(trimmed.slice(7)) |
| 328 | } |
| 329 | |
| 330 | // Skip other URLs |
| 331 | if (trimmed.includes('://')) return null |
| 332 | |
| 333 | // Remove surrounding quotes |
| 334 | if ((trimmed.startsWith('"') && trimmed.endsWith('"')) || |
| 335 | (trimmed.startsWith("'") && trimmed.endsWith("'"))) { |
| 336 | trimmed = trimmed.slice(1, -1) |
| 337 | } |
| 338 | |
| 339 | try { |
| 340 | const resolvedPath = resolveFilePath(trimmed, cwd) |
| 341 | if (!existsSync(resolvedPath)) return null |
| 342 | // Skip images — they're handled by image-specific logic |
| 343 | if (isImageFile(resolvedPath)) return null |
| 344 | |
| 345 | const stats = statSync(resolvedPath) |
| 346 | return { |
| 347 | path: resolvedPath, |
| 348 | isDirectory: stats.isDirectory(), |
| 349 | } |
| 350 | } catch { |
| 351 | return null |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Check if text looks like a single file path pointing to an existing image. |
no test coverage detected