support jpeg or jpg extension

This commit is contained in:
Celogeek 2023-01-16 11:07:19 +01:00
parent 84e4d32f72
commit cf0cb2ea89
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A

View File

@ -212,22 +212,25 @@ func LoadImages(path string, options *ImageOptions) ([]*Image, error) {
return images, nil return images, nil
} }
func loadDir(input string) (int, chan *imageTask, error) { func isJpeg(path string) bool {
switch strings.ToLower(filepath.Ext(path)) {
case ".jpg", ".jpeg":
{
return true
}
}
return false
}
func loadDir(input string) (int, chan *imageTask, error) {
images := make([]string, 0) images := make([]string, 0)
err := filepath.WalkDir(input, func(path string, d fs.DirEntry, err error) error { err := filepath.WalkDir(input, func(path string, d fs.DirEntry, err error) error {
if err != nil { if err != nil {
return err return err
} }
if d.IsDir() { if !d.IsDir() && isJpeg(path) {
return nil
}
ext := filepath.Ext(path)
if strings.ToLower(ext) != ".jpg" {
return nil
}
images = append(images, path) images = append(images, path)
}
return nil return nil
}) })
if err != nil { if err != nil {
@ -266,14 +269,10 @@ func loadCbz(input string) (int, chan *imageTask, error) {
images := make([]*zip.File, 0) images := make([]*zip.File, 0)
for _, f := range r.File { for _, f := range r.File {
if f.FileInfo().IsDir() { if !f.FileInfo().IsDir() && isJpeg(f.Name) {
continue
}
if strings.ToLower(filepath.Ext(f.Name)) != ".jpg" {
continue
}
images = append(images, f) images = append(images, f)
} }
}
if len(images) == 0 { if len(images) == 0 {
r.Close() r.Close()
return 0, nil, fmt.Errorf("no images found") return 0, nil, fmt.Errorf("no images found")
@ -320,16 +319,10 @@ func loadCbr(input string) (int, chan *imageTask, error) {
break break
} }
if f.IsDir { if !f.IsDir && isJpeg(f.Name) {
continue
}
if strings.ToLower(filepath.Ext(f.Name)) != ".jpg" {
continue
}
names = append(names, f.Name) names = append(names, f.Name)
} }
}
rl.Close() rl.Close()
if len(names) == 0 { if len(names) == 0 {