added file size

This commit is contained in:
ston1th 2022-10-05 20:35:15 +02:00
commit 055e9db8e2
5 changed files with 33 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import (
stdfs "io/fs" stdfs "io/fs"
"net/http" "net/http"
"os" "os"
"strconv"
"strings" "strings"
"github.com/go-logr/logr" "github.com/go-logr/logr"
@ -100,6 +101,33 @@ func (fs *FS) Stat(name string) (fi stdfs.FileInfo, err error) {
return return
} }
const (
_ = 1 << (iota * 10)
KiB
MiB
GiB
TiB
)
func (fs *FS) FileSize(name string) (size string) {
fi, err := fs.Stat(name)
if err != nil {
return
}
s := fi.Size()
switch {
case s >= TiB:
return strconv.Itoa(int(s/TiB)) + " TiB"
case s >= GiB:
return strconv.Itoa(int(s/GiB)) + " GiB"
case s >= MiB:
return strconv.Itoa(int(s/MiB)) + " MiB"
case s >= KiB:
return strconv.Itoa(int(s/KiB)) + " KiB"
}
return strconv.Itoa(int(s)) + " B"
}
func (fs *FS) RemoveDst(name string) error { func (fs *FS) RemoveDst(name string) error {
return fs.dst.Remove(name) return fs.dst.Remove(name)
} }

View file

@ -59,6 +59,7 @@ type file struct {
Name template.HTML Name template.HTML
URI template.HTML URI template.HTML
Anchor string Anchor string
Size string
Status int Status int
Prio int Prio int
Errc int Errc int
@ -122,6 +123,7 @@ func (r *responseInterceptor) GetPaths(path string, fs *fs.FS, relative bool) (d
Name: name, Name: name,
URI: uri, URI: uri,
Anchor: anchor(p), Anchor: anchor(p),
Size: fs.FileSize(full),
Status: fs.CacheStatus(full), Status: fs.CacheStatus(full),
}) })
} }

View file

@ -17,7 +17,7 @@
<tr class="listitem"> <tr class="listitem">
<td class="listpath"><a id="{{$s.Anchor}}" href="{{$s.URI}}">{{$s.Name}}</a></td> <td class="listpath"><a id="{{$s.Anchor}}" href="{{$s.URI}}">{{$s.Name}}</a></td>
<td class="listoptions"> <td class="listoptions">
{{if ge $s.Status 0}}<span>{{$s.Status}}%</span>{{end}}<a href="{{$s.URI}}?o=v">[v]</a> {{if ge $s.Status 0}}<span>{{$s.Status}}%</span>{{end}}<span>{{$s.Size}}</span><a href="{{$s.URI}}?o=v">[v]</a>
</td> </td>
</tr> </tr>
<tr class="spacer"><td colspan="2"> <tr class="spacer"><td colspan="2">

View file

@ -20,7 +20,7 @@
<tr class="listitem"> <tr class="listitem">
<td class="listpath"><a id="{{$s.Anchor}}" href="{{$s.URI}}">{{$s.Name}}</a></td> <td class="listpath"><a id="{{$s.Anchor}}" href="{{$s.URI}}">{{$s.Name}}</a></td>
<td class="listoptions"> <td class="listoptions">
{{if ge $s.Status 0}}<span>{{$s.Status}}%</span>{{end}}<a href="{{$s.URI}}?o=v">[v]</a><a href="{{$s.URI}}?o=n">[n]</a><a href="{{$s.URI}}?o=p">[p]</a> {{if ge $s.Status 0}}<span>{{$s.Status}}%</span>{{end}}<span>{{$s.Size}}</span><a href="{{$s.URI}}?o=v">[v]</a><a href="{{$s.URI}}?o=n">[n]</a><a href="{{$s.URI}}?o=p">[p]</a>
</td> </td>
</tr> </tr>
<tr class="spacer"><td colspan="2"> <tr class="spacer"><td colspan="2">

View file

@ -24,6 +24,7 @@ Quota: {{.QuotaCur}} / {{.QuotaMax}} GiB
<span class="status-yellow">[queued]</span> <span class="status-yellow">[queued]</span>
{{end -}} {{end -}}
{{end -}} {{end -}}
<span>{{$s.Size}}</span>
<span>{{$s.Prio}}</span><a href="{{$s.URI}}?o=v">[v]</a><a href="{{$s.Name}}?o=s&r=preloads">[s]</a><a href="{{$s.Name}}?o=i&r=preloads">[+]</a><a href="{{$s.Name}}?o=d&r=preloads">[-]</a> <span>{{$s.Prio}}</span><a href="{{$s.URI}}?o=v">[v]</a><a href="{{$s.Name}}?o=s&r=preloads">[s]</a><a href="{{$s.Name}}?o=i&r=preloads">[+]</a><a href="{{$s.Name}}?o=d&r=preloads">[-]</a>
</td> </td>
</tr> </tr>