diff --git a/server/ctrlsubsonic/handlers_by_tags.go b/server/ctrlsubsonic/handlers_by_tags.go index b55dc942..6424b9ff 100644 --- a/server/ctrlsubsonic/handlers_by_tags.go +++ b/server/ctrlsubsonic/handlers_by_tags.go @@ -132,7 +132,7 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response { user.ID) q = q.Order("plays.count DESC") case "newest": - q = q.Order("modified_at DESC") + q = q.Order("created_at DESC") case "random": q = q.Order(gorm.Expr("random()")) case "recent": diff --git a/server/ctrlsubsonic/spec/construct_by_folder.go b/server/ctrlsubsonic/spec/construct_by_folder.go index 6e3c9f81..8040f8f4 100644 --- a/server/ctrlsubsonic/spec/construct_by_folder.go +++ b/server/ctrlsubsonic/spec/construct_by_folder.go @@ -15,6 +15,7 @@ func NewAlbumByFolder(f *db.Album) *Album { Title: f.RightPath, TrackCount: f.ChildCount, Duration: f.Duration, + Created: f.CreatedAt, } if f.Cover != "" { a.CoverID = f.SID() @@ -28,7 +29,7 @@ func NewTCAlbumByFolder(f *db.Album) *TrackChild { IsDir: true, Title: f.RightPath, ParentID: f.ParentSID(), - CreatedAt: f.UpdatedAt, + CreatedAt: f.CreatedAt, } if f.Cover != "" { trCh.CoverID = f.SID() diff --git a/server/ctrlsubsonic/spec/construct_by_tags.go b/server/ctrlsubsonic/spec/construct_by_tags.go index c997b4cf..32509951 100644 --- a/server/ctrlsubsonic/spec/construct_by_tags.go +++ b/server/ctrlsubsonic/spec/construct_by_tags.go @@ -9,7 +9,7 @@ import ( func NewAlbumByTags(a *db.Album, artist *db.Artist) *Album { ret := &Album{ - Created: a.ModifiedAt, + Created: a.CreatedAt, ID: a.SID(), Name: a.TagTitle, Year: a.TagYear, diff --git a/server/ctrlsubsonic/spec/spec.go b/server/ctrlsubsonic/spec/spec.go index e242ed90..f30fab89 100644 --- a/server/ctrlsubsonic/spec/spec.go +++ b/server/ctrlsubsonic/spec/spec.go @@ -94,6 +94,7 @@ type Album struct { CoverID *specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"` ArtistID *specid.ID `xml:"artistId,attr,omitempty" json:"artistId,omitempty"` Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"` + Created time.Time `xml:"created,attr,omitempty" json:"created,omitempty"` // browsing by folder (eg. getAlbumList) Title string `xml:"title,attr,omitempty" json:"title"` Album string `xml:"album,attr,omitempty" json:"album"` @@ -103,7 +104,6 @@ type Album struct { Name string `xml:"name,attr" json:"name"` TrackCount int `xml:"songCount,attr" json:"songCount"` Duration int `xml:"duration,attr" json:"duration"` - Created time.Time `xml:"created,attr,omitempty" json:"created,omitempty"` Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"` Year int `xml:"year,attr,omitempty" json:"year,omitempty"` Tracks []*TrackChild `xml:"song,omitempty" json:"song,omitempty"` diff --git a/server/ctrlsubsonic/testdata/db b/server/ctrlsubsonic/testdata/db index 849a3225..7aad42f3 100644 Binary files a/server/ctrlsubsonic/testdata/db and b/server/ctrlsubsonic/testdata/db differ diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist index b3869461..d9482237 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist +++ b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_artist @@ -16,7 +16,7 @@ "name": "", "songCount": 10, "duration": 2609, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-13T12:57:28.850090338+01:00" }, { "id": "al-9", @@ -29,7 +29,7 @@ "name": "", "songCount": 21, "duration": 4222, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-13T12:57:24.306717554+01:00" }, { "id": "al-5", @@ -42,7 +42,7 @@ "name": "", "songCount": 14, "duration": 2738, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-05T17:46:37.675917974+01:00" }, { "id": "al-6", @@ -54,7 +54,7 @@ "name": "", "songCount": 9, "duration": 2801, - "created": "0001-01-01T00:00:00Z" + "created": "2019-05-23T15:12:02.921473302+01:00" }, { "id": "al-21", @@ -67,7 +67,7 @@ "name": "", "songCount": 15, "duration": 2324, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-10T19:26:30.944742894+01:00" }, { "id": "al-3", @@ -80,7 +80,7 @@ "name": "", "songCount": 5, "duration": 1871, - "created": "0001-01-01T00:00:00Z" + "created": "2019-05-16T22:10:52+01:00" }, { "id": "al-16", @@ -93,7 +93,7 @@ "name": "", "songCount": 16, "duration": 3040, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:48+01:00" }, { "id": "al-17", @@ -106,7 +106,7 @@ "name": "", "songCount": 18, "duration": 3266, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:48+01:00" }, { "id": "al-19", @@ -119,7 +119,7 @@ "name": "", "songCount": 15, "duration": 3812, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:30+01:00" }, { "id": "al-13", @@ -132,7 +132,7 @@ "name": "", "songCount": 9, "duration": 2169, - "created": "0001-01-01T00:00:00Z" + "created": "2019-05-23T15:12:02.921473302+01:00" } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name index f9d749f8..3dde97e8 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name +++ b/server/ctrlsubsonic/testdata/test_get_album_list_alpha_name @@ -16,7 +16,7 @@ "name": "", "songCount": 21, "duration": 4222, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-13T12:57:24.306717554+01:00" }, { "id": "al-8", @@ -29,7 +29,7 @@ "name": "", "songCount": 10, "duration": 2609, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-13T12:57:28.850090338+01:00" }, { "id": "al-19", @@ -42,7 +42,7 @@ "name": "", "songCount": 15, "duration": 3812, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:30+01:00" }, { "id": "al-21", @@ -55,7 +55,7 @@ "name": "", "songCount": 15, "duration": 2324, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-10T19:26:30.944742894+01:00" }, { "id": "al-17", @@ -68,7 +68,7 @@ "name": "", "songCount": 18, "duration": 3266, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:48+01:00" }, { "id": "al-16", @@ -81,7 +81,7 @@ "name": "", "songCount": 16, "duration": 3040, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:48+01:00" }, { "id": "al-6", @@ -93,7 +93,7 @@ "name": "", "songCount": 9, "duration": 2801, - "created": "0001-01-01T00:00:00Z" + "created": "2019-05-23T15:12:02.921473302+01:00" }, { "id": "al-3", @@ -106,7 +106,7 @@ "name": "", "songCount": 5, "duration": 1871, - "created": "0001-01-01T00:00:00Z" + "created": "2019-05-16T22:10:52+01:00" }, { "id": "al-5", @@ -119,7 +119,7 @@ "name": "", "songCount": 14, "duration": 2738, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-05T17:46:37.675917974+01:00" }, { "id": "al-13", @@ -132,7 +132,7 @@ "name": "", "songCount": 9, "duration": 2169, - "created": "0001-01-01T00:00:00Z" + "created": "2019-05-23T15:12:02.921473302+01:00" } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_newest b/server/ctrlsubsonic/testdata/test_get_album_list_newest index 41719280..91c8d04d 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_newest +++ b/server/ctrlsubsonic/testdata/test_get_album_list_newest @@ -16,7 +16,7 @@ "name": "", "songCount": 10, "duration": 2609, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-13T12:57:28.850090338+01:00" }, { "id": "al-9", @@ -29,7 +29,7 @@ "name": "", "songCount": 21, "duration": 4222, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-13T12:57:24.306717554+01:00" }, { "id": "al-21", @@ -42,7 +42,7 @@ "name": "", "songCount": 15, "duration": 2324, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-10T19:26:30.944742894+01:00" }, { "id": "al-5", @@ -55,7 +55,7 @@ "name": "", "songCount": 14, "duration": 2738, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-05T17:46:37.675917974+01:00" }, { "id": "al-6", @@ -67,7 +67,7 @@ "name": "", "songCount": 9, "duration": 2801, - "created": "0001-01-01T00:00:00Z" + "created": "2019-05-23T15:12:02.921473302+01:00" }, { "id": "al-13", @@ -80,7 +80,7 @@ "name": "", "songCount": 9, "duration": 2169, - "created": "0001-01-01T00:00:00Z" + "created": "2019-05-23T15:12:02.921473302+01:00" }, { "id": "al-3", @@ -93,7 +93,7 @@ "name": "", "songCount": 5, "duration": 1871, - "created": "0001-01-01T00:00:00Z" + "created": "2019-05-16T22:10:52+01:00" }, { "id": "al-16", @@ -106,7 +106,7 @@ "name": "", "songCount": 16, "duration": 3040, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:48+01:00" }, { "id": "al-17", @@ -119,7 +119,7 @@ "name": "", "songCount": 18, "duration": 3266, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:48+01:00" }, { "id": "al-19", @@ -132,7 +132,7 @@ "name": "", "songCount": 15, "duration": 3812, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:30+01:00" } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_random b/server/ctrlsubsonic/testdata/test_get_album_list_random index a0a44499..bf5c8b17 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_random @@ -5,19 +5,6 @@ "type": "gonic", "albumList": { "album": [ - { - "id": "al-16", - "coverArt": "al-16", - "artist": "Swell Maps", - "title": "(1980) Jane From Occupied Europe", - "album": "", - "parent": "al-15", - "isDir": true, - "name": "", - "songCount": 16, - "duration": 3040, - "created": "0001-01-01T00:00:00Z" - }, { "id": "al-19", "coverArt": "al-19", @@ -29,7 +16,20 @@ "name": "", "songCount": 15, "duration": 3812, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:30+01:00" + }, + { + "id": "al-21", + "coverArt": "al-21", + "artist": "Captain Beefheart", + "title": "(1970) Lick My Decals Off, Bitch", + "album": "", + "parent": "al-20", + "isDir": true, + "name": "", + "songCount": 15, + "duration": 2324, + "created": "2019-06-10T19:26:30.944742894+01:00" }, { "id": "al-17", @@ -42,46 +42,32 @@ "name": "", "songCount": 18, "duration": 3266, - "created": "0001-01-01T00:00:00Z" + "created": "2019-04-30T16:48:48+01:00" }, { - "id": "al-3", - "coverArt": "al-3", - "artist": "Jah Wobble, The Edge, Holger Czukay", - "title": "(1983) Snake Charmer", - "album": "", - "parent": "al-2", - "isDir": true, - "name": "", - "songCount": 5, - "duration": 1871, - "created": "0001-01-01T00:00:00Z" - }, - { - "id": "al-21", - "coverArt": "al-21", - "artist": "Captain Beefheart", - "title": "(1970) Lick My Decals Off, Bitch", + "id": "al-6", + "artist": "A Certain Ratio", + "title": "(1981) To EachOTHER.", "album": "", - "parent": "al-20", + "parent": "al-4", "isDir": true, "name": "", - "songCount": 15, - "duration": 2324, - "created": "0001-01-01T00:00:00Z" + "songCount": 9, + "duration": 2801, + "created": "2019-05-23T15:12:02.921473302+01:00" }, { - "id": "al-5", - "coverArt": "al-5", - "artist": "A Certain Ratio", - "title": "(1994) The Graveyard and the Ballroom", + "id": "al-13", + "coverArt": "al-13", + "artist": "There", + "title": "(2010) Anika", "album": "", - "parent": "al-4", + "parent": "al-12", "isDir": true, "name": "", - "songCount": 14, - "duration": 2738, - "created": "0001-01-01T00:00:00Z" + "songCount": 9, + "duration": 2169, + "created": "2019-05-23T15:12:02.921473302+01:00" }, { "id": "al-8", @@ -94,7 +80,7 @@ "name": "", "songCount": 10, "duration": 2609, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-13T12:57:28.850090338+01:00" }, { "id": "al-9", @@ -107,32 +93,46 @@ "name": "", "songCount": 21, "duration": 4222, - "created": "0001-01-01T00:00:00Z" + "created": "2019-06-13T12:57:24.306717554+01:00" }, { - "id": "al-6", + "id": "al-5", + "coverArt": "al-5", "artist": "A Certain Ratio", - "title": "(1981) To EachOTHER.", + "title": "(1994) The Graveyard and the Ballroom", "album": "", "parent": "al-4", "isDir": true, "name": "", - "songCount": 9, - "duration": 2801, - "created": "0001-01-01T00:00:00Z" + "songCount": 14, + "duration": 2738, + "created": "2019-06-05T17:46:37.675917974+01:00" }, { - "id": "al-13", - "coverArt": "al-13", - "artist": "There", - "title": "(2010) Anika", + "id": "al-16", + "coverArt": "al-16", + "artist": "Swell Maps", + "title": "(1980) Jane From Occupied Europe", "album": "", - "parent": "al-12", + "parent": "al-15", "isDir": true, "name": "", - "songCount": 9, - "duration": 2169, - "created": "0001-01-01T00:00:00Z" + "songCount": 16, + "duration": 3040, + "created": "2019-04-30T16:48:48+01:00" + }, + { + "id": "al-3", + "coverArt": "al-3", + "artist": "Jah Wobble, The Edge, Holger Czukay", + "title": "(1983) Snake Charmer", + "album": "", + "parent": "al-2", + "isDir": true, + "name": "", + "songCount": 5, + "duration": 1871, + "created": "2019-05-16T22:10:52+01:00" } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_album_list_two_random b/server/ctrlsubsonic/testdata/test_get_album_list_two_random index 87dea95a..0b6ba98c 100644 --- a/server/ctrlsubsonic/testdata/test_get_album_list_two_random +++ b/server/ctrlsubsonic/testdata/test_get_album_list_two_random @@ -18,6 +18,19 @@ "created": "2019-04-30T16:48:48+01:00", "year": 1979 }, + { + "id": "al-9", + "coverArt": "al-9", + "artistId": "ar-3", + "artist": "13th Floor Elevators", + "title": "", + "album": "", + "name": "The Psychedelic Sounds of the 13th Floor Elevators", + "songCount": 21, + "duration": 4222, + "created": "2019-06-13T12:57:24.306717554+01:00", + "year": 1966 + }, { "id": "al-16", "coverArt": "al-16", @@ -31,32 +44,6 @@ "created": "2019-04-30T16:48:48+01:00", "year": 1980 }, - { - "id": "al-21", - "coverArt": "al-21", - "artistId": "ar-7", - "artist": "Captain Beefheart & His Magic Band", - "title": "", - "album": "", - "name": "Lick My Decals Off, Baby", - "songCount": 15, - "duration": 2324, - "created": "2019-06-10T19:26:30.944742894+01:00", - "year": 1970 - }, - { - "id": "al-8", - "coverArt": "al-8", - "artistId": "ar-3", - "artist": "13th Floor Elevators", - "title": "", - "album": "", - "name": "Easter Everywhere", - "songCount": 10, - "duration": 2609, - "created": "2019-06-13T12:57:28.850090338+01:00", - "year": 1967 - }, { "id": "al-19", "coverArt": "al-19", @@ -83,30 +70,43 @@ "year": 1981 }, { - "id": "al-9", - "coverArt": "al-9", + "id": "al-8", + "coverArt": "al-8", "artistId": "ar-3", "artist": "13th Floor Elevators", "title": "", "album": "", - "name": "The Psychedelic Sounds of the 13th Floor Elevators", - "songCount": 21, - "duration": 4222, - "created": "2019-06-13T12:57:24.306717554+01:00", - "year": 1966 + "name": "Easter Everywhere", + "songCount": 10, + "duration": 2609, + "created": "2019-06-13T12:57:28.850090338+01:00", + "year": 1967 }, { - "id": "al-13", - "coverArt": "al-13", - "artistId": "ar-4", - "artist": "Anikas", + "id": "al-21", + "coverArt": "al-21", + "artistId": "ar-7", + "artist": "Captain Beefheart & His Magic Band", "title": "", "album": "", - "name": "Anika", - "songCount": 9, - "duration": 2169, - "created": "2019-05-23T15:12:02.921473302+01:00", - "year": 2010 + "name": "Lick My Decals Off, Baby", + "songCount": 15, + "duration": 2324, + "created": "2019-06-10T19:26:30.944742894+01:00", + "year": 1970 + }, + { + "id": "al-5", + "coverArt": "al-5", + "artistId": "ar-2", + "artist": "A Certain Ratio", + "title": "", + "album": "", + "name": "The Graveyard and the Ballroom", + "songCount": 14, + "duration": 2738, + "created": "2019-06-05T17:46:37.675917974+01:00", + "year": 1994 }, { "id": "al-3", @@ -122,17 +122,17 @@ "year": 1983 }, { - "id": "al-5", - "coverArt": "al-5", - "artistId": "ar-2", - "artist": "A Certain Ratio", + "id": "al-13", + "coverArt": "al-13", + "artistId": "ar-4", + "artist": "Anikas", "title": "", "album": "", - "name": "The Graveyard and the Ballroom", - "songCount": 14, - "duration": 2738, - "created": "2019-06-05T17:46:37.675917974+01:00", - "year": 1994 + "name": "Anika", + "songCount": 9, + "duration": 2169, + "created": "2019-05-23T15:12:02.921473302+01:00", + "year": 2010 } ] } diff --git a/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks b/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks index 87f01c12..aab19d3d 100644 --- a/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks +++ b/server/ctrlsubsonic/testdata/test_get_music_directory_without_tracks @@ -10,7 +10,7 @@ { "id": "al-3", "coverArt": "al-3", - "created": "2019-07-08T21:49:40.995905275+01:00", + "created": "2019-05-16T22:10:52+01:00", "isDir": true, "isVideo": false, "parent": "al-2", diff --git a/server/ctrlsubsonic/testdata/test_search_two_q_13 b/server/ctrlsubsonic/testdata/test_search_two_q_13 index 05bf1c36..0ebc5157 100644 --- a/server/ctrlsubsonic/testdata/test_search_two_q_13 +++ b/server/ctrlsubsonic/testdata/test_search_two_q_13 @@ -14,7 +14,7 @@ { "id": "al-9", "coverArt": "al-9", - "created": "2019-07-08T21:49:41.246041678+01:00", + "created": "2019-06-13T12:57:24.306717554+01:00", "isDir": true, "isVideo": false, "parent": "al-7", diff --git a/server/ctrlsubsonic/testdata/test_search_two_q_ani b/server/ctrlsubsonic/testdata/test_search_two_q_ani index 6f6ee0a4..e84a394a 100644 --- a/server/ctrlsubsonic/testdata/test_search_two_q_ani +++ b/server/ctrlsubsonic/testdata/test_search_two_q_ani @@ -14,7 +14,7 @@ { "id": "al-13", "coverArt": "al-13", - "created": "2019-07-08T21:49:41.334460116+01:00", + "created": "2019-05-23T15:12:02.921473302+01:00", "isDir": true, "isVideo": false, "parent": "al-12", diff --git a/server/db/db.go b/server/db/db.go index defa5f45..f35f2d4d 100644 --- a/server/db/db.go +++ b/server/db/db.go @@ -82,6 +82,7 @@ func New(path string) (*DB, error) { migratePodcast(), migrateBookmarks(), migratePodcastAutoDownload(), + migrateAlbumCreatedAt(), )) if err = migr.Migrate(); err != nil { return nil, fmt.Errorf("migrating to latest version: %w", err) diff --git a/server/db/migrations.go b/server/db/migrations.go index 162dd6c5..624a5983 100644 --- a/server/db/migrations.go +++ b/server/db/migrations.go @@ -262,3 +262,24 @@ func migratePodcastAutoDownload() gormigrate.Migration { }, } } + +func migrateAlbumCreatedAt() gormigrate.Migration { + return gormigrate.Migration{ + ID: "202110041330", + Migrate: func(tx *gorm.DB) error { + step := tx.AutoMigrate( + Album{}, + ) + if err := step.Error; err != nil { + return fmt.Errorf("step auto migrate: %w", err) + } + step = tx.Exec(` + UPDATE albums SET created_at=modified_at; + `) + if err := step.Error; err != nil { + return fmt.Errorf("step migrate album created_at: %w", err) + } + return nil + }, + } +} diff --git a/server/db/model.go b/server/db/model.go index 4baad501..8d2e5b4b 100644 --- a/server/db/model.go +++ b/server/db/model.go @@ -179,6 +179,7 @@ type Play struct { type Album struct { ID int `gorm:"primary_key"` + CreatedAt time.Time UpdatedAt time.Time ModifiedAt time.Time LeftPath string `gorm:"unique_index:idx_left_path_right_path"`