mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
check if track exists in db before sending file
This commit is contained in:
+9
-15
@@ -185,20 +185,13 @@ def get_all_favorites():
|
||||
artists = remove_none(artists)
|
||||
|
||||
recents = []
|
||||
first_n = favs[:album_limit]
|
||||
# first_n = favs
|
||||
|
||||
for fav in first_n:
|
||||
if fav[2] == FavType.track:
|
||||
try:
|
||||
track = [t for t in tracks if t.trackhash == fav[1]][0]
|
||||
recents.append({
|
||||
"type": "track",
|
||||
"item": recent_fav_track_serializer(track)
|
||||
})
|
||||
except IndexError:
|
||||
pass
|
||||
for fav in favs:
|
||||
if len(recents) >= largest:
|
||||
break
|
||||
|
||||
elif fav[2] == FavType.album:
|
||||
if fav[2] == FavType.album:
|
||||
try:
|
||||
album = [a for a in albums if a.albumhash == fav[1]][0]
|
||||
recents.append({
|
||||
@@ -206,8 +199,9 @@ def get_all_favorites():
|
||||
"item": recent_fav_album_serializer(album)
|
||||
})
|
||||
except IndexError:
|
||||
pass
|
||||
elif fav[2] == FavType.artist:
|
||||
continue
|
||||
|
||||
if fav[2] == FavType.artist:
|
||||
try:
|
||||
artist = [a for a in artists if a.artisthash == fav[1]][0]
|
||||
recents.append({
|
||||
@@ -215,7 +209,7 @@ def get_all_favorites():
|
||||
"item": recent_fav_artist_serializer(artist)
|
||||
})
|
||||
except IndexError:
|
||||
pass
|
||||
continue
|
||||
|
||||
return {
|
||||
"recents": recents[:album_limit],
|
||||
|
||||
+11
-3
@@ -24,9 +24,17 @@ def send_track_file(trackhash: str):
|
||||
|
||||
filepath = request.args.get("filepath")
|
||||
|
||||
if filepath is not None and os.path.exists(filepath):
|
||||
audio_type = get_mime(filepath)
|
||||
return send_file(filepath, mimetype=audio_type)
|
||||
if filepath is not None:
|
||||
try:
|
||||
track = TrackStore.get_tracks_by_filepaths([filepath])[0]
|
||||
except IndexError:
|
||||
track = None
|
||||
|
||||
track_exists = track is not None and os.path.exists(track.filepath)
|
||||
|
||||
if track_exists:
|
||||
audio_type = get_mime(filepath)
|
||||
return send_file(filepath, mimetype=audio_type)
|
||||
|
||||
if trackhash is None:
|
||||
return msg, 404
|
||||
|
||||
Reference in New Issue
Block a user