1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 19:52:16 +00:00

Small refactoring of supysonic.api.get_entity

This commit is contained in:
spl0k 2018-01-30 21:56:06 +01:00
parent 66b6eb341e
commit 27b9c232c2
5 changed files with 16 additions and 16 deletions

View File

@ -99,19 +99,19 @@ def get_client_prefs():
def not_found(*args, **kwargs):
return request.error_formatter(0, 'Not implemented'), 501
def get_entity(req, cls, param = 'id'):
eid = req.values.get(param)
def get_entity(cls, param = 'id'):
eid = request.values.get(param)
if not eid:
return False, req.error_formatter(10, 'Missing %s id' % cls.__name__)
return False, request.error_formatter(10, 'Missing %s id' % cls.__name__)
try:
eid = uuid.UUID(eid)
entity = cls[eid]
return True, entity
except ValueError:
return False, req.error_formatter(0, 'Invalid %s id' % cls.__name__)
return False, request.error_formatter(0, 'Invalid %s id' % cls.__name__)
except ObjectNotFound:
return False, (req.error_formatter(70, '%s not found' % cls.__name__), 404)
return False, (request.error_formatter(70, '%s not found' % cls.__name__), 404)
from .system import *
from .browse import *

View File

@ -175,7 +175,7 @@ def rate():
@api.route('/scrobble.view', methods = [ 'GET', 'POST' ])
@db_session
def scrobble():
status, res = get_entity(request, Track)
status, res = get_entity(Track)
if not status:
return res

View File

@ -108,7 +108,7 @@ def list_indexes():
@api.route('/getMusicDirectory.view', methods = [ 'GET', 'POST' ])
@db_session
def show_directory():
status, res = get_entity(request, Folder)
status, res = get_entity(Folder)
if not status:
return res
@ -151,7 +151,7 @@ def list_artists():
@api.route('/getArtist.view', methods = [ 'GET', 'POST' ])
@db_session
def artist_info():
status, res = get_entity(request, Artist)
status, res = get_entity(Artist)
if not status:
return res
@ -165,7 +165,7 @@ def artist_info():
@api.route('/getAlbum.view', methods = [ 'GET', 'POST' ])
@db_session
def album_info():
status, res = get_entity(request, Album)
status, res = get_entity(Album)
if not status:
return res
@ -177,7 +177,7 @@ def album_info():
@api.route('/getSong.view', methods = [ 'GET', 'POST' ])
@db_session
def track_info():
status, res = get_entity(request, Track)
status, res = get_entity(Track)
if not status:
return res

View File

@ -49,7 +49,7 @@ def prepare_transcoding_cmdline(base_cmdline, input_file, input_format, output_f
@api.route('/stream.view', methods = [ 'GET', 'POST' ])
@db_session
def stream_media():
status, res = get_entity(request, Track)
status, res = get_entity(Track)
if not status:
return res
@ -136,7 +136,7 @@ def stream_media():
@api.route('/download.view', methods = [ 'GET', 'POST' ])
def download_media():
with db_session:
status, res = get_entity(request, Track)
status, res = get_entity(Track)
if not status:
return res
@ -145,7 +145,7 @@ def download_media():
@api.route('/getCoverArt.view', methods = [ 'GET', 'POST' ])
def cover_art():
with db_session:
status, res = get_entity(request, Folder)
status, res = get_entity(Folder)
if not status:
return res

View File

@ -51,7 +51,7 @@ def list_playlists():
@api.route('/getPlaylist.view', methods = [ 'GET', 'POST' ])
@db_session
def show_playlist():
status, res = get_entity(request, Playlist)
status, res = get_entity(Playlist)
if not status:
return res
@ -107,7 +107,7 @@ def create_playlist():
@api.route('/deletePlaylist.view', methods = [ 'GET', 'POST' ])
@db_session
def delete_playlist():
status, res = get_entity(request, Playlist)
status, res = get_entity(Playlist)
if not status:
return res
@ -120,7 +120,7 @@ def delete_playlist():
@api.route('/updatePlaylist.view', methods = [ 'GET', 'POST' ])
@db_session
def update_playlist():
status, res = get_entity(request, Playlist, 'playlistId')
status, res = get_entity(Playlist, 'playlistId')
if not status:
return res