( imagePath: string, cwd: string, )
| 184 | * or { success: false, error } if the file doesn't exist or isn't supported. |
| 185 | */ |
| 186 | export async function validateAndAddImage( |
| 187 | imagePath: string, |
| 188 | cwd: string, |
| 189 | ): Promise<{ success: true } | { success: false; error: string }> { |
| 190 | const resolvedPath = resolveFilePath(imagePath, cwd) |
| 191 | |
| 192 | // Check if file exists |
| 193 | if (!existsSync(resolvedPath)) { |
| 194 | const error = 'file not found' |
| 195 | addPendingImageWithError(resolvedPath, `❌ ${error}`) |
| 196 | return { success: false, error } |
| 197 | } |
| 198 | |
| 199 | // Check if it's a supported format |
| 200 | if (!isImageFile(resolvedPath)) { |
| 201 | const ext = path.extname(imagePath).toLowerCase() |
| 202 | const error = ext ? `unsupported format ${ext}` : 'unsupported format' |
| 203 | addPendingImageWithError(resolvedPath, `❌ ${error}`) |
| 204 | return { success: false, error } |
| 205 | } |
| 206 | |
| 207 | // Process and add the image (addPendingImageFromFile handles exiting image mode on success) |
| 208 | await addPendingImageFromFile(resolvedPath, cwd) |
| 209 | return { success: true } |
| 210 | } |
| 211 | |
| 212 | // --------------------------------------------------------------------------- |
| 213 | // File / folder attachments |
no test coverage detected