-
Notifications
You must be signed in to change notification settings - Fork 0
/
gateway_indexPage.go
160 lines (154 loc) · 3.21 KB
/
gateway_indexPage.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package corehttp
import (
"html/template"
"path"
)
// structs for directory listing
type listingTemplateData struct {
Listing []directoryItem
Path string
BackLink string
}
type directoryItem struct {
Size uint64
Name string
Path string
}
// Directory listing template
var listingTemplate = template.Must(template.New("dir").Funcs(template.FuncMap{"iconFromExt": iconFromExt}).Parse(`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!-- TODO: seed these - maybe like the starter ex or the webui? -->
<link rel="stylesheet" href="/ipfs/QmXB7PLRWH6bCiwrGh2MrBBjNkLv3mY3JdYXCikYZSwLED/bootstrap.min.css"/>
<!-- helper to construct this is here: https://github.com/cryptix/exp/blob/master/imgesToCSSData/convert.go -->
<link rel="stylesheet" href="/ipfs/QmXB7PLRWH6bCiwrGh2MrBBjNkLv3mY3JdYXCikYZSwLED/icons.css">
<style>
.narrow {width: 0px;}
.padding { margin: 100px;}
#header {
background: #000;
}
#logo {
height: 25px;
margin: 10px;
}
.ipfs-icon {
width:16px;
}
</style>
<title>{{ .Path }}</title>
</head>
<body>
<div id="header" class="row">
<div class="col-xs-2">
<div id="logo" class="ipfs-logo"> </div>
</div>
</div>
<br/>
<div class="col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Index of {{ .Path }}</strong>
</div>
<table class="table table-striped">
<tr>
<td class="narrow">
<div class="ipfs-icon ipfs-_blank"> </div>
</td>
<td class="padding">
<a href="{{.BackLink}}">..</a>
</td>
<td></td>
</tr>
{{ range .Listing }}
<tr>
<td>
<div class="ipfs-icon {{iconFromExt .Name}}"> </div>
</td>
<td>
<a href="{{ .Path }}">{{ .Name }}</a>
</td>
<td>{{ .Size }} bytes</td>
</tr>
{{ end }}
</table>
</div>
</div>
</body>
</html>
`))
// helper to guess the type/icon for it by the extension name
func iconFromExt(name string) string {
ext := path.Ext(name)
_, ok := knownIcons[ext]
if !ok {
// default blank icon
return "ipfs-_blank"
}
return "ipfs-" + ext[1:] // slice of the first dot
}
var knownIcons = map[string]bool{
".aac": true,
".aiff": true,
".ai": true,
".avi": true,
".bmp": true,
".c": true,
".cpp": true,
".css": true,
".dat": true,
".dmg": true,
".doc": true,
".dotx": true,
".dwg": true,
".dxf": true,
".eps": true,
".exe": true,
".flv": true,
".gif": true,
".h": true,
".hpp": true,
".html": true,
".ics": true,
".iso": true,
".java": true,
".jpg": true,
".js": true,
".key": true,
".less": true,
".mid": true,
".mp3": true,
".mp4": true,
".mpg": true,
".odf": true,
".ods": true,
".odt": true,
".otp": true,
".ots": true,
".ott": true,
".pdf": true,
".php": true,
".png": true,
".ppt": true,
".psd": true,
".py": true,
".qt": true,
".rar": true,
".rb": true,
".rtf": true,
".sass": true,
".scss": true,
".sql": true,
".tga": true,
".tgz": true,
".tiff": true,
".txt": true,
".wav": true,
".xls": true,
".xlsx": true,
".xml": true,
".yml": true,
".zip": true,
}