mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
provide fallback image
return fallback image if image is not found @imgserver
This commit is contained in:
@@ -12,11 +12,13 @@ def join(*args: Tuple[str]) -> str:
|
||||
|
||||
|
||||
HOME = path.expanduser("~")
|
||||
ROOT_PATH = path.join(HOME, ".alice", "images")
|
||||
APP_DIR = join(HOME, ".alice")
|
||||
IMG_PATH = path.join(APP_DIR, "images")
|
||||
|
||||
THUMB_PATH = join(ROOT_PATH, "thumbnails")
|
||||
ARTIST_PATH = join(ROOT_PATH, "artists")
|
||||
PLAYLIST_PATH = join(ROOT_PATH, "playlists")
|
||||
ASSETS_PATH = join(APP_DIR, "assets")
|
||||
THUMB_PATH = join(IMG_PATH, "thumbnails")
|
||||
ARTIST_PATH = join(IMG_PATH, "artists")
|
||||
PLAYLIST_PATH = join(IMG_PATH, "playlists")
|
||||
|
||||
|
||||
@app.route("/")
|
||||
@@ -24,6 +26,16 @@ def hello():
|
||||
return "Hello mf"
|
||||
|
||||
|
||||
def send_fallback_img():
|
||||
img = join(ASSETS_PATH, "default.webp")
|
||||
exists = path.exists(img)
|
||||
|
||||
if not exists:
|
||||
return "", 404
|
||||
|
||||
return send_from_directory(ASSETS_PATH, "default.webp")
|
||||
|
||||
|
||||
@app.route("/t/<imgpath>")
|
||||
def send_thumbnail(imgpath: str):
|
||||
fpath = join(THUMB_PATH, imgpath)
|
||||
@@ -32,7 +44,7 @@ def send_thumbnail(imgpath: str):
|
||||
if exists:
|
||||
return send_from_directory(THUMB_PATH, imgpath)
|
||||
|
||||
return {"msg": "Not found"}, 404
|
||||
return send_fallback_img()
|
||||
|
||||
|
||||
@app.route("/a/<imgpath>")
|
||||
@@ -43,7 +55,7 @@ def send_artist_image(imgpath: str):
|
||||
if exists:
|
||||
return send_from_directory(ARTIST_PATH, imgpath)
|
||||
|
||||
return {"msg": "Not found"}, 404
|
||||
return send_fallback_img()
|
||||
|
||||
|
||||
@app.route("/p/<imgpath>")
|
||||
@@ -54,11 +66,8 @@ def send_playlist_image(imgpath: str):
|
||||
if exists:
|
||||
return send_from_directory(PLAYLIST_PATH, imgpath)
|
||||
|
||||
return {"msg": "Not found"}, 404
|
||||
return send_fallback_img()
|
||||
|
||||
|
||||
# TODO
|
||||
# Return Fallback images instead of JSON
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(threaded=True, port=9877)
|
||||
|
||||
Reference in New Issue
Block a user