mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
Fixing static checks about passing nil context
This commit is contained in:
parent
95790b9eff
commit
03c3c192ed
17 changed files with 42 additions and 29 deletions
|
@ -1,6 +1,7 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -22,7 +23,7 @@ var (
|
||||||
|
|
||||||
func InitTokenAuth(ds model.DataStore) {
|
func InitTokenAuth(ds model.DataStore) {
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
secret, err := ds.Property(nil).DefaultGet(consts.JWTSecretKey, "not so secret")
|
secret, err := ds.Property(context.TODO()).DefaultGet(consts.JWTSecretKey, "not so secret")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("No JWT secret found in DB. Setting a temp one, but please report this error", err)
|
log.Error("No JWT secret found in DB. Setting a temp one, but please report this error", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
"github.com/deluan/navidrome/log"
|
"github.com/deluan/navidrome/log"
|
||||||
|
@ -14,7 +15,7 @@ import (
|
||||||
var _ = Describe("Cover", func() {
|
var _ = Describe("Cover", func() {
|
||||||
var cover Cover
|
var cover Cover
|
||||||
var ds model.DataStore
|
var ds model.DataStore
|
||||||
ctx := log.NewContext(nil)
|
ctx := log.NewContext(context.TODO())
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
ds = &persistence.MockDataStore{MockedTranscoding: &mockTranscodingRepository{}}
|
ds = &persistence.MockDataStore{MockedTranscoding: &mockTranscodingRepository{}}
|
||||||
|
|
|
@ -16,7 +16,7 @@ var _ = Describe("MediaStreamer", func() {
|
||||||
var streamer MediaStreamer
|
var streamer MediaStreamer
|
||||||
var ds model.DataStore
|
var ds model.DataStore
|
||||||
ffmpeg := &fakeFFmpeg{Data: "fake data"}
|
ffmpeg := &fakeFFmpeg{Data: "fake data"}
|
||||||
ctx := log.NewContext(nil)
|
ctx := log.NewContext(context.TODO())
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
ds = &persistence.MockDataStore{MockedTranscoding: &mockTranscodingRepository{}}
|
ds = &persistence.MockDataStore{MockedTranscoding: &mockTranscodingRepository{}}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
var _ = Describe("Players", func() {
|
var _ = Describe("Players", func() {
|
||||||
var players Players
|
var players Players
|
||||||
var repo *mockPlayerRepository
|
var repo *mockPlayerRepository
|
||||||
ctx := context.WithValue(log.NewContext(nil), "user", model.User{ID: "userid", UserName: "johndoe"})
|
ctx := context.WithValue(log.NewContext(context.TODO()), "user", model.User{ID: "userid", UserName: "johndoe"})
|
||||||
ctx = context.WithValue(ctx, "username", "johndoe")
|
ctx = context.WithValue(ctx, "username", "johndoe")
|
||||||
var beforeRegister time.Time
|
var beforeRegister time.Time
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ func (p *playlists) Delete(ctx context.Context, playlistId string) error {
|
||||||
if owner != pls.Owner {
|
if owner != pls.Owner {
|
||||||
return model.ErrNotAuthorized
|
return model.ErrNotAuthorized
|
||||||
}
|
}
|
||||||
return p.ds.Playlist(nil).Delete(playlistId)
|
return p.ds.Playlist(ctx).Delete(playlistId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *playlists) Update(ctx context.Context, playlistId string, name *string, idsToAdd []string, idxToRemove []int) error {
|
func (p *playlists) Update(ctx context.Context, playlistId string, name *string, idsToAdd []string, idxToRemove []int) error {
|
||||||
|
|
|
@ -70,7 +70,7 @@ var _ = Describe("Logger", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("can get data from the request's context", func() {
|
It("can get data from the request's context", func() {
|
||||||
ctx := NewContext(nil, "foo", "bar")
|
ctx := NewContext(context.TODO(), "foo", "bar")
|
||||||
req := httptest.NewRequest("get", "/", nil).WithContext(ctx)
|
req := httptest.NewRequest("get", "/", nil).WithContext(ctx)
|
||||||
|
|
||||||
Error(req, "Simple Message", "key1", "value1")
|
Error(req, "Simple Message", "key1", "value1")
|
||||||
|
|
|
@ -14,7 +14,7 @@ var _ = Describe("AlbumRepository", func() {
|
||||||
var repo model.AlbumRepository
|
var repo model.AlbumRepository
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
ctx := context.WithValue(log.NewContext(nil), "user", model.User{ID: "userid"})
|
ctx := context.WithValue(log.NewContext(context.TODO()), "user", model.User{ID: "userid"})
|
||||||
repo = NewAlbumRepository(ctx, orm.NewOrm())
|
repo = NewAlbumRepository(ctx, orm.NewOrm())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ var _ = Describe("ArtistRepository", func() {
|
||||||
var repo model.ArtistRepository
|
var repo model.ArtistRepository
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
ctx := context.WithValue(log.NewContext(nil), "user", model.User{ID: "userid"})
|
ctx := context.WithValue(log.NewContext(context.TODO()), "user", model.User{ID: "userid"})
|
||||||
repo = NewArtistRepository(ctx, orm.NewOrm())
|
repo = NewArtistRepository(ctx, orm.NewOrm())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package persistence_test
|
package persistence_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
"github.com/deluan/navidrome/log"
|
"github.com/deluan/navidrome/log"
|
||||||
"github.com/deluan/navidrome/model"
|
"github.com/deluan/navidrome/model"
|
||||||
|
@ -13,7 +15,7 @@ var _ = Describe("GenreRepository", func() {
|
||||||
var repo model.GenreRepository
|
var repo model.GenreRepository
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
repo = persistence.NewGenreRepository(log.NewContext(nil), orm.NewOrm())
|
repo = persistence.NewGenreRepository(log.NewContext(context.TODO()), orm.NewOrm())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns all records", func() {
|
It("returns all records", func() {
|
||||||
|
|
|
@ -16,7 +16,7 @@ var _ = Describe("MediaRepository", func() {
|
||||||
var mr model.MediaFileRepository
|
var mr model.MediaFileRepository
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
ctx := context.WithValue(log.NewContext(nil), "user", model.User{ID: "userid"})
|
ctx := context.WithValue(log.NewContext(context.TODO()), "user", model.User{ID: "userid"})
|
||||||
mr = NewMediaFileRepository(ctx, orm.NewOrm())
|
mr = NewMediaFileRepository(ctx, orm.NewOrm())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ func TestPersistence(t *testing.T) {
|
||||||
//conf.Server.Path = "./test-123.db"
|
//conf.Server.Path = "./test-123.db"
|
||||||
conf.Server.DbPath = "file::memory:?cache=shared"
|
conf.Server.DbPath = "file::memory:?cache=shared"
|
||||||
orm.RegisterDataBase("default", db.Driver, conf.Server.DbPath)
|
orm.RegisterDataBase("default", db.Driver, conf.Server.DbPath)
|
||||||
New()
|
|
||||||
db.EnsureLatestVersion()
|
db.EnsureLatestVersion()
|
||||||
log.SetLevel(log.LevelCritical)
|
log.SetLevel(log.LevelCritical)
|
||||||
RegisterFailHandler(Fail)
|
RegisterFailHandler(Fail)
|
||||||
|
@ -85,7 +84,7 @@ var _ = Describe("Initialize test DB", func() {
|
||||||
// TODO Load this data setup from file(s)
|
// TODO Load this data setup from file(s)
|
||||||
BeforeSuite(func() {
|
BeforeSuite(func() {
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
ctx := context.WithValue(log.NewContext(nil), "user", model.User{ID: "userid"})
|
ctx := context.WithValue(log.NewContext(context.TODO()), "user", model.User{ID: "userid"})
|
||||||
mr := NewMediaFileRepository(ctx, o)
|
mr := NewMediaFileRepository(ctx, o)
|
||||||
for _, s := range testSongs {
|
for _, s := range testSongs {
|
||||||
err := mr.Put(&s)
|
err := mr.Put(&s)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package persistence
|
package persistence
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
"github.com/deluan/navidrome/log"
|
"github.com/deluan/navidrome/log"
|
||||||
"github.com/deluan/navidrome/model"
|
"github.com/deluan/navidrome/model"
|
||||||
|
@ -12,7 +14,7 @@ var _ = Describe("PlaylistRepository", func() {
|
||||||
var repo model.PlaylistRepository
|
var repo model.PlaylistRepository
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
repo = NewPlaylistRepository(log.NewContext(nil), orm.NewOrm())
|
repo = NewPlaylistRepository(log.NewContext(context.TODO()), orm.NewOrm())
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Count", func() {
|
Describe("Count", func() {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package persistence
|
package persistence
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
. "github.com/deluan/navidrome/log"
|
"github.com/deluan/navidrome/log"
|
||||||
"github.com/deluan/navidrome/model"
|
"github.com/deluan/navidrome/model"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
@ -12,7 +14,7 @@ var _ = Describe("Property Repository", func() {
|
||||||
var pr model.PropertyRepository
|
var pr model.PropertyRepository
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
pr = NewPropertyRepository(NewContext(nil), orm.NewOrm())
|
pr = NewPropertyRepository(log.NewContext(context.TODO()), orm.NewOrm())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("saves and restore a new property", func() {
|
It("saves and restore a new property", func() {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package persistence
|
package persistence
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
"github.com/deluan/navidrome/log"
|
"github.com/deluan/navidrome/log"
|
||||||
"github.com/deluan/navidrome/model"
|
"github.com/deluan/navidrome/model"
|
||||||
|
@ -12,7 +14,7 @@ var _ = Describe("UserRepository", func() {
|
||||||
var repo model.UserRepository
|
var repo model.UserRepository
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
repo = NewUserRepository(log.NewContext(nil), orm.NewOrm())
|
repo = NewUserRepository(log.NewContext(context.TODO()), orm.NewOrm())
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Put/Get/FindByUsername", func() {
|
Describe("Put/Get/FindByUsername", func() {
|
||||||
|
|
|
@ -34,7 +34,7 @@ func (s *Scanner) Rescan(mediaFolder string, fullRescan bool) error {
|
||||||
log.Debug("Scanning folder (full scan)", "folder", mediaFolder)
|
log.Debug("Scanning folder (full scan)", "folder", mediaFolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := folderScanner.Scan(log.NewContext(nil), lastModifiedSince)
|
err := folderScanner.Scan(log.NewContext(context.TODO()), lastModifiedSince)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error importing MediaFolder", "folder", mediaFolder, err)
|
log.Error("Error importing MediaFolder", "folder", mediaFolder, err)
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func (s *Scanner) RescanAll(fullRescan bool) error {
|
||||||
func (s *Scanner) Status() []StatusInfo { return nil }
|
func (s *Scanner) Status() []StatusInfo { return nil }
|
||||||
|
|
||||||
func (s *Scanner) getLastModifiedSince(folder string) time.Time {
|
func (s *Scanner) getLastModifiedSince(folder string) time.Time {
|
||||||
ms, err := s.ds.Property(nil).Get(model.PropLastScan + "-" + folder)
|
ms, err := s.ds.Property(context.TODO()).Get(model.PropLastScan + "-" + folder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return time.Time{}
|
return time.Time{}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func (s *Scanner) updateLastModifiedSince(folder string, t time.Time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scanner) loadFolders() {
|
func (s *Scanner) loadFolders() {
|
||||||
fs, _ := s.ds.MediaFolder(nil).GetAll()
|
fs, _ := s.ds.MediaFolder(context.TODO()).GetAll()
|
||||||
for _, f := range fs {
|
for _, f := range fs {
|
||||||
log.Info("Configuring Media Folder", "name", f.Name, "path", f.Path)
|
log.Info("Configuring Media Folder", "name", f.Name, "path", f.Path)
|
||||||
s.folders[f.Path] = NewTagScanner(f.Path, s.ds)
|
s.folders[f.Path] = NewTagScanner(f.Path, s.ds)
|
||||||
|
|
|
@ -113,7 +113,7 @@ func (s *TagScanner) Scan(ctx context.Context, lastModifiedSince time.Time) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.ds.GC(log.NewContext(nil))
|
err = s.ds.GC(log.NewContext(context.TODO()))
|
||||||
log.Info("Finished Music Folder", "folder", s.rootFolder, "elapsed", time.Since(start))
|
log.Info("Finished Music Folder", "folder", s.rootFolder, "elapsed", time.Since(start))
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
@ -18,7 +19,8 @@ func initialSetup(ds model.DataStore) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := ds.Property(nil).Get(consts.InitialSetupFlagKey)
|
properties := ds.Property(context.TODO())
|
||||||
|
_, err := properties.Get(consts.InitialSetupFlagKey)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -33,13 +35,14 @@ func initialSetup(ds model.DataStore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ds.Property(nil).Put(consts.InitialSetupFlagKey, time.Now().String())
|
err = properties.Put(consts.InitialSetupFlagKey, time.Now().String())
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func createInitialAdminUser(ds model.DataStore) error {
|
func createInitialAdminUser(ds model.DataStore) error {
|
||||||
c, err := ds.User(nil).CountAll()
|
users := ds.User(context.TODO())
|
||||||
|
c, err := users.CountAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Could not access User table: %s", err))
|
panic(fmt.Sprintf("Could not access User table: %s", err))
|
||||||
}
|
}
|
||||||
|
@ -59,7 +62,7 @@ func createInitialAdminUser(ds model.DataStore) error {
|
||||||
Password: initialPassword,
|
Password: initialPassword,
|
||||||
IsAdmin: true,
|
IsAdmin: true,
|
||||||
}
|
}
|
||||||
err := ds.User(nil).Put(&initialUser)
|
err := users.Put(&initialUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Could not create initial admin user", "user", initialUser, err)
|
log.Error("Could not create initial admin user", "user", initialUser, err)
|
||||||
}
|
}
|
||||||
|
@ -68,13 +71,14 @@ func createInitialAdminUser(ds model.DataStore) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createJWTSecret(ds model.DataStore) error {
|
func createJWTSecret(ds model.DataStore) error {
|
||||||
_, err := ds.Property(nil).Get(consts.JWTSecretKey)
|
properties := ds.Property(context.TODO())
|
||||||
|
_, err := properties.Get(consts.JWTSecretKey)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
jwtSecret, _ := uuid.NewRandom()
|
jwtSecret, _ := uuid.NewRandom()
|
||||||
log.Warn("Creating JWT secret, used for encrypting UI sessions")
|
log.Warn("Creating JWT secret, used for encrypting UI sessions")
|
||||||
err = ds.Property(nil).Put(consts.JWTSecretKey, jwtSecret.String())
|
err = properties.Put(consts.JWTSecretKey, jwtSecret.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Could not save JWT secret in DB", err)
|
log.Error("Could not save JWT secret in DB", err)
|
||||||
}
|
}
|
||||||
|
@ -82,8 +86,8 @@ func createJWTSecret(ds model.DataStore) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDefaultTranscodings(ds model.DataStore) error {
|
func createDefaultTranscodings(ds model.DataStore) error {
|
||||||
repo := ds.Transcoding(nil)
|
transcodings := ds.Transcoding(context.TODO())
|
||||||
c, _ := repo.CountAll()
|
c, _ := transcodings.CountAll()
|
||||||
if c != 0 {
|
if c != 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -98,7 +102,7 @@ func createDefaultTranscodings(ds model.DataStore) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Info("Creating default transcoding config", "name", t.Name)
|
log.Info("Creating default transcoding config", "name", t.Name)
|
||||||
if err = repo.Put(&t); err != nil {
|
if err = transcodings.Put(&t); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue