added file size
This commit is contained in:
parent
00d87ecb5c
commit
055e9db8e2
5 changed files with 33 additions and 2 deletions
28
pkg/fs/fs.go
28
pkg/fs/fs.go
|
|
@ -12,6 +12,7 @@ import (
|
|||
stdfs "io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
|
|
@ -100,6 +101,33 @@ func (fs *FS) Stat(name string) (fi stdfs.FileInfo, err error) {
|
|||
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 {
|
||||
return fs.dst.Remove(name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ type file struct {
|
|||
Name template.HTML
|
||||
URI template.HTML
|
||||
Anchor string
|
||||
Size string
|
||||
Status int
|
||||
Prio int
|
||||
Errc int
|
||||
|
|
@ -122,6 +123,7 @@ func (r *responseInterceptor) GetPaths(path string, fs *fs.FS, relative bool) (d
|
|||
Name: name,
|
||||
URI: uri,
|
||||
Anchor: anchor(p),
|
||||
Size: fs.FileSize(full),
|
||||
Status: fs.CacheStatus(full),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
<tr class="listitem">
|
||||
<td class="listpath"><a id="{{$s.Anchor}}" href="{{$s.URI}}">{{$s.Name}}</a></td>
|
||||
<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>
|
||||
</tr>
|
||||
<tr class="spacer"><td colspan="2">
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
<tr class="listitem">
|
||||
<td class="listpath"><a id="{{$s.Anchor}}" href="{{$s.URI}}">{{$s.Name}}</a></td>
|
||||
<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>
|
||||
</tr>
|
||||
<tr class="spacer"><td colspan="2">
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ Quota: {{.QuotaCur}} / {{.QuotaMax}} GiB
|
|||
<span class="status-yellow">[queued]</span>
|
||||
{{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>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue