Adding image preview

This commit is contained in:
Alex Trimpe 2023-10-29 13:15:54 -04:00
parent b5505d4773
commit 97196b4cc1
2 changed files with 13 additions and 7 deletions

View file

@ -24,10 +24,11 @@ import (
)
type rowTemplate struct {
Name string
Href template.HTML
Size string
Ext string
Name string
Href template.HTML
Size string
Ext string
Image bool
}
type pageTemplate struct {
@ -94,7 +95,7 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
title := "/" + strings.TrimPrefix(path, *extraPath)
p := pageTemplate{}
if path != *extraPath {
p.RowsFolders = append(p.RowsFolders, rowTemplate{"../", "../", "", "folder"})
p.RowsFolders = append(p.RowsFolders, rowTemplate{"../", "../", "", "folder", false})
}
p.ExtraPath = template.HTML(html.EscapeString(*extraPath))
p.Ro = *ro
@ -116,17 +117,19 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
href := url.PathEscape(el.Name())
name := el.Name()
lowerName := strings.ToLower(el.Name())
image := strings.HasSuffix(lowerName, ".png") || strings.HasSuffix(lowerName, ".jpeg") || strings.HasSuffix(lowerName, ".jpg")
if el.IsDir() && strings.HasPrefix(href, "/") {
href = strings.Replace(href, "/", "", 1)
}
if el.IsDir() {
p.RowsFolders = append(p.RowsFolders, rowTemplate{name + "/", template.HTML(href), "", "folder"})
p.RowsFolders = append(p.RowsFolders, rowTemplate{name + "/", template.HTML(href), "", "folder", false})
} else {
sl := strings.Split(name, ".")
ext := strings.ToLower(sl[len(sl)-1])
p.RowsFiles = append(p.RowsFiles, rowTemplate{name, template.HTML(href), humanize(el.Size()), ext})
p.RowsFiles = append(p.RowsFiles, rowTemplate{name, template.HTML(href), humanize(el.Size()), ext, image})
}
}

3
ui/ui.tmpl vendored
View file

@ -75,6 +75,9 @@
<td class="file-size"><code>{{.Size}}</code></td>
<td class="arrow"><div class="arrow-icon"></div></td>
<td class="display-name"><a class="list-links" oncontextmenu="return setCursorTo(event.target.innerText)" onclick="return onClickLink(event)" href="{{.Href}}">{{.Name}}</a></td>
{{if .Image}}
<td><img src="{{.Href}}" style="max-width: 20em;"/></td>
{{end}}
</tr>
{{end}}
</table>