MCPcopy
hub / github.com/CodebuffAI/codebuff / validateAndAddImage

Function validateAndAddImage

cli/src/utils/pending-attachments.ts:186–210  ·  view source on GitHub ↗
(
  imagePath: string,
  cwd: string,
)

Source from the content-addressed store, hash-verified

184 * or { success: false, error } if the file doesn't exist or isn't supported.
185 */
186export 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

Callers 3

ChatFunction · 0.90
routeUserPromptFunction · 0.90
handleImageCommandFunction · 0.90

Calls 4

resolveFilePathFunction · 0.90
isImageFileFunction · 0.90
addPendingImageWithErrorFunction · 0.85
addPendingImageFromFileFunction · 0.85

Tested by

no test coverage detected