Auto-Import playlists found in the Music Folder
This commit is contained in:
@@ -80,8 +80,20 @@ func (r mediaFileRepository) FindByAlbum(albumId string) (model.MediaFiles, erro
|
||||
return res, err
|
||||
}
|
||||
|
||||
// FindByPath only return mediafiles that are direct children of requested path
|
||||
func (r mediaFileRepository) FindByPath(path string) (model.MediaFiles, error) {
|
||||
func (r mediaFileRepository) FindByPath(path string) (*model.MediaFile, error) {
|
||||
sel := r.selectMediaFile().Where(Eq{"path": path})
|
||||
var res model.MediaFiles
|
||||
if err := r.queryAll(sel, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(res) == 0 {
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
return &res[0], nil
|
||||
}
|
||||
|
||||
// FindAllByPath only return mediafiles that are direct children of requested path
|
||||
func (r mediaFileRepository) FindAllByPath(path string) (model.MediaFiles, error) {
|
||||
// Query by path based on https://stackoverflow.com/a/13911906/653632
|
||||
sel0 := r.selectMediaFile().Columns(fmt.Sprintf("substr(path, %d) AS item", len(path)+2)).
|
||||
Where(pathStartsWith(path))
|
||||
|
||||
@@ -55,7 +55,7 @@ var _ = Describe("MediaRepository", func() {
|
||||
Expect(mr.Put(&model.MediaFile{ID: "7001", Path: P("/Find:By'Path/_/123.mp3")})).To(BeNil())
|
||||
Expect(mr.Put(&model.MediaFile{ID: "7002", Path: P("/Find:By'Path/1/123.mp3")})).To(BeNil())
|
||||
|
||||
found, err := mr.FindByPath(P("/Find:By'Path/_/"))
|
||||
found, err := mr.FindAllByPath(P("/Find:By'Path/_/"))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(found).To(HaveLen(1))
|
||||
Expect(found[0].ID).To(Equal("7001"))
|
||||
@@ -65,12 +65,12 @@ var _ = Describe("MediaRepository", func() {
|
||||
Expect(mr.Put(&model.MediaFile{ID: "7003", Path: P("/Casesensitive/file1.mp3")})).To(BeNil())
|
||||
Expect(mr.Put(&model.MediaFile{ID: "7004", Path: P("/casesensitive/file2.mp3")})).To(BeNil())
|
||||
|
||||
found, err := mr.FindByPath(P("/Casesensitive"))
|
||||
found, err := mr.FindAllByPath(P("/Casesensitive"))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(found).To(HaveLen(1))
|
||||
Expect(found[0].ID).To(Equal("7003"))
|
||||
|
||||
found, err = mr.FindByPath(P("/casesensitive/"))
|
||||
found, err = mr.FindAllByPath(P("/casesensitive/"))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(found).To(HaveLen(1))
|
||||
Expect(found[0].ID).To(Equal("7004"))
|
||||
|
||||
@@ -103,6 +103,16 @@ func (r *playlistRepository) Get(id string) (*model.Playlist, error) {
|
||||
return &pls, err
|
||||
}
|
||||
|
||||
func (r *playlistRepository) FindByPath(path string) (*model.Playlist, error) {
|
||||
sel := r.newSelect().Columns("*").Where(Eq{"path": path})
|
||||
var pls model.Playlist
|
||||
err := r.queryOne(sel, &pls)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pls, err
|
||||
}
|
||||
|
||||
func (r *playlistRepository) GetAll(options ...model.QueryOptions) (model.Playlists, error) {
|
||||
sel := r.newSelect(options...).Columns("*").Where(r.userFilter())
|
||||
res := model.Playlists{}
|
||||
|
||||
@@ -65,6 +65,13 @@ func (r *userRepository) Put(u *model.User) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *userRepository) FindFirstAdmin() (*model.User, error) {
|
||||
sel := r.newSelect(model.QueryOptions{Sort: "updated_at", Max: 1}).Columns("*").Where(Eq{"is_admin": true})
|
||||
var usr model.User
|
||||
err := r.queryOne(sel, &usr)
|
||||
return &usr, err
|
||||
}
|
||||
|
||||
func (r *userRepository) FindByUsername(username string) (*model.User, error) {
|
||||
username = strings.ToLower(username)
|
||||
sel := r.newSelect().Columns("*").Where(Eq{"user_name": username})
|
||||
|
||||
Reference in New Issue
Block a user