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"
"os"
"os/signal"
"path"
"syscall"
"git.arav.su/Arav/httpr"
@ -20,10 +21,8 @@ import (
var (
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")
playlistPath = flag.String("playlist", "", "path to a playlist")
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")
workDirPath = flag.String("work-dir", "/mnt/data/appdata/radio", "path to a working directory")
playlistName = flag.String("playlist", "all-rand", "a playlist name")
songListLen = flag.Int64("list-length", 10, "number of songs to show in last N songs table")
showVersion = flag.Bool("v", false, "show version")
@ -40,7 +39,7 @@ func main() {
return
}
stats, err := sqlite_stats.New(*statisticsDbPath)
stats, err := sqlite_stats.New(path.Join(*workDirPath, "statistics.db3"))
if err != nil {
log.Fatalln("Statistics:", err)
}
@ -49,7 +48,7 @@ func main() {
currentSong := radio.Song{}
lstnrs := radio.NewListenerCounter()
plylst, err := radio.NewPlaylist(*playlistPath, true)
plylst, err := radio.NewPlaylist(path.Join(*workDirPath, "playlists", *playlistName), true)
if err != nil {
log.Fatalln(err)
}
@ -68,14 +67,14 @@ func main() {
})
r.Handler(http.MethodGet, "/filelist", func(w http.ResponseWriter, r *http.Request) {
if *filelistPath == "" {
http.Error(w, "no filelist", http.StatusNotFound)
data, err := os.ReadFile(path.Join(*workDirPath, "filelist.html"))
if err != nil {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
w.Header().Add("Content-Type", "text/html")
w.Header().Add("Link", "<"+utils.Site(r.Host)+"/filelist>; rel=\"canonical\"")
data, _ := os.ReadFile(*filelistPath)
w.Write(data)
})
@ -87,7 +86,7 @@ func main() {
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")

View File

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