mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-31 07:59:37 +05:00
small fixes
This commit is contained in:
@@ -179,20 +179,24 @@ This will run soundcloak as a daemon (remove the -d part of the command to just
|
||||
<summary>Click to view</summary>
|
||||
|
||||
You can only configure in one of the two ways:
|
||||
|
||||
- Using config file (`soundcloak.json` in current directory // your own path and filename)
|
||||
- Using environment variables (`SOUNDCLOAK_CONFIG` must be set to `FROM_ENV`!)
|
||||
|
||||
Some notes:
|
||||
|
||||
- When specifying time, specify it in seconds.
|
||||
|
||||
|
||||
| JSON key | Environment variable | Default value | Description |
|
||||
| :------------------------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| None | SOUNDCLOAK_CONFIG | soundcloak.json | File to load soundcloak config from. If set to `FROM_ENV`, soundcloak loads the config from environment variables. |
|
||||
| None | SOUNDCLOAK_CONFIG | soundcloak.json | File to load soundcloak config from. If set to`FROM_ENV`, soundcloak loads the config from environment variables. |
|
||||
| DefaultPreferences | DEFAULT_PREFERENCES | {"Player": "hls", "ProxyStreams": false, "FullyPreloadTrack": false, "ProxyImages": false, "ParseDescriptions": true} | see /_/preferences page, default values adapt to your config (Player: "restream" if Restream, else "hls", ProxyStreams and ProxyImages will be same as respective config values) |
|
||||
| ProxyImages | PROXY_IMAGES | false | Enables proxying of images (user avatars, track covers etc) |
|
||||
| ImageCacheControl | IMAGE_CACHE_CONTROL | max-age=600, public, immutable | [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Contro) header value for proxied images. Cached for 10 minutes by default. |
|
||||
| ImageCacheControl | IMAGE_CACHE_CONTROL | max-age=600, public, immutable | [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) header value for proxied images. Cached for 10 minutes by default. |
|
||||
| ProxyStreams | PROXY_STREAMS | false | Enables proxying of song parts and hls playlist files |
|
||||
| Restream | RESTREAM | false | Enables Restream Player in settings and the /_/restream/:author/:track endpoint. This player can be used without JavaScript and also can be used for downloading songs. |
|
||||
| RestreamCacheControl | RESTREAM_CACHE_CONTROL | max-age=3600, public, immutable | [Cache-Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) header value for restreamed songs. Cached for 1 hour by default. |
|
||||
| ClientIDTTL | CLIENT_ID_TTL | 30 minutes | Time until ClientID cache expires. ClientID is used for authenticating with SoundCloud API |
|
||||
| UserTTL | USER_TTL | 10 minutes | Time until User profile cache expires |
|
||||
| UserCacheCleanDelay | USER_CACHE_CLEAN_DELAY | 2.5 minutes | Time between each cleanup of the cache (to remove expired users) |
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cfg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -56,7 +57,7 @@ var ProxyStreams = false
|
||||
// If this setting is set to true, ProxyStreams and FullyPreloadTrack will be ignored (you could count this as a replacement for having both as true, also should be a bit more effective)
|
||||
// You can also easily download the songs this way (right click => save audio as..., the only downside is that there is no metadata)
|
||||
var Restream = false
|
||||
var RestreamCacheControl = "max-age=604800, public, immutable"
|
||||
var RestreamCacheControl = "max-age=3600, public, immutable"
|
||||
|
||||
// enable /_/info endpoint (shows if some settings are enabled/disabled)
|
||||
var InstanceInfo = true
|
||||
@@ -178,13 +179,22 @@ func boolean(in string) bool {
|
||||
return strings.Trim(strings.ToLower(in), " ") == "true"
|
||||
}
|
||||
|
||||
type wrappedError struct {
|
||||
err error
|
||||
fault string
|
||||
}
|
||||
|
||||
func (w wrappedError) Error() string {
|
||||
return fmt.Sprintf("error loading %s: %s", w.fault, w.err)
|
||||
}
|
||||
|
||||
func fromEnv() error {
|
||||
env := os.Getenv("DEFAULT_PREFERENCES")
|
||||
if env != "" {
|
||||
var p Preferences
|
||||
err := json.Unmarshal([]byte(env), &p)
|
||||
if err != nil {
|
||||
return err
|
||||
return wrappedError{err, "DEFAULT_PREFERENCES"}
|
||||
}
|
||||
|
||||
loadDefaultPreferences(p)
|
||||
@@ -226,7 +236,7 @@ func fromEnv() error {
|
||||
if env != "" {
|
||||
num, err := strconv.ParseInt(env, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
return wrappedError{err, "CLIENT_ID_TTL"}
|
||||
}
|
||||
|
||||
ClientIDTTL = time.Duration(num) * time.Second
|
||||
@@ -236,7 +246,7 @@ func fromEnv() error {
|
||||
if env != "" {
|
||||
num, err := strconv.ParseInt(env, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
return wrappedError{err, "USER_TTL"}
|
||||
}
|
||||
|
||||
UserTTL = time.Duration(num) * time.Second
|
||||
@@ -246,7 +256,7 @@ func fromEnv() error {
|
||||
if env != "" {
|
||||
num, err := strconv.ParseInt(env, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
return wrappedError{err, "USER_CACHE_CLEAN_DELAY"}
|
||||
}
|
||||
|
||||
UserCacheCleanDelay = time.Duration(num) * time.Second
|
||||
@@ -256,7 +266,7 @@ func fromEnv() error {
|
||||
if env != "" {
|
||||
num, err := strconv.ParseInt(env, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
return wrappedError{err, "TRACK_TTL"}
|
||||
}
|
||||
|
||||
TrackTTL = time.Duration(num) * time.Second
|
||||
@@ -266,7 +276,7 @@ func fromEnv() error {
|
||||
if env != "" {
|
||||
num, err := strconv.ParseInt(env, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
return wrappedError{err, "TRACK_CACHE_CLEAN_DELAY"}
|
||||
}
|
||||
|
||||
TrackCacheCleanDelay = time.Duration(num) * time.Second
|
||||
@@ -276,7 +286,7 @@ func fromEnv() error {
|
||||
if env != "" {
|
||||
num, err := strconv.ParseInt(env, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
return wrappedError{err, "PLAYLIST_TTL"}
|
||||
}
|
||||
|
||||
PlaylistTTL = time.Duration(num) * time.Second
|
||||
@@ -286,7 +296,7 @@ func fromEnv() error {
|
||||
if env != "" {
|
||||
num, err := strconv.ParseInt(env, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
return wrappedError{err, "PLAYLIST_CACHE_CLEAN_DELAY"}
|
||||
}
|
||||
|
||||
PlaylistCacheCleanDelay = time.Duration(num) * time.Second
|
||||
@@ -301,7 +311,7 @@ func fromEnv() error {
|
||||
if env != "" {
|
||||
num, err := strconv.ParseInt(env, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
return wrappedError{err, "DNS_CACHE_TTL"}
|
||||
}
|
||||
|
||||
DNSCacheTTL = time.Duration(num) * time.Second
|
||||
@@ -327,7 +337,7 @@ func fromEnv() error {
|
||||
var p []string
|
||||
err := json.Unmarshal([]byte(env), &p)
|
||||
if err != nil {
|
||||
return err
|
||||
return wrappedError{err, "TRUSTED_PROXIES"}
|
||||
}
|
||||
|
||||
TrustedProxies = p
|
||||
@@ -341,8 +351,12 @@ func init() {
|
||||
if env := os.Getenv("SOUNDCLOAK_CONFIG"); env == "FROM_ENV" {
|
||||
err := fromEnv()
|
||||
if err != nil {
|
||||
// So we only set default preferences if it fails to load that in
|
||||
if err.(wrappedError).fault == "DEFAULT_PREFERENCES" {
|
||||
defaultPreferences()
|
||||
}
|
||||
|
||||
log.Println("failed to load config from environment:", err)
|
||||
defaultPreferences()
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user