diff --git a/dataswamp/services.go b/dataswamp/services.go index c35e032..caefe28 100644 --- a/dataswamp/services.go +++ b/dataswamp/services.go @@ -123,6 +123,10 @@ func (s SwampFileService) OpenOutFile(ref swampfile.FileReference) (swampfile.Sw return f, nil } +func (s SwampFileService) NamespaceStats() ([]namespace.Namespace, error) { + return s.namespace_repo.All() +} + func (s SwampFileService) CleanUpExpiredFiles() error { s.logger.Info("Cleaning up expired files") nss, err := s.namespace_repo.All() diff --git a/server/bog.go b/server/bog.go index 7bd64db..053fde8 100644 --- a/server/bog.go +++ b/server/bog.go @@ -6,9 +6,9 @@ import ( "caj-larsson/bog/dataswamp/swampfile" fs_swampfile "caj-larsson/bog/infrastructure/fs/swampfile" sql_namespace "caj-larsson/bog/infrastructure/sqlite/namespace" - "fmt" "net/http" "strconv" + "text/template" "time" ) @@ -41,7 +41,18 @@ func buildNamespaceRepository(config DatabaseConfig) namespace.Repository { func (b *Bog) fileHandler(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { - fmt.Fprintf(w, "Hi") + templ, err := template.ParseFiles("server/views/dashboard.html") + + if err != nil { + panic(err) + } + + stats, _ := b.file_service.NamespaceStats() + err = templ.Execute(w, stats) + + if err != nil { + panic(err) + } return } ref := swampfile.FileReference{r.URL.Path, r.Header["User-Agent"][0]} diff --git a/server/views/dashboard.html b/server/views/dashboard.html new file mode 100644 index 0000000..491e3ef --- /dev/null +++ b/server/views/dashboard.html @@ -0,0 +1,33 @@ + + + + bog + + + + + + + + + + + + + + + + {{ range . }} + + + + + + + + + {{ end }} + +
NameLast SeenQuotaUsageDownloadUpload
{{ .Name }}{{ .LastSeen }} - {{ .AllowanceDuration }}{{ .FileQuota.CurrentUsage }}/{{ .FileQuota.AllowanceKB}} B{{ .Usage.SizeB }}B - {{ .Usage.Num }} {{ .Download.SizeB }}B - {{ .Download.Num }} {{ .Upload.SizeB }}B - {{ .Upload.Num }}
+ +