mirror of
https://github.com/pldubouilh/gossa
synced 2025-12-15 21:04:24 +01:00
Adding image preview
This commit is contained in:
parent
b5505d4773
commit
97196b4cc1
2 changed files with 13 additions and 7 deletions
17
gossa.go
17
gossa.go
|
|
@ -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
3
ui/ui.tmpl
vendored
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue