added disk quota
This commit is contained in:
parent
4499e88245
commit
9cc2b04342
26 changed files with 1376 additions and 61 deletions
|
|
@ -10,6 +10,8 @@ import (
|
|||
"strings"
|
||||
|
||||
"cachefs/pkg/fs"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
type statusInterceptor struct {
|
||||
|
|
@ -51,9 +53,7 @@ type file struct {
|
|||
|
||||
type files []file
|
||||
|
||||
func (f files) Len() int { return len(f) }
|
||||
func (f files) Less(i, j int) bool { return f[i].Name < f[j].Name }
|
||||
func (f files) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
|
||||
func (files) Less(i, j file) bool { return i.Name < j.Name }
|
||||
|
||||
type responseInterceptor struct {
|
||||
buf bytes.Buffer
|
||||
|
|
@ -98,7 +98,7 @@ func (r *responseInterceptor) GetPaths(path string, fs *fs.FS) (dir dirContents,
|
|||
}
|
||||
}
|
||||
sort.Strings(dir.Dirs)
|
||||
sort.Sort(dir.Files)
|
||||
slices.SortFunc(dir.Files, dir.Files.Less)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import (
|
|||
"io"
|
||||
stdfs "io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"cachefs/pkg/fs"
|
||||
|
|
@ -15,6 +17,21 @@ import (
|
|||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
func PrintStack() {
|
||||
os.Stderr.Write(Stack())
|
||||
}
|
||||
|
||||
func Stack() []byte {
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
n := runtime.Stack(buf, true)
|
||||
if n < len(buf) {
|
||||
return buf[:n]
|
||||
}
|
||||
buf = make([]byte, 2*len(buf))
|
||||
}
|
||||
}
|
||||
|
||||
type FileServer struct {
|
||||
log logr.Logger
|
||||
fs *fs.FS
|
||||
|
|
@ -51,13 +68,17 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
r.URL.Path = upath
|
||||
}
|
||||
p := path.Clean(upath)
|
||||
option := r.FormValue("o")
|
||||
if option == "debug" {
|
||||
PrintStack()
|
||||
}
|
||||
d, _, err := fs.fs.StatWithOffline(p)
|
||||
if err != nil {
|
||||
msg, code := toHTTPError(err)
|
||||
http.Error(w, msg, code)
|
||||
return
|
||||
}
|
||||
option := r.FormValue("o")
|
||||
//option := r.FormValue("o")
|
||||
if option == "v" {
|
||||
err = video.Execute(w, r.URL.Path)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ var (
|
|||
{{end -}}
|
||||
{{range $s := .Files -}}
|
||||
<tr><td><a id="{{$s.Anchor}}" href="{{$s.Name}}">{{$s.Name}}</a></td>
|
||||
<td><a href="{{$s.Name}}?o=v">[v]</a> <a href="{{$s.Name}}?o=n">[n]</a> <a href="{{$s.Name}}?o=p">[p]</a> <a href="{{$s.Name}}?o=s">[s]</a> {{if ge $s.Status 0}}{{$s.Status}}%{{end}}</td></tr>
|
||||
<td><a href="{{$s.Name}}?o=v">[v]</a> <a href="{{$s.Name}}?o=n">[n]</a> <a href="{{$s.Name}}?o=p">[p]</a> <a href="{{$s.Name}}?o=s">[s]</a> {{if ne $s.Status -1}}{{$s.Status}}%{{end}}</td></tr>
|
||||
{{end -}}
|
||||
</table>
|
||||
</article>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"cachefs/pkg/fs"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"golang.org/x/exp/slices"
|
||||
"golang.org/x/net/webdav"
|
||||
)
|
||||
|
||||
|
|
@ -65,10 +66,5 @@ func skipDavLog(path string) bool {
|
|||
if i > 0 {
|
||||
path = path[i+1:]
|
||||
}
|
||||
for _, v := range skipDavFiles {
|
||||
if path == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(skipDavFiles, path)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue