MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / validateImageFile

Function validateImageFile

internal/cli/flags.go:332–349  ·  view source on GitHub ↗

validateImageFile rejects a path that exists or has an extension other than png, jpeg, jpg, or webp.

(imagePath string)

Source from the content-addressed store, hash-verified

330
331// validateImageFile rejects a path that exists or has an extension other than png, jpeg, jpg, or webp.
332func validateImageFile(imagePath string) error {
333 if imagePath == "" {
334 return nil
335 }
336
337 if _, err := os.Stat(imagePath); err == nil {
338 return fmt.Errorf(i18n.T("image_file_already_exists"), imagePath)
339 }
340
341 ext := strings.ToLower(filepath.Ext(imagePath))
342 validExtensions := []string{".png", ".jpeg", ".jpg", ".webp"}
343
344 if slices.Contains(validExtensions, ext) {
345 return nil
346 }
347
348 return fmt.Errorf(i18n.T("invalid_image_file_extension"), ext)
349}
350
351func validateImageParameters(imagePath, size, quality, background string, compression int) error {
352 if imagePath == "" {

Callers 2

TestValidateImageFileFunction · 0.85
BuildChatOptionsMethod · 0.85

Calls 1

TFunction · 0.92

Tested by 1

TestValidateImageFileFunction · 0.68