diff options
Diffstat (limited to 'app/config.go')
| -rw-r--r-- | app/config.go | 69 |
1 files changed, 53 insertions, 16 deletions
diff --git a/app/config.go b/app/config.go index c848b9c..3fb8103 100644 --- a/app/config.go +++ b/app/config.go @@ -3,14 +3,18 @@ package app import ( "encoding/json" "os" + "regexp" + "strconv" "time" + + "git.macaw.me/skunky/devianter" ) type cache_config struct { Enabled bool Path string MaxSize int64 `json:"max-size"` - Lifetime int64 + Lifetime string UpdateInterval int64 `json:"update-interval"` } @@ -20,6 +24,7 @@ type config struct { BasePath string `json:"base-path"` Cache cache_config Proxy, Nsfw bool + UserAgent string `json:"user-agent"` DownloadProxy string `json:"download-proxy"` Dirs []string `json:"dirs-to-memory"` } @@ -33,31 +38,36 @@ var CFG = config{ Path: "cache", UpdateInterval: 1, }, - Dirs: []string{"html", "css"}, - Proxy: true, - Nsfw: true, + Dirs: []string{"html", "css"}, + UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36", + Proxy: true, + Nsfw: true, } +var lifetimeParsed int64 + func ExecuteConfig() { go func() { - defer func() { - if r := recover(); r != nil { - recover() - } - }() for { - Templates["instances.json"] = string(Download("https://git.macaw.me/skunky/SkunkyArt/raw/branch/master/instances.json").Body) - time.Sleep(1 * time.Second) + func() { + defer func() { + if r := recover(); r != nil { + recover() + } + }() + Templates["instances.json"] = string(Download("https://git.macaw.me/skunky/SkunkyArt/raw/branch/master/instances.json").Body) + }() + time.Sleep(1 * time.Hour) } }() - const helpmsg = `SkunkyArt v1.3 [refactoring] + const helpmsg = `SkunkyArt v1.3.1 [CSS improvements for mobile and strips on Daily Deviations] Usage: - [-c|--config] - path to config - [-h|--help] - returns this message Example: ./skunkyart -c config.json -Copyright lost+skunk, X11. https://git.macaw.me/skunky/skunkyart/src/tag/v1.3` +Copyright lost+skunk, X11. https://git.macaw.me/skunky/skunkyart/src/tag/v1.3.1` a := os.Args for n, x := range a { @@ -75,15 +85,42 @@ Copyright lost+skunk, X11. https://git.macaw.me/skunky/skunkyart/src/tag/v1.3` if CFG.cfg != "" { f, err := os.ReadFile(CFG.cfg) - try_with_exitstatus(err, 1) + tryWithExitStatus(err, 1) - try_with_exitstatus(json.Unmarshal(f, &CFG), 1) + tryWithExitStatus(json.Unmarshal(f, &CFG), 1) if CFG.Cache.Enabled && !CFG.Proxy { exit("Incompatible settings detected: cannot use caching media content without proxy", 1) } - if CFG.Cache.MaxSize != 0 || CFG.Cache.Lifetime != 0 { + if CFG.Cache.Enabled { + if CFG.Cache.Lifetime != "" { + var duration int64 + day := 24 * time.Hour.Milliseconds() + numstr := regexp.MustCompile("[0-9]+").FindAllString(CFG.Cache.Lifetime, -1) + num, _ := strconv.Atoi(numstr[len(numstr)-1]) + + switch unit := CFG.Cache.Lifetime[len(CFG.Cache.Lifetime)-1:]; unit { + case "i": + duration = time.Minute.Milliseconds() + case "h": + duration = time.Hour.Milliseconds() + case "d": + duration = day + case "w": + duration = day * 7 + case "m": + duration = day * 30 + case "y": + duration = day * 360 + default: + exit("Invalid unit specified: "+unit, 1) + } + + lifetimeParsed = duration * int64(num) + } + CFG.Cache.MaxSize /= 1024 ^ 2 go InitCacheSystem() } + devianter.UserAgent = CFG.UserAgent } } |
