also retry requests if connection closed; add /_/info endpoint

This commit is contained in:
Laptop
2024-10-26 21:34:59 +03:00
parent 796b47b9be
commit 2e1dabdc13
3 changed files with 26 additions and 1 deletions

View File

@@ -18,6 +18,9 @@ const ImageCacheControl = "max-age=600; public" // 10 minutes by default, only u
// proxy streams (hls playlist files and track parts)
const ProxyStreams = false
// enable /_/info endpoint (shows if some settings are enabled/disabled)
const InstanceInfo = true
// time-to-live for clientid cache
// larger number will improve performance (no need to recheck everytime) but might make soundcloak briefly unusable for a larger amount of time if the client id is invalidated
const ClientIDTTL = 30 * time.Minute

View File

@@ -123,7 +123,7 @@ func DoWithRetry(httpc *fasthttp.HostClient, req *fasthttp.Request, resp *fastht
return nil
}
if !os.IsTimeout(err) && err != fasthttp.ErrTimeout {
if !os.IsTimeout(err) && err != fasthttp.ErrTimeout && err != fasthttp.ErrConnectionClosed {
return
}
}

22
main.go
View File

@@ -142,6 +142,28 @@ func main() {
proxystreams.Load(app)
}
if cfg.InstanceInfo {
type info struct {
ProxyImages bool
ProxyStreams bool
FullyPreloadTrack bool
}
data, err := cfg.JSON.Marshal(info{
ProxyImages: cfg.ProxyImages,
ProxyStreams: cfg.ProxyStreams,
FullyPreloadTrack: cfg.FullyPreloadTrack,
})
if err != nil {
log.Println("Failed to marshal instance info:", err)
}
app.Get("/_/info", func(c *fiber.Ctx) error {
c.Set("Content-Type", "application/json")
return c.Send(data)
})
}
app.Get("/:user/sets", func(c *fiber.Ctx) error {
user, err := sc.GetUser(c.Params("user"))
if err != nil {