Filesystem

/views/vfile/Detail.html (2.4 KB)

 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
{% import (
"encoding/base64"
"strings"
"unicode/utf8"

"{{{ .Package }}}/app"
"{{{ .Package }}}/app/controller/cutil"
"{{{ .Package }}}/app/lib/filesystem"
"{{{ .Package }}}/app/util"
"{{{ .Package }}}/views/components"
) %}

{% func Detail(path []string, b []byte, urlPrefix string, additionalLinks map[string]string, as *app.State, ps *cutil.PageState, lineNumLinkAndTitle ...string) %}
{%- if additionalLinks != nil && len(additionalLinks) > 0 -%}
<div class="right">
{%- for k, v := range additionalLinks -%}
{%- code
var icon string
if iconIdx := strings.Index(k, "**"); iconIdx > -1 {
icon = k[iconIdx+2:]
k = k[:iconIdx]
}
var newWindow bool
if strings.HasPrefix(k, "!") {
newWindow = true
k = k[1:]
}
-%}
<a href="{%s v %}"{% if newWindow %} target="_blank"{% endif %}><button>{% if icon != "" %}{%= components.SVGButton(icon, ps) %} {% endif %}{%s k %}</button></a>
{%- endfor -%}
</div>
{%- endif -%}
<h3>
{%- for idx, p := range path -%}/<a href="{%s urlPrefix %}/{%s util.StringFilePath(path[:idx + 1]...) %}">{%s p %}</a>{%- endfor -%}
<em>({%s util.ByteSizeSI(int64(len(b))) %})</em>
</h3>
<div class="mt">
{%- if len(b) > (1024 * 128) -%}
<em>File is {%d len(b) %} bytes, which is too large for the file viewer</em>
{%- elseif utf8.Valid(b) -%}
{%- code out, _ := cutil.FormatFilename(string(b), path[len(path)-1], lineNumLinkAndTitle...) -%}
{%s= out %}
{%- else -%}

{%- if imgType := filesystem.ImageType(path...); imgType != "" -%}
<img alt="Image of type [{%s imgType %}]" src="data:image/{%s imgType %};base64,{%s base64.StdEncoding.EncodeToString(b) %}" />
<hr />
{%- endif -%}

{%- code exif, err := filesystem.ExifExtract(b) -%}
{%- if err == nil -%}
<div class="overflow full-width">
<table>
<thead>
<tr>
<th>EXIF Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{%- for k, v := range exif -%}
<tr>
<td>{%s k %}</td>
<td>{%v v %}</td>
</tr>
{%- endfor -%}
</tbody>
</table>
</div>
{%- else -%}
<em>File is binary and contains no exif header</em>
{%- endif -%}
{%- endif -%}
</div>
{% endfunc %}