2024-06-13 20:56:03 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2024-07-05 21:46:25 +00:00
|
|
|
"encoding/json"
|
2024-06-13 20:56:03 +00:00
|
|
|
"os"
|
2024-07-13 18:32:04 +00:00
|
|
|
"time"
|
2024-06-13 20:56:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type cache_config struct {
|
2024-07-06 17:06:04 +00:00
|
|
|
Enabled bool
|
|
|
|
Path string
|
|
|
|
MaxSize int64 `json:"max-size"`
|
|
|
|
Lifetime int64
|
|
|
|
UpdateInterval int64 `json:"update-interval"`
|
2024-06-13 20:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type config struct {
|
2024-07-13 18:32:04 +00:00
|
|
|
cfg string
|
|
|
|
Listen string
|
|
|
|
BasePath string `json:"base-path"`
|
|
|
|
Cache cache_config
|
|
|
|
Proxy, Nsfw bool
|
|
|
|
DownloadProxy string `json:"download-proxy"`
|
|
|
|
Dirs []string `json:"dirs-to-memory"`
|
2024-06-13 20:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var CFG = config{
|
|
|
|
cfg: "config.json",
|
|
|
|
Listen: "127.0.0.1:3003",
|
2024-07-05 21:46:25 +00:00
|
|
|
BasePath: "/",
|
2024-06-13 20:56:03 +00:00
|
|
|
Cache: cache_config{
|
2024-07-06 17:06:04 +00:00
|
|
|
Enabled: true,
|
|
|
|
Path: "cache",
|
|
|
|
UpdateInterval: 1,
|
2024-06-13 20:56:03 +00:00
|
|
|
},
|
2024-07-13 18:32:04 +00:00
|
|
|
Dirs: []string{"html", "css"},
|
|
|
|
Proxy: true,
|
|
|
|
Nsfw: true,
|
2024-06-13 20:56:03 +00:00
|
|
|
}
|
|
|
|
|
2024-07-05 21:46:25 +00:00
|
|
|
func ExecuteConfig() {
|
2024-07-13 18:32:04 +00:00
|
|
|
go func() {
|
2024-07-13 19:12:50 +00:00
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
recover()
|
|
|
|
}
|
|
|
|
}()
|
2024-07-13 18:32:04 +00:00
|
|
|
for {
|
|
|
|
Templates["instances.json"] = string(Download("https://git.macaw.me/skunky/SkunkyArt/raw/branch/master/instances.json").Body)
|
2024-07-13 19:12:50 +00:00
|
|
|
time.Sleep(1 * time.Second)
|
2024-07-05 21:46:25 +00:00
|
|
|
}
|
2024-07-13 18:32:04 +00:00
|
|
|
}()
|
2024-07-05 21:46:25 +00:00
|
|
|
|
2024-07-13 18:32:04 +00:00
|
|
|
const helpmsg = `SkunkyArt v1.3 [refactoring]
|
2024-06-13 20:56:03 +00:00
|
|
|
Usage:
|
2024-07-05 21:46:25 +00:00
|
|
|
- [-c|--config] - path to config
|
|
|
|
- [-h|--help] - returns this message
|
2024-06-13 20:56:03 +00:00
|
|
|
Example:
|
2024-07-05 21:46:25 +00:00
|
|
|
./skunkyart -c config.json
|
2024-07-13 18:32:04 +00:00
|
|
|
Copyright lost+skunk, X11. https://git.macaw.me/skunky/skunkyart/src/tag/v1.3`
|
2024-07-05 21:46:25 +00:00
|
|
|
|
2024-07-13 18:32:04 +00:00
|
|
|
a := os.Args
|
|
|
|
for n, x := range a {
|
|
|
|
switch x {
|
|
|
|
case "-c", "--config":
|
|
|
|
if len(a) >= 3 {
|
|
|
|
CFG.cfg = a[n+1]
|
|
|
|
} else {
|
|
|
|
exit("Not enought arguments", 1)
|
2024-07-05 21:46:25 +00:00
|
|
|
}
|
2024-07-13 18:32:04 +00:00
|
|
|
case "-h", "--help":
|
|
|
|
exit(helpmsg, 0)
|
|
|
|
}
|
|
|
|
}
|
2024-07-05 21:46:25 +00:00
|
|
|
|
2024-07-13 18:32:04 +00:00
|
|
|
if CFG.cfg != "" {
|
|
|
|
f, err := os.ReadFile(CFG.cfg)
|
|
|
|
try_with_exitstatus(err, 1)
|
|
|
|
|
|
|
|
try_with_exitstatus(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 {
|
|
|
|
go InitCacheSystem()
|
2024-06-13 20:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|