Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit 96f0250

Browse files
committed
feat: add function to parse file format, update template
1 parent 6be162e commit 96f0250

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

render.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,22 @@ func customFuncs() template.FuncMap {
150150

151151
return strings.Split(filename, ".")[0]
152152
},
153+
"getElementByFileExt": func(fileType string) string {
154+
imgTypes := "jpg png gif jpeg svg icon webp raw"
155+
videoTypes := "avi mp4 mkv mov wmv flv avchd"
156+
audioTypes := "mp3 ogg aac oga flac pcm wav aiff"
157+
158+
fileType = strings.ToLower(fileType)
159+
160+
if strings.Contains(imgTypes, fileType) {
161+
return "image"
162+
} else if strings.Contains(videoTypes, fileType) {
163+
return "video"
164+
} else if strings.Contains(audioTypes, fileType) {
165+
return "audio"
166+
}
167+
168+
return ""
169+
},
153170
}
154171
}

templates/fs_list.html

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h2 class="title is-2">
1010
<table class="table is-striped" style="width:100%;">
1111
<thead>
1212
<tr>
13-
<th style="width:40%;">Name</th>
13+
<th style="width:30%;">Name</th>
1414
<th style="width:10%; text-align:center;">Size</th>
1515
<th style="width:10%; text-align:center;">Type</th>
1616
<th style="width:20%; text-align:center;">Uploaded</th>
@@ -20,13 +20,35 @@ <h2 class="title is-2">
2020
</thead>
2121
<tbody>
2222
{{range .Data}}
23-
{{$fileType := convertFileType .Key}}
24-
<tr style="height:100px;">
23+
{{$fileType := convertFileType .Key}}
24+
{{$elementType := getElementByFileExt $fileType}}
25+
26+
{{ if or (eq $elementType "") (eq $elementType "audio")}}
27+
<tr style="height:100px;">
28+
{{ else }}
29+
<tr style="height:200px;">
30+
{{ end }}
2531
<td>{{ parseFilename .Key }}</td>
2632
<td style="text-align:center;">{{ convertFileSize .Size }}</td>
27-
<td style="text-align:center;">{{ convertFileType .Key }}</td>
33+
<td style="text-align:center;">{{ $fileType }}</td>
2834
<td style="text-align:center;">{{ convertFileUploadedDate .Uploaded}}</td>
29-
<td style="text-align:center;">TODO</td>
35+
<td style="text-align:center;">
36+
{{ if eq $elementType "image" }}
37+
<a href="{{ .URL }}">
38+
<img src="{{ .URL }}" alt="uploaded image" style="height:200px;">
39+
</a>
40+
{{ else if eq $elementType "video" }}
41+
<video controls style="height:200px;">
42+
<source src="{{ .URL }}">
43+
</video>
44+
{{ else if eq $elementType "audio" }}
45+
<audio src="{{ .URL }}" controls></audio>
46+
{{ else }}
47+
<a href="{{ .URL }}">
48+
Can't preview!
49+
</a>
50+
{{ end }}
51+
</td>
3052
<td style="text-align:center;">
3153
<a
3254
href="/ui/fs/del/{{ .ID }}"

0 commit comments

Comments
 (0)