1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +00:00

Improved playlists error handling

This commit is contained in:
spl0k 2017-11-08 23:18:41 +01:00
parent 6f713e12db
commit 336f556ced

View File

@ -34,6 +34,10 @@ def list_playlists():
if not request.user.admin: if not request.user.admin:
return request.error_formatter(50, 'Restricted to admins') return request.error_formatter(50, 'Restricted to admins')
user = store.find(User, User.name == username).one()
if not user:
return request.error_formatter(70, 'No such user')
query = store.find(Playlist, Playlist.user_id == User.id, User.name == username).order_by(Playlist.name) query = store.find(Playlist, Playlist.user_id == User.id, User.name == username).order_by(Playlist.name)
return request.formatter({ 'playlists': { 'playlist': [ p.as_subsonic_playlist(request.user) for p in query ] } }) return request.formatter({ 'playlists': { 'playlist': [ p.as_subsonic_playlist(request.user) for p in query ] } })
@ -44,6 +48,9 @@ def show_playlist():
if not status: if not status:
return res return res
if res.user_id != request.user.id and not request.user.admin:
return request.error_formatter('50', 'Private playlist')
info = res.as_subsonic_playlist(request.user) info = res.as_subsonic_playlist(request.user)
info['entry'] = [ t.as_subsonic_child(request.user, request.prefs) for t in res.get_tracks() ] info['entry'] = [ t.as_subsonic_child(request.user, request.prefs) for t in res.get_tracks() ]
return request.formatter({ 'playlist': info }) return request.formatter({ 'playlist': info })
@ -82,6 +89,7 @@ def create_playlist():
for sid in songs: for sid in songs:
track = store.get(Track, sid) track = store.get(Track, sid)
if not track: if not track:
store.rollback()
return request.error_formatter(70, 'Unknown song') return request.error_formatter(70, 'Unknown song')
playlist.add(track) playlist.add(track)