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