fix filetype extension check
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
type FileDescription struct {
|
||||
TkType tk.FileType
|
||||
TkTypeName string
|
||||
MacExtensions []string
|
||||
IconFile string
|
||||
MIMETypes []string
|
||||
@@ -18,7 +19,7 @@ type FileDescription struct {
|
||||
|
||||
var Valid = []FileDescription{
|
||||
{
|
||||
TkType: tk.FileType{TypeName: "BMP", Extensions: []string{".bmp"}},
|
||||
TkTypeName: "BMP",
|
||||
MacExtensions: []string{"bmp", "BMP"},
|
||||
IconFile: "bmp.icns",
|
||||
MIMETypes: []string{"image/bmp"},
|
||||
@@ -27,7 +28,7 @@ var Valid = []FileDescription{
|
||||
ItemContentTypes: "com.microsoft.bmp",
|
||||
},
|
||||
{
|
||||
TkType: tk.FileType{TypeName: "JPEG", Extensions: []string{".jpg", ".jpeg"}},
|
||||
TkTypeName: "JPEG",
|
||||
MacExtensions: []string{"jpg", "JPG", "jpeg", "JPEG"},
|
||||
IconFile: "jpeg.icns",
|
||||
MIMETypes: []string{"image/jpeg"},
|
||||
@@ -36,7 +37,7 @@ var Valid = []FileDescription{
|
||||
ItemContentTypes: "public.jpeg",
|
||||
},
|
||||
{
|
||||
TkType: tk.FileType{TypeName: "GIF", Extensions: []string{".gif"}},
|
||||
TkTypeName: "GIF",
|
||||
MacExtensions: []string{"gif", "GIF"},
|
||||
IconFile: "gif.icns",
|
||||
MIMETypes: []string{"image/gif"},
|
||||
@@ -45,7 +46,7 @@ var Valid = []FileDescription{
|
||||
ItemContentTypes: "com.compuserve.gif",
|
||||
},
|
||||
{
|
||||
TkType: tk.FileType{TypeName: "PNG", Extensions: []string{".png"}},
|
||||
TkTypeName: "PNG",
|
||||
MacExtensions: []string{"PNG", "png"},
|
||||
IconFile: "png.icns",
|
||||
MIMETypes: []string{"image/png"},
|
||||
@@ -54,7 +55,7 @@ var Valid = []FileDescription{
|
||||
ItemContentTypes: "public.png",
|
||||
},
|
||||
{
|
||||
TkType: tk.FileType{TypeName: "TGA", Extensions: []string{".tga"}},
|
||||
TkTypeName: "TGA",
|
||||
MacExtensions: []string{"tga", "TGA"},
|
||||
IconFile: "tga.icns",
|
||||
MIMETypes: []string{"image/targa", "image/tga", "application/tga"},
|
||||
@@ -63,7 +64,7 @@ var Valid = []FileDescription{
|
||||
ItemContentTypes: "com.truevision.tga-image",
|
||||
},
|
||||
{
|
||||
TkType: tk.FileType{TypeName: "TIFF", Extensions: []string{".tiff"}},
|
||||
TkTypeName: "TIFF",
|
||||
MacExtensions: []string{"tiff", "TIFF", "tif", "TIF"},
|
||||
IconFile: "tiff.icns",
|
||||
MIMETypes: []string{"image/tiff"},
|
||||
@@ -76,7 +77,13 @@ var Valid = []FileDescription{
|
||||
func GetTkTypes(fds []FileDescription) []tk.FileType {
|
||||
fts := make([]tk.FileType, len(fds))
|
||||
for i, fd := range fds {
|
||||
fts[i] = fd.TkType
|
||||
fts[i] = tk.FileType{
|
||||
TypeName: fd.TkTypeName,
|
||||
Extensions: make([]string, len(fd.MacExtensions)),
|
||||
}
|
||||
for j, ex := range fd.MacExtensions {
|
||||
fts[i].Extensions[j] = fmt.Sprintf(".%s", ex)
|
||||
}
|
||||
}
|
||||
return fts
|
||||
}
|
||||
|
5
main.go
5
main.go
@@ -49,8 +49,11 @@ func isImage(entry os.DirEntry) bool {
|
||||
return false
|
||||
}
|
||||
ext := filepath.Ext(entry.Name())
|
||||
if ext == "" {
|
||||
return false
|
||||
}
|
||||
for _, ft := range validFileTypes {
|
||||
if slices.Contains(ft.TkType.Extensions, ext) {
|
||||
if slices.Contains(ft.MacExtensions, ext[1:]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user