mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 08:56:17 +00:00
Fix Folder ID bugs and sqlite migration.
This commit is contained in:
parent
99ce42c9ff
commit
81192bfeca
@ -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 *
|
||||
|
@ -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)
|
||||
|
@ -29,7 +29,7 @@ try:
|
||||
except ImportError:
|
||||
from urlparse import urlparse, parse_qsl
|
||||
|
||||
SCHEMA_VERSION = "20190518"
|
||||
SCHEMA_VERSION = "20190915"
|
||||
|
||||
|
||||
def now():
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user