diff --git a/supysonic/api/__init__.py b/supysonic/api/__init__.py index 7d8e485..93c70f5 100644 --- a/supysonic/api/__init__.py +++ b/supysonic/api/__init__.py @@ -97,8 +97,11 @@ def get_entity_id(cls, eid): try: return int(eid) except ValueError: - raise ValueError("Invalid Folder ID: %s", eid) - return uuid.UUID(eid) + return None + try: + return uuid.UUID(eid) + except ValueError: + return None from .errors import * diff --git a/supysonic/api/media.py b/supysonic/api/media.py index c26763c..45a1639 100644 --- a/supysonic/api/media.py +++ b/supysonic/api/media.py @@ -35,7 +35,7 @@ from ..covers import get_embedded_cover from ..db import Track, Album, Artist, Folder, User, ClientPrefs, now from ..py23 import dict -from . import api, get_entity +from . import api, get_entity, get_entity_id from .exceptions import ( GenericError, MissingParameter, @@ -215,15 +215,19 @@ def download_media(): @api.route("/getCoverArt.view", methods=["GET", "POST"]) def cover_art(): cache = current_app.cache + eid = request.values["id"] - if Folder.exists(id=eid): + fid = get_entity_id(Folder, eid) + tid = get_entity_id(Track, eid) + + if fid and Folder.exists(id=eid): res = get_entity(Folder) if not res.cover_art or not os.path.isfile( os.path.join(res.path, res.cover_art) ): raise NotFound("Cover art") cover_path = os.path.join(res.path, res.cover_art) - elif Track.exists(id=eid): + elif tid and Track.exists(id=eid): cache_key = "{}-cover".format(eid) try: cover_path = cache.get(cache_key) diff --git a/supysonic/db.py b/supysonic/db.py index f079dfb..2da1152 100644 --- a/supysonic/db.py +++ b/supysonic/db.py @@ -29,7 +29,7 @@ try: except ImportError: from urlparse import urlparse, parse_qsl -SCHEMA_VERSION = "20190518" +SCHEMA_VERSION = "20190915" def now(): diff --git a/supysonic/schema/migration/sqlite/20190915.sql b/supysonic/schema/migration/sqlite/20190915.sql index 4823e2e..2e0062e 100644 --- a/supysonic/schema/migration/sqlite/20190915.sql +++ b/supysonic/schema/migration/sqlite/20190915.sql @@ -26,11 +26,18 @@ CREATE TABLE IF NOT EXISTS folder_new ( CREATE INDEX IF NOT EXISTS index_folder_parent_id_fk ON folder_new(parent_id); CREATE UNIQUE INDEX IF NOT EXISTS index_folder_path ON folder_new(path_hash); +INSERT INTO folder_new(id, root, name, path, path_hash, created, cover_art, last_scan, parent_id) +SELECT id_int.id, root, name, path, path_hash, created, cover_art, last_scan, NULL +FROM folder +JOIN folder_id_to_int id_int ON folder.id == id_int.uuid +WHERE folder.parent_id IS NULL; + INSERT INTO folder_new(id, root, name, path, path_hash, created, cover_art, last_scan, parent_id) SELECT id_int.id, root, name, path, path_hash, created, cover_art, last_scan, parent_id_int.id FROM folder JOIN folder_id_to_int id_int ON folder.id == id_int.uuid -JOIN folder_id_to_int parent_id_int ON folder.parent_id == parent_id_int.uuid; +JOIN folder_id_to_int parent_id_int ON folder.parent_id == parent_id_int.uuid +WHERE folder.parent_id IS NOT NULL; DROP TABLE folder; ALTER TABLE folder_new RENAME TO folder; @@ -94,7 +101,7 @@ CREATE INDEX IF NOT EXISTS index_starred_folder_starred_id_fk ON starred_folder_ INSERT INTO starred_folder_new(user_id, starred_id, date) SELECT user_id, id_int.id, date FROM starred_folder -JOIN folder_id_to_int id_int ON starred_folder_new.starred_id == id_int.uuid; +JOIN folder_id_to_int id_int ON starred_folder.starred_id == id_int.uuid; DROP TABLE starred_folder; ALTER TABLE starred_folder_new RENAME TO starred_folder;