Fix url in UI
This commit is contained in:
@@ -29,7 +29,7 @@ func (c *Cache) refreshTorrentsWorker() {
|
||||
}
|
||||
|
||||
func (c *Cache) resetInvalidLinksWorker() {
|
||||
// Calculate time until next 12:00 CET
|
||||
// Calculate time until next 00:00 CET
|
||||
now := time.Now()
|
||||
loc, err := time.LoadLocation("CET")
|
||||
if err != nil {
|
||||
@@ -43,7 +43,7 @@ func (c *Cache) resetInvalidLinksWorker() {
|
||||
nowInCET.Year(),
|
||||
nowInCET.Month(),
|
||||
nowInCET.Day(),
|
||||
12, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
loc,
|
||||
)
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
path "path/filepath"
|
||||
"slices"
|
||||
@@ -464,6 +465,48 @@ func (h *Handler) serveDirectory(w http.ResponseWriter, r *http.Request, file we
|
||||
"add": func(a, b int) int {
|
||||
return a + b
|
||||
},
|
||||
"urlpath": func(p string) string {
|
||||
segments := strings.Split(p, "/")
|
||||
for i, segment := range segments {
|
||||
segments[i] = url.PathEscape(segment)
|
||||
}
|
||||
return strings.Join(segments, "/")
|
||||
},
|
||||
"formatSize": func(bytes int64) string {
|
||||
const (
|
||||
KB = 1024
|
||||
MB = 1024 * KB
|
||||
GB = 1024 * MB
|
||||
TB = 1024 * GB
|
||||
)
|
||||
|
||||
var size float64
|
||||
var unit string
|
||||
|
||||
switch {
|
||||
case bytes >= TB:
|
||||
size = float64(bytes) / TB
|
||||
unit = "TB"
|
||||
case bytes >= GB:
|
||||
size = float64(bytes) / GB
|
||||
unit = "GB"
|
||||
case bytes >= MB:
|
||||
size = float64(bytes) / MB
|
||||
unit = "MB"
|
||||
case bytes >= KB:
|
||||
size = float64(bytes) / KB
|
||||
unit = "KB"
|
||||
default:
|
||||
size = float64(bytes)
|
||||
unit = "bytes"
|
||||
}
|
||||
|
||||
// Format to 2 decimal places for larger units, no decimals for bytes
|
||||
if unit == "bytes" {
|
||||
return fmt.Sprintf("%.0f %s", size, unit)
|
||||
}
|
||||
return fmt.Sprintf("%.2f %s", size, unit)
|
||||
},
|
||||
}
|
||||
tmpl, err := template.New("directory").Funcs(funcMap).Parse(directoryTemplate)
|
||||
if err != nil {
|
||||
|
||||
@@ -109,16 +109,16 @@ const directoryTemplate = `
|
||||
<h1>Index of {{.Path}}</h1>
|
||||
<ul>
|
||||
{{if .ShowParent}}
|
||||
<li><a href="{{.ParentPath}}" class="parent-dir"><span class="file-number"></span>Parent Directory</a></li>
|
||||
<li><a href="{{urlpath .ParentPath}}" class="parent-dir"><span class="file-number"></span>Parent Directory</a></li>
|
||||
{{end}}
|
||||
{{range $index, $file := .Children}}
|
||||
<li>
|
||||
<a href="{{$.Path}}/{{$file.Name}}">
|
||||
<a href="{{urlpath (printf "%s/%s" $.Path $file.Name)}}">
|
||||
<span class="file-number">{{add $index 1}}.</span>
|
||||
<span class="file-name">{{$file.Name}}{{if $file.IsDir}}/{{end}}</span>
|
||||
<span class="file-info">
|
||||
{{if not $file.IsDir}}
|
||||
{{$file.Size}} bytes
|
||||
{{formatSize $file.Size}}
|
||||
{{end}}
|
||||
{{$file.ModTime.Format "2006-01-02 15:04:05"}}
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user