-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilePacker.go
75 lines (69 loc) · 1.5 KB
/
filePacker.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"os"
"path"
"strings"
)
type fileEchoItem struct {
Name string // file name
Path string
Icon string // icon path
IsDir bool
IsImg bool
Width int
Height int
}
type dirEchoItem struct {
Name string
Path string
Icon string
}
func newfileEchoItem(basepath string, info os.FileInfo) *fileEchoItem {
vf := &fileEchoItem{
Name: info.Name(),
Path: path.Join(WORKING_PATH, basepath, info.Name()),
IsDir: info.IsDir(),
IsImg: false,
Width: 160,
Height: 120,
}
vf.GetIconFile()
return vf
}
// return icon path
func (self *fileEchoItem) GetIconFile() string {
if self.IsDir {
self.Icon = "/img/folder.svg"
return self.Icon
}
suffix := "unknwon"
for i := len(self.Name) - 1; i >= 0; i-- {
if self.Name[i] == '.' {
suffix = strings.ToLower(self.Name[i:])
break
}
}
var icon string
switch suffix {
case ".pdf":
icon = "pdf.svg"
case ".txt":
icon = "txt.svg"
case ".rar", ".zip", ".gz":
icon = "achive.svg"
case ".doc", ".docx":
icon = "word.svg"
case ".png", ".svg", ".jpeg", ".jpg", ".bmp", ".gif":
icon = "img.svg"
self.IsImg = true
default:
icon = "unknow.svg"
}
self.Icon = "/img/" + icon
return self.Icon
}
/*
https://www.jianshu.com/p/05671bab2357
http://www.admpub.com/blog/post-221.html
https://www.quantamagazine.org/new-theory-cracks-open-the-black-box-of-deep-learning-20170921/?utm_source=Quanta+Magazine&utm_campaign=49cbae757d-EMAIL_CAMPAIGN_2017_09_21&utm_medium=email&utm_term=0_f0cb61321c-49cbae757d-389736021
*/