* Detect if input is just a file path (from drag-and-drop into terminal). * Returns the cleaned path or null.
(input)
| 97 | * Returns the cleaned path or null. |
| 98 | */ |
| 99 | function detectDroppedFile(input) { |
| 100 | const trimmed = input.trim().replace(/^["']|["']$/g, ''); // Strip quotes terminals sometimes add |
| 101 | |
| 102 | // Check if it looks like a file path (absolute or relative with image extension) |
| 103 | const ext = require('path').extname(trimmed).toLowerCase(); |
| 104 | if (!IMAGE_EXTENSIONS.includes(ext)) return null; |
| 105 | |
| 106 | // Must look like a path (has slashes or starts with drive letter) |
| 107 | if (trimmed.includes('/') || trimmed.includes('\\') || /^[A-Z]:/i.test(trimmed) || trimmed.startsWith('.')) { |
| 108 | const fs = require('fs'); |
| 109 | const resolved = require('path').resolve(trimmed); |
| 110 | if (fs.existsSync(resolved)) return resolved; |
| 111 | } |
| 112 | |
| 113 | return null; |
| 114 | } |
| 115 | |
| 116 | module.exports = { extractImages, formatImagesForAPI, modelSupportsVision, detectDroppedFile, IMAGE_EXTENSIONS }; |