filetype_detect.go
895 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package tool
import (
"path/filepath"
"strings"
)
const (
Image = "image"
Video = "video"
)
var TypeMap = map[string]string{
"jpg": Image,
"png": Image,
"gif": Image,
"webp": Image,
"cr2": Image,
"tif": Image,
"bmp": Image,
"heif": Image,
"jxr": Image,
"psd": Image,
"ico": Image,
"dwg": Image,
"avif": Image,
"mp4": Video,
"m4v": Video,
"mkv": Video,
"webm": Video,
"mov": Video,
"avi": Video,
"wmv": Video,
"mpg": Video,
"flv": Video,
"3gp": Video,
}
var DefaultFileTypeDetector = FileTypeDetector{}
type FileTypeDetector struct {
}
func (c FileTypeDetector) Classify(medias []string, mediaType string) []string {
result := make([]string, 0)
for _, media := range medias {
v, ok := TypeMap[strings.Trim(filepath.Ext(media), ".")]
if !ok {
continue
}
if v == mediaType {
result = append(result, media)
}
}
return result
}