Skip to content

Commit

Permalink
honor dlna sort order to content exceeding the first page (#3747)
Browse files Browse the repository at this point in the history
  • Loading branch information
cj12312021 authored May 23, 2023
1 parent 124adb3 commit 58a6c22
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
18 changes: 13 additions & 5 deletions internal/dlna/cds.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,21 @@ func getRootObjects() []interface{} {
return objs
}

func getSortDirection(sceneFilter *models.SceneFilterType, sort string) models.SortDirectionEnum {
direction := models.SortDirectionEnumDesc
if sort == "title" {
direction = models.SortDirectionEnumAsc
}

return direction
}

func (me *contentDirectoryService) getVideos(sceneFilter *models.SceneFilterType, parentID string, host string) []interface{} {
var objs []interface{}

if err := txn.WithReadTxn(context.TODO(), me.txnManager, func(ctx context.Context) error {
sort := me.VideoSortOrder
direction := models.SortDirectionEnumDesc
if sort == "title" {
direction = models.SortDirectionEnumAsc
}
direction := getSortDirection(sceneFilter, sort)
findFilter := &models.FindFilterType{
PerPage: &pageSize,
Sort: &sort,
Expand Down Expand Up @@ -497,8 +503,10 @@ func (me *contentDirectoryService) getPageVideos(sceneFilter *models.SceneFilter
parentID: parentID,
}

sort := me.VideoSortOrder
direction := getSortDirection(sceneFilter, sort)
var err error
objs, err = pager.getPageVideos(ctx, me.repository.SceneFinder, me.repository.FileFinder, page, host)
objs, err = pager.getPageVideos(ctx, me.repository.SceneFinder, me.repository.FileFinder, page, host, sort, direction)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions internal/dlna/paging.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func (p *scenePager) getPages(ctx context.Context, r scene.Queryer, total int) (
return objs, nil
}

func (p *scenePager) getPageVideos(ctx context.Context, r SceneFinder, f file.Finder, page int, host string) ([]interface{}, error) {
func (p *scenePager) getPageVideos(ctx context.Context, r SceneFinder, f file.Finder, page int, host string, sort string, direction models.SortDirectionEnum) ([]interface{}, error) {
var objs []interface{}

sort := "title"
findFilter := &models.FindFilterType{
PerPage: &pageSize,
Page: &page,
Sort: &sort,
PerPage: &pageSize,
Page: &page,
Sort: &sort,
Direction: &direction,
}

scenes, err := scene.Query(ctx, r, p.sceneFilter, findFilter)
Expand Down

0 comments on commit 58a6c22

Please sign in to comment.