🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
refactor: removed unused code, unnecessary typecasts and fixed small warnings
Deluanf6e448c1ba4f
diff --git a/engine/browser.go b/engine/browser.goindex 36234422b..3181fb858 100644--- a/engine/browser.go+++ b/engine/browser.go@@ -37,7 +37,7 @@ func (b *browser) MediaFolders(ctx context.Context) (model.MediaFolders, error)func (b *browser) Indexes(ctx context.Context, mediaFolderId string, ifModifiedSince time.Time) (model.ArtistIndexes, time.Time, error) {// TODO Proper handling of mediaFolderId param- folder, err := b.ds.MediaFolder(ctx).Get(mediaFolderId)+ folder, _ := b.ds.MediaFolder(ctx).Get(mediaFolderId)l, err := b.ds.Property(ctx).DefaultGet(model.PropLastScan+"-"+folder.Path, "-1")ms, _ := strconv.ParseInt(l, 10, 64)diff --git a/engine/mock_nowplaying_repo.go b/engine/mock_nowplaying_repo.godeleted file mode 100644index 718ee55c4..000000000--- a/engine/mock_nowplaying_repo.go+++ /dev/null@@ -1,86 +0,0 @@-package engine--import (- "errors"- "time"-)--func CreateMockNowPlayingRepo() *MockNowPlaying {- return &MockNowPlaying{}-}--type MockNowPlaying struct {- NowPlayingRepository- data []NowPlayingInfo- t time.Time- err bool-}--func (m *MockNowPlaying) SetError(err bool) {- m.err = err-}--func (m *MockNowPlaying) Enqueue(info *NowPlayingInfo) error {- if m.err {- return errors.New("Error!")- }-- m.data = append(m.data, NowPlayingInfo{})- copy(m.data[1:], m.data[0:])- m.data[0] = *info-- if !m.t.IsZero() {- m.data[0].Start = m.t- m.t = time.Time{}- }-- return nil-}--func (m *MockNowPlaying) Dequeue(playerId int) (*NowPlayingInfo, error) {- if len(m.data) == 0 {- return nil, nil- }- l := len(m.data)- info := m.data[l-1]- m.data = m.data[:l-1]-- return &info, nil-}--func (m *MockNowPlaying) Count(playerId int) (int64, error) {- return int64(len(m.data)), nil-}--func (m *MockNowPlaying) GetAll() ([]*NowPlayingInfo, error) {- np, err := m.Head(1)- if np == nil || err != nil {- return nil, err- }- return []*NowPlayingInfo{np}, err-}--func (m *MockNowPlaying) Head(playerId int) (*NowPlayingInfo, error) {- if len(m.data) == 0 {- return nil, nil- }- info := m.data[0]- return &info, nil-}--func (m *MockNowPlaying) Tail(playerId int) (*NowPlayingInfo, error) {- if len(m.data) == 0 {- return nil, nil- }- info := m.data[len(m.data)-1]- return &info, nil-}--func (m *MockNowPlaying) ClearAll() {- m.data = make([]NowPlayingInfo, 0)- m.err = false-}--func (m *MockNowPlaying) OverrideNow(t time.Time) {- m.t = t-}diff --git a/engine/mock_property_repo.go b/engine/mock_property_repo.godeleted file mode 100644index d796abd0f..000000000--- a/engine/mock_property_repo.go+++ /dev/null@@ -1,46 +0,0 @@-package engine--import (- "errors"-- "github.com/deluan/navidrome/model"-)--func CreateMockPropertyRepo() *MockProperty {- return &MockProperty{data: make(map[string]string)}-}--type MockProperty struct {- model.PropertyRepository- data map[string]string- err bool-}--func (m *MockProperty) SetError(err bool) {- m.err = err-}--func (m *MockProperty) Put(id string, value string) error {- if m.err {- return errors.New("Error!")- }- m.data[id] = value- return nil-}--func (m *MockProperty) Get(id string) (string, error) {- if m.err {- return "", errors.New("Error!")- }- return m.data[id], nil-}--func (m *MockProperty) DefaultGet(id string, defaultValue string) (string, error) {- v, err := m.Get(id)-- if v == "" {- v = defaultValue- }-- return v, err-}diff --git a/engine/playlists.go b/engine/playlists.goindex f4a0a0ae4..e1da7748a 100644--- a/engine/playlists.go+++ b/engine/playlists.go@@ -73,15 +73,15 @@ func (p *playlists) Delete(ctx context.Context, playlistId string) error {func (p *playlists) Update(ctx context.Context, playlistId string, name *string, idsToAdd []string, idxToRemove []int) error {pls, err := p.ds.Playlist(ctx).Get(playlistId)+ if err != nil {+ return err+ }owner := p.getUser(ctx)if owner != pls.Owner {return model.ErrNotAuthorized}- if err != nil {- return err- }if name != nil {pls.Name = *name}diff --git a/persistence/persistence.go b/persistence/persistence.goindex df8963570..d473efc69 100644--- a/persistence/persistence.go+++ b/persistence/persistence.go@@ -3,7 +3,6 @@ package persistenceimport ("context""reflect"- "sync""github.com/astaxie/beego/orm""github.com/deluan/navidrome/db"@@ -11,10 +10,6 @@ import ("github.com/deluan/navidrome/model")-var (- once sync.Once-)-type SQLStore struct {orm orm.Ormer}diff --git a/persistence/playlist_repository.go b/persistence/playlist_repository.goindex bbf4c8154..06eb7824e 100644--- a/persistence/playlist_repository.go+++ b/persistence/playlist_repository.go@@ -71,7 +71,7 @@ func (r *playlistRepository) GetWithTracks(id string) (*model.Playlist, error) {continue}pls.Duration += mf.Duration- newTracks = append(newTracks, model.MediaFile(*mf))+ newTracks = append(newTracks, *mf)}pls.Tracks = newTracksreturn pls, errdiff --git a/persistence/property_repository.go b/persistence/property_repository.goindex efbbda4e2..4bf5fcdcb 100644--- a/persistence/property_repository.go+++ b/persistence/property_repository.go@@ -8,11 +8,6 @@ import ("github.com/deluan/navidrome/model")-type property struct {- ID string `orm:"pk;column(id)"`- Value string-}-type propertyRepository struct {sqlRepository}diff --git a/persistence/sql_annotations.go b/persistence/sql_annotations.goindex c1bd23f9f..50d092f7d 100644--- a/persistence/sql_annotations.go+++ b/persistence/sql_annotations.go@@ -10,18 +10,6 @@ import ("github.com/google/uuid")-type annotation struct {- AnnID string `json:"annID" orm:"pk;column(ann_id)"`- UserID string `json:"userID" orm:"pk;column(user_id)"`- ItemID string `json:"itemID" orm:"pk;column(item_id)"`- ItemType string `json:"itemType"`- PlayCount int `json:"playCount"`- PlayDate time.Time `json:"playDate"`- Rating int `json:"rating"`- Starred bool `json:"starred"`- StarredAt time.Time `json:"starredAt"`-}-const annotationTable = "annotation"func (r sqlRepository) newSelectWithAnnotation(idField string, options ...model.QueryOptions) SelectBuilder {diff --git a/scanner/change_detector.go b/scanner/change_detector.goindex 38392f045..5b51d4b84 100644--- a/scanner/change_detector.go+++ b/scanner/change_detector.go@@ -46,10 +46,10 @@ func (s *ChangeDetector) Scan(lastModifiedSince time.Time) (changed []string, defunc (s *ChangeDetector) loadDir(dirPath string) (children []string, lastUpdated time.Time, err error) {dir, err := os.Open(dirPath)- defer dir.Close()if err != nil {return}+ defer dir.Close()dirInfo, err := os.Stat(dirPath)if err != nil {returndiff --git a/utils/strings_test.go b/utils/strings_test.goindex 6e23e5327..53ee8d4af 100644--- a/utils/strings_test.go+++ b/utils/strings_test.go@@ -6,13 +6,13 @@ import (func TestLongestCommonPrefix(t *testing.T) {expected := "/Music/iTunes 1/iTunes Media/Music/"- actual := LongestCommonPrefix(test_strings)+ actual := LongestCommonPrefix(testStrings)if actual != expected {t.Errorf("Couldn't find longest common prefix: want '%s', got '%s'", expected, actual)}}-var test_strings = []string{+var testStrings = []string{"/Music/iTunes 1/iTunes Media/Music/ABBA/Gold_ Greatest Hits/Dancing Queen.m4a","/Music/iTunes 1/iTunes Media/Music/ABBA/Gold_ Greatest Hits/Mamma Mia.m4a","/Music/iTunes 1/iTunes Media/Music/Art Blakey/A Night At Birdland, Vol. 1/01 Annoucement By Pee Wee Marquette.m4a",