From 684787bcb72aece2aa914597a3bc8788432e66f7 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sun, 13 Jul 2025 21:23:34 +0100 Subject: Add flags --- pkg/config/site.go | 12 ++++ pkg/site/site.go | 22 +++++++ pkg/upload/upload.go | 5 ++ web/command/handler/flags.go | 71 +++++++++++++++++++++++ web/command/handler/site.go | 5 +- web/command/handler/upload.go | 6 +- web/command/html/error.go | 13 +++++ web/command/html/flags.go | 130 ++++++++++++++++++++++++++++++++++++++++++ web/command/html/home.go | 8 +++ web/command/html/site.go | 9 ++- web/command/html/style.css | 14 ++++- web/mux.go | 2 + 12 files changed, 285 insertions(+), 12 deletions(-) create mode 100644 web/command/handler/flags.go create mode 100644 web/command/html/error.go create mode 100644 web/command/html/flags.go diff --git a/pkg/config/site.go b/pkg/config/site.go index ffd5ddc..4b36f1a 100644 --- a/pkg/config/site.go +++ b/pkg/config/site.go @@ -6,8 +6,20 @@ import ( "github.com/pelletier/go-toml/v2" ) +type SiteFlag uint + +const ( + FlagDisable SiteFlag = 1 << iota + FlagTLS + FlagIndex + FlagPassword + FlagReadOnly +) + type SiteConfig struct { Host string + + Flags SiteFlag } func ReadSiteConfig(filePath string, dst *SiteConfig) error { diff --git a/pkg/site/site.go b/pkg/site/site.go index 37dca5f..3daf5e7 100644 --- a/pkg/site/site.go +++ b/pkg/site/site.go @@ -8,6 +8,7 @@ import ( "path" "path/filepath" "regexp" + "strings" "time" "github.com/LMBishop/scrapbook/pkg/config" @@ -136,6 +137,9 @@ func (s *Site) EvaluateSiteStatus() string { if err != nil || !stat.IsDir() { return "inactive" } + if s.SiteConfig.Flags&config.FlagDisable != 0 { + return "inactive" + } return "live" } @@ -145,6 +149,24 @@ func (s *Site) EvaluateSiteStatusReason() string { if err != nil || !stat.IsDir() { return "This site is inacessible because no version is active" } + if s.SiteConfig.Flags&config.FlagDisable != 0 { + return "This site is inacessible because it is disabled" + } return "This site is live" } + +func (s *Site) ConvertFlagsToString() string { + var bits []string + bitNames := []string{"D", "T", "I", "P", "R"} + + for i := 0; i < len(bitNames); i++ { + if s.SiteConfig.Flags&(1< .flags:not(.header) { + font-family: monospace; +} + .sites-table > .name > span:nth-child(2) { font-size: smaller; } diff --git a/web/mux.go b/web/mux.go index b6a5528..0821723 100644 --- a/web/mux.go +++ b/web/mux.go @@ -16,6 +16,8 @@ func NewMux(cfg *config.MainConfig, siteIndex *index.SiteIndex) *http.ServeMux { mux.HandleFunc("GET /site/{site}/", handler.GetSite(cfg, siteIndex)) mux.HandleFunc("GET /site/{site}/upload", handler.GetUpload(siteIndex)) mux.HandleFunc("POST /site/{site}/upload", handler.PostUpload(cfg, siteIndex)) + mux.HandleFunc("GET /site/{site}/flags", handler.GetFlags(siteIndex)) + mux.HandleFunc("POST /site/{site}/flags", handler.PostFlags(cfg, siteIndex)) return mux } -- cgit v1.2.3-70-g09d2