MCPcopy
hub / github.com/danielmiessler/Fabric / validateImageFile

Function validateImageFile

internal/cli/flags.go:353–372  ·  view source on GitHub ↗

validateImageFile validates the image file path and extension

(imagePath string)

Source from the content-addressed store, hash-verified

351
352// validateImageFile validates the image file path and extension
353func validateImageFile(imagePath string) error {
354 if imagePath == "" {
355 return nil // No validation needed if no image file specified
356 }
357
358 // Check if file already exists
359 if _, err := os.Stat(imagePath); err == nil {
360 return fmt.Errorf(i18n.T("image_file_already_exists"), imagePath)
361 }
362
363 // Check file extension
364 ext := strings.ToLower(filepath.Ext(imagePath))
365 validExtensions := []string{".png", ".jpeg", ".jpg", ".webp"}
366
367 if slices.Contains(validExtensions, ext) {
368 return nil // Valid extension found
369 }
370
371 return fmt.Errorf(i18n.T("invalid_image_file_extension"), ext)
372}
373
374// validateImageParameters validates image generation parameters
375func validateImageParameters(imagePath, size, quality, background string, compression int) error {

Callers 2

TestValidateImageFileFunction · 0.85
BuildChatOptionsMethod · 0.85

Calls 1

TFunction · 0.92

Tested by 1

TestValidateImageFileFunction · 0.68