diff options
| author | Leonardo Bishop <me@leonardobishop.net> | 2025-07-13 21:23:34 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.net> | 2025-07-13 21:23:34 +0100 |
| commit | 684787bcb72aece2aa914597a3bc8788432e66f7 (patch) | |
| tree | a55fdcfc6f7f4d2f7ae86ba0a94e8d366f5c5cda /pkg | |
| parent | cdb75d3fcbc9339b897f8c6ff4d69a577f017393 (diff) | |
Add flags
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/config/site.go | 12 | ||||
| -rw-r--r-- | pkg/site/site.go | 22 | ||||
| -rw-r--r-- | pkg/upload/upload.go | 5 |
3 files changed, 39 insertions, 0 deletions
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<<i) != 0 { + bits = append(bits, bitNames[i]) + } else { + bits = append(bits, "-") + } + } + + return strings.Join(bits, "") +} diff --git a/pkg/upload/upload.go b/pkg/upload/upload.go index aff7803..1576431 100644 --- a/pkg/upload/upload.go +++ b/pkg/upload/upload.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strings" + "github.com/LMBishop/scrapbook/pkg/config" "github.com/LMBishop/scrapbook/pkg/index" ) @@ -19,6 +20,10 @@ func HandleUpload(siteName string, reader *multipart.Reader, index *index.SiteIn return "", fmt.Errorf("no such site: %s", siteName) } + if s.SiteConfig.Flags&config.FlagReadOnly != 0 { + return "", fmt.Errorf("site is read only: %s", siteName) + } + temp, err := os.CreateTemp(os.TempDir(), "scrapbook") if err != nil { return "", fmt.Errorf("failed to create temporary file: %w", err) |
