mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-10 13:07:35 +00:00

+ fix bug that caused duplicate artist color entries to db + check if app is windows (prep for windows build) + remove caribou migrations lib + rename all api blueprints to "api" + unregister child directories when customizing root dirs + misc
35 lines
815 B
Python
35 lines
815 B
Python
"""
|
|
Contains all the track routes.
|
|
"""
|
|
from flask import Blueprint, send_file
|
|
|
|
from app.db.store import Store
|
|
|
|
api = Blueprint("track", __name__, url_prefix="/")
|
|
|
|
|
|
@api.route("/file/<trackhash>")
|
|
def send_track_file(trackhash: str):
|
|
"""
|
|
Returns an audio file that matches the passed id to the client.
|
|
Falls back to track hash if id is not found.
|
|
"""
|
|
msg = {"msg": "File Not Found"}
|
|
if trackhash is None:
|
|
return msg, 404
|
|
|
|
try:
|
|
track = Store.get_tracks_by_trackhashes([trackhash])[0]
|
|
except IndexError:
|
|
track = None
|
|
|
|
if track is None:
|
|
return msg, 404
|
|
|
|
audio_type = track.filepath.rsplit(".", maxsplit=1)[-1]
|
|
|
|
try:
|
|
return send_file(track.filepath, mimetype=f"audio/{audio_type}")
|
|
except FileNotFoundError:
|
|
return msg, 404
|