mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-18 21:07:44 +03:00
Keep order of shared mediafiles
This commit is contained in:
parent
c770229154
commit
26be5b8396
@ -101,13 +101,28 @@ func (r *shareRepository) loadMedia(share *model.Share) error {
|
|||||||
return nil
|
return nil
|
||||||
case "media_file":
|
case "media_file":
|
||||||
mfRepo := NewMediaFileRepository(r.ctx, r.ormer)
|
mfRepo := NewMediaFileRepository(r.ctx, r.ormer)
|
||||||
share.Tracks, err = mfRepo.GetAll(model.QueryOptions{Filters: Eq{"id": ids}})
|
tracks, err := mfRepo.GetAll(model.QueryOptions{Filters: Eq{"id": ids}})
|
||||||
|
share.Tracks = sortByIdPosition(tracks, ids)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Warn(r.ctx, "Unsupported Share ResourceType", "share", share.ID, "resourceType", share.ResourceType)
|
log.Warn(r.ctx, "Unsupported Share ResourceType", "share", share.ID, "resourceType", share.ResourceType)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sortByIdPosition(mfs model.MediaFiles, ids []string) model.MediaFiles {
|
||||||
|
m := map[string]int{}
|
||||||
|
for i, mf := range mfs {
|
||||||
|
m[mf.ID] = i
|
||||||
|
}
|
||||||
|
var sorted model.MediaFiles
|
||||||
|
for _, id := range ids {
|
||||||
|
if idx, ok := m[id]; ok {
|
||||||
|
sorted = append(sorted, mfs[idx])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sorted
|
||||||
|
}
|
||||||
|
|
||||||
func (r *shareRepository) Update(id string, entity interface{}, cols ...string) error {
|
func (r *shareRepository) Update(id string, entity interface{}, cols ...string) error {
|
||||||
s := entity.(*model.Share)
|
s := entity.(*model.Share)
|
||||||
// TODO Validate record
|
// TODO Validate record
|
||||||
|
Loading…
x
Reference in New Issue
Block a user