Rename env vars prefix to ND_

This commit is contained in:
Deluan 2020-01-24 01:29:31 -05:00
parent d48ddacaba
commit bff6f3a4bd
18 changed files with 42 additions and 42 deletions

View file

@ -44,9 +44,9 @@ COPY --from=gobuilder /src/navidrome /app/
COPY --from=gobuilder /tmp/ffmpeg*/ffmpeg /usr/bin/ COPY --from=gobuilder /tmp/ffmpeg*/ffmpeg /usr/bin/
VOLUME ["/data", "/music"] VOLUME ["/data", "/music"]
ENV SONIC_DBPATH /data/navidrome.db ENV ND_DBPATH /data/navidrome.db
ENV SONIC_MUSICFOLDER /music ENV ND_MUSICFOLDER /music
ENV SONIC_LOGLEVEL info ENV ND_LOGLEVEL info
EXPOSE 4533 EXPOSE 4533
WORKDIR /app WORKDIR /app

View file

@ -50,10 +50,10 @@ services:
- "4533:4533" - "4533:4533"
environment: environment:
# All options with their default values: # All options with their default values:
SONIC_MUSICFOLDER: /music ND_MUSICFOLDER: /music
SONIC_PORT: 4533 ND_PORT: 4533
SONIC_SCANINTERVAL: 10s ND_SCANINTERVAL: 10s
SONIC_LOGLEVEL: debug ND_LOGLEVEL: debug
volumes: volumes:
- "./data:/data" - "./data:/data"
- "/Users/deluan/Music/iTunes/iTunes Media/Music:/music" - "/Users/deluan/Music/iTunes/iTunes Media/Music:/music"

View file

@ -8,7 +8,7 @@ import (
"github.com/koding/multiconfig" "github.com/koding/multiconfig"
) )
type sonic struct { type nd struct {
Port string `default:"4533"` Port string `default:"4533"`
MusicFolder string `default:"./music"` MusicFolder string `default:"./music"`
DbPath string `default:"./data/navidrome.db"` DbPath string `default:"./data/navidrome.db"`
@ -30,20 +30,20 @@ type sonic struct {
DevInitialPassword string `default:""` DevInitialPassword string `default:""`
} }
var Sonic *sonic var Server *nd
func LoadFromFlags() { func LoadFromFlags() {
l := &multiconfig.FlagLoader{} l := &multiconfig.FlagLoader{}
l.Load(Sonic) l.Load(Server)
} }
func LoadFromEnv() { func LoadFromEnv() {
port := os.Getenv("PORT") port := os.Getenv("PORT")
if port != "" { if port != "" {
Sonic.Port = port Server.Port = port
} }
l := &multiconfig.EnvironmentLoader{} l := &multiconfig.EnvironmentLoader{}
err := l.Load(Sonic) err := l.Load(Server)
if err != nil { if err != nil {
log.Error("Error parsing configuration from environment") log.Error("Error parsing configuration from environment")
} }
@ -51,12 +51,12 @@ func LoadFromEnv() {
func LoadFromTags() { func LoadFromTags() {
l := &multiconfig.TagLoader{} l := &multiconfig.TagLoader{}
l.Load(Sonic) l.Load(Server)
} }
func LoadFromFile(tomlFile string) { func LoadFromFile(tomlFile string) {
l := &multiconfig.TOMLLoader{Path: tomlFile} l := &multiconfig.TOMLLoader{Path: tomlFile}
err := l.Load(Sonic) err := l.Load(Server)
if err != nil { if err != nil {
log.Error("Error loading configuration file", "file", tomlFile, err) log.Error("Error loading configuration file", "file", tomlFile, err)
} }
@ -72,10 +72,10 @@ func Load() {
LoadFromLocalFile() LoadFromLocalFile()
LoadFromEnv() LoadFromEnv()
LoadFromFlags() LoadFromFlags()
log.SetLogLevelString(Sonic.LogLevel) log.SetLogLevelString(Server.LogLevel)
} }
func init() { func init() {
Sonic = new(sonic) Server = new(nd)
LoadFromTags() LoadFromTags()
} }

View file

@ -8,9 +8,9 @@ services:
- "4533:4533" - "4533:4533"
environment: environment:
# See all options and defaults in conf/configuration.go # See all options and defaults in conf/configuration.go
SONIC_PORT: 4533 ND_PORT: 4533
SONIC_SCANINTERVAL: 5s ND_SCANINTERVAL: 5s
SONIC_LOGLEVEL: debug ND_LOGLEVEL: debug
volumes: volumes:
- "./data:/data" - "./data:/data"
- "/Users/deluan/Music/iTunes/iTunes Media/Music:/music" - "/Users/deluan/Music/iTunes/iTunes Media/Music:/music"

View file

@ -16,7 +16,7 @@ import (
func Stream(ctx context.Context, path string, bitRate int, maxBitRate int, w io.Writer) error { func Stream(ctx context.Context, path string, bitRate int, maxBitRate int, w io.Writer) error {
var f io.Reader var f io.Reader
var err error var err error
enabled := !conf.Sonic.DisableDownsampling enabled := !conf.Server.DisableDownsampling
if enabled && maxBitRate > 0 && bitRate > maxBitRate { if enabled && maxBitRate > 0 && bitRate > maxBitRate {
f, err = downsample(ctx, path, maxBitRate) f, err = downsample(ctx, path, maxBitRate)
} else { } else {
@ -46,7 +46,7 @@ func downsample(ctx context.Context, path string, maxBitRate int) (f io.Reader,
} }
func createDownsamplingCommand(path string, maxBitRate int) (string, []string) { func createDownsamplingCommand(path string, maxBitRate int) (string, []string) {
cmd := conf.Sonic.DownsampleCommand cmd := conf.Server.DownsampleCommand
split := strings.Split(cmd, " ") split := strings.Split(cmd, " ")
for i, s := range split { for i, s := range split {

View file

@ -8,12 +8,12 @@ import (
func main() { func main() {
conf.Load() conf.Load()
if !conf.Sonic.DevDisableBanner { if !conf.Server.DevDisableBanner {
server.ShowBanner() server.ShowBanner()
} }
a := CreateServer(conf.Sonic.MusicFolder) a := CreateServer(conf.Server.MusicFolder)
a.MountRouter("/rest", CreateSubsonicAPIRouter()) a.MountRouter("/rest", CreateSubsonicAPIRouter())
a.MountRouter("/app", CreateAppRouter("/app")) a.MountRouter("/app", CreateAppRouter("/app"))
a.Run(":" + conf.Sonic.Port) a.Run(":" + conf.Server.Port)
} }

View file

@ -28,7 +28,7 @@ type artistRepository struct {
func NewArtistRepository(o orm.Ormer) model.ArtistRepository { func NewArtistRepository(o orm.Ormer) model.ArtistRepository {
r := &artistRepository{} r := &artistRepository{}
r.ormer = o r.ormer = o
r.indexGroups = utils.ParseIndexGroups(conf.Sonic.IndexGroups) r.indexGroups = utils.ParseIndexGroups(conf.Server.IndexGroups)
r.tableName = "artist" r.tableName = "artist"
return r return r
} }

View file

@ -15,7 +15,7 @@ func NewMediaFolderRepository(o orm.Ormer) model.MediaFolderRepository {
} }
func (*mediaFolderRepository) GetAll() (model.MediaFolders, error) { func (*mediaFolderRepository) GetAll() (model.MediaFolders, error) {
mediaFolder := model.MediaFolder{ID: "0", Path: conf.Sonic.MusicFolder} mediaFolder := model.MediaFolder{ID: "0", Path: conf.Server.MusicFolder}
mediaFolder.Name = "Music Library" mediaFolder.Name = "Music Library"
result := make(model.MediaFolders, 1) result := make(model.MediaFolders, 1)
result[0] = mediaFolder result[0] = mediaFolder

View file

@ -27,7 +27,7 @@ type SQLStore struct {
func New() model.DataStore { func New() model.DataStore {
once.Do(func() { once.Do(func() {
dbPath := conf.Sonic.DbPath dbPath := conf.Server.DbPath
if dbPath == ":memory:" { if dbPath == ":memory:" {
dbPath = "file::memory:?cache=shared" dbPath = "file::memory:?cache=shared"
} }
@ -114,7 +114,7 @@ func (db *SQLStore) getOrmer() orm.Ormer {
} }
func initORM(dbPath string) error { func initORM(dbPath string) error {
verbose := conf.Sonic.LogLevel == "trace" verbose := conf.Server.LogLevel == "trace"
orm.Debug = verbose orm.Debug = verbose
if strings.Contains(dbPath, "postgres") { if strings.Contains(dbPath, "postgres") {
driver = "postgres" driver = "postgres"

View file

@ -60,9 +60,9 @@ func P(path string) string {
var _ = Describe("Initialize test DB", func() { var _ = Describe("Initialize test DB", func() {
BeforeSuite(func() { BeforeSuite(func() {
//log.SetLevel(log.LevelTrace) //log.SetLevel(log.LevelTrace)
//conf.Sonic.DbPath, _ = ioutil.TempDir("", "navidrome_tests") //conf.Server.DbPath, _ = ioutil.TempDir("", "navidrome_tests")
//os.MkdirAll(conf.Sonic.DbPath, 0700) //os.MkdirAll(conf.Server.DbPath, 0700)
conf.Sonic.DbPath = ":memory:" conf.Server.DbPath = ":memory:"
ds := New() ds := New()
artistRepo := ds.Artist() artistRepo := ds.Artist()
for _, a := range testArtists { for _, a := range testArtists {

View file

@ -216,7 +216,7 @@ func (m *Metadata) parseDuration(tagName string) int {
} }
func createProbeCommand(inputs []string) (string, []string) { func createProbeCommand(inputs []string) (string, []string) {
cmd := conf.Sonic.ProbeCommand cmd := conf.Server.ProbeCommand
split := strings.Split(cmd, " ") split := strings.Split(cmd, " ")
args := make([]string, 0) args := make([]string, 0)

View file

@ -20,7 +20,7 @@ func xTestScanner(t *testing.T) {
var _ = XDescribe("TODO: REMOVE", func() { var _ = XDescribe("TODO: REMOVE", func() {
It("WORKS!", func() { It("WORKS!", func() {
conf.Sonic.DbPath = "./testDB" conf.Server.DbPath = "./testDB"
log.SetLevel(log.LevelDebug) log.SetLevel(log.LevelDebug)
ds := persistence.New() ds := persistence.New()

View file

@ -45,7 +45,7 @@ func (app *Router) routes() http.Handler {
r.Post("/login", Login(app.ds)) r.Post("/login", Login(app.ds))
r.Route("/api", func(r chi.Router) { r.Route("/api", func(r chi.Router) {
if !conf.Sonic.DevDisableAuthentication { if !conf.Server.DevDisableAuthentication {
r.Use(jwtauth.Verifier(TokenAuth)) r.Use(jwtauth.Verifier(TokenAuth))
r.Use(Authenticator) r.Use(Authenticator)
} }

View file

@ -53,8 +53,8 @@ func createDefaultUser(ds model.DataStore) error {
id, _ := uuid.NewRandom() id, _ := uuid.NewRandom()
random, _ := uuid.NewRandom() random, _ := uuid.NewRandom()
initialPassword := random.String() initialPassword := random.String()
if conf.Sonic.DevInitialPassword != "" { if conf.Server.DevInitialPassword != "" {
initialPassword = conf.Sonic.DevInitialPassword initialPassword = conf.Server.DevInitialPassword
} }
log.Warn("Creating initial user. Please change the password!", "user", consts.InitialUserName, "password", initialPassword) log.Warn("Creating initial user. Please change the password!", "user", consts.InitialUserName, "password", initialPassword)
initialUser := model.User{ initialUser := model.User{

View file

@ -68,9 +68,9 @@ func (a *Server) initRoutes() {
} }
func (a *Server) initScanner() { func (a *Server) initScanner() {
interval, err := time.ParseDuration(conf.Sonic.ScanInterval) interval, err := time.ParseDuration(conf.Server.ScanInterval)
if err != nil { if err != nil {
log.Error("Invalid interval specification. Using default of 5m", "conf", conf.Sonic.ScanInterval, err) log.Error("Invalid interval specification. Using default of 5m", "conf", conf.Server.ScanInterval, err)
interval = 5 * time.Minute interval = 5 * time.Minute
} else { } else {
log.Info("Starting scanner", "interval", interval.String()) log.Info("Starting scanner", "interval", interval.String())
@ -80,7 +80,7 @@ func (a *Server) initScanner() {
for { for {
err := a.Scanner.RescanAll(false) err := a.Scanner.RescanAll(false)
if err != nil { if err != nil {
log.Error("Error scanning media folder", "folder", conf.Sonic.MusicFolder, err) log.Error("Error scanning media folder", "folder", conf.Server.MusicFolder, err)
} }
time.Sleep(interval) time.Sleep(interval)
} }

View file

@ -48,7 +48,7 @@ func (api *Router) routes() http.Handler {
r.Use(checkRequiredParameters) r.Use(checkRequiredParameters)
// Add validation middleware if not disabled // Add validation middleware if not disabled
if !conf.Sonic.DevDisableAuthentication { if !conf.Server.DevDisableAuthentication {
r.Use(authenticate(api.Users)) r.Use(authenticate(api.Users))
// TODO Validate version // TODO Validate version
} }

View file

@ -41,7 +41,7 @@ func (c *BrowsingController) getArtistIndex(r *http.Request, ifModifiedSince tim
} }
res := &responses.Indexes{ res := &responses.Indexes{
IgnoredArticles: conf.Sonic.IgnoredArticles, IgnoredArticles: conf.Server.IgnoredArticles,
LastModified: fmt.Sprint(utils.ToMillis(lastModified)), LastModified: fmt.Sprint(utils.ToMillis(lastModified)),
} }

View file

@ -7,7 +7,7 @@ import (
) )
func NoArticle(name string) string { func NoArticle(name string) string {
articles := strings.Split(conf.Sonic.IgnoredArticles, " ") articles := strings.Split(conf.Server.IgnoredArticles, " ")
for _, a := range articles { for _, a := range articles {
n := strings.TrimPrefix(name, a+" ") n := strings.TrimPrefix(name, a+" ")
if n != name { if n != name {