1
0

Simplifying configuration via introducing a -work-dir option.

This commit is contained in:
Alexander Andreev 2024-06-25 03:31:00 +04:00
parent 41aea2112a
commit e331370bdb
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34
2 changed files with 13 additions and 16 deletions

View File

@ -13,6 +13,7 @@ import (
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
"path"
"syscall" "syscall"
"git.arav.su/Arav/httpr" "git.arav.su/Arav/httpr"
@ -20,10 +21,8 @@ import (
var ( var (
listenAddress = flag.String("listen", "/var/run/dwelling-radio/sock", "listen address (ip:port|unix_path)") listenAddress = flag.String("listen", "/var/run/dwelling-radio/sock", "listen address (ip:port|unix_path)")
filelistPath = flag.String("filelist", "/mnt/data/appdata/radio/filelist.html", "path to a filelist.html file") workDirPath = flag.String("work-dir", "/mnt/data/appdata/radio", "path to a working directory")
playlistPath = flag.String("playlist", "", "path to a playlist") playlistName = flag.String("playlist", "all-rand", "a playlist name")
fallbackSong = flag.String("fallback-song", "", "path to a fallback song")
statisticsDbPath = flag.String("db", "/mnt/data/appdata/radio/statistics.db3", "path to a statistics database")
songListLen = flag.Int64("list-length", 10, "number of songs to show in last N songs table") songListLen = flag.Int64("list-length", 10, "number of songs to show in last N songs table")
showVersion = flag.Bool("v", false, "show version") showVersion = flag.Bool("v", false, "show version")
@ -40,7 +39,7 @@ func main() {
return return
} }
stats, err := sqlite_stats.New(*statisticsDbPath) stats, err := sqlite_stats.New(path.Join(*workDirPath, "statistics.db3"))
if err != nil { if err != nil {
log.Fatalln("Statistics:", err) log.Fatalln("Statistics:", err)
} }
@ -49,7 +48,7 @@ func main() {
currentSong := radio.Song{} currentSong := radio.Song{}
lstnrs := radio.NewListenerCounter() lstnrs := radio.NewListenerCounter()
plylst, err := radio.NewPlaylist(*playlistPath, true) plylst, err := radio.NewPlaylist(path.Join(*workDirPath, "playlists", *playlistName), true)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
@ -68,14 +67,14 @@ func main() {
}) })
r.Handler(http.MethodGet, "/filelist", func(w http.ResponseWriter, r *http.Request) { r.Handler(http.MethodGet, "/filelist", func(w http.ResponseWriter, r *http.Request) {
if *filelistPath == "" { data, err := os.ReadFile(path.Join(*workDirPath, "filelist.html"))
http.Error(w, "no filelist", http.StatusNotFound) if err != nil {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return return
} }
w.Header().Add("Content-Type", "text/html") w.Header().Add("Content-Type", "text/html")
w.Header().Add("Link", "<"+utils.Site(r.Host)+"/filelist>; rel=\"canonical\"") w.Header().Add("Link", "<"+utils.Site(r.Host)+"/filelist>; rel=\"canonical\"")
data, _ := os.ReadFile(*filelistPath)
w.Write(data) w.Write(data)
}) })
@ -87,7 +86,7 @@ func main() {
r.ServeStatic("/assets/*filepath", web.Assets()) r.ServeStatic("/assets/*filepath", web.Assets())
djh := ihttp.NewDJHandlers(lstnrs, plylst, stats, &currentSong, *songListLen, *fallbackSong) djh := ihttp.NewDJHandlers(lstnrs, plylst, stats, &currentSong, *songListLen, path.Join(*workDirPath, "fallback.ogg"))
s := r.Sub("/api") s := r.Sub("/api")

View File

@ -8,10 +8,8 @@ Type=simple
Restart=on-failure Restart=on-failure
DynamicUser=yes DynamicUser=yes
ExecStart=/usr/bin/dwelling-radio -listen /var/run/dwelling-radio/sock \ ExecStart=/usr/bin/dwelling-radio -listen /var/run/dwelling-radio/sock \
-filelist /mnt/data/appdata/radio/filelist.html \ -work-dir /mnt/data/appdata/radio \
-playlist /mnt/data/appdata/radio/playlists/all-rand \ -playlist all-rand \
-fallback-song /mnt/data/appdata/radio/fallback.ogg \
-db /mnt/data/appdata/radio/statistics.db3 \
-lst-len 10 -lst-len 10
ReadOnlyPaths=/ ReadOnlyPaths=/