provide fallback image

return fallback image if image is not found @imgserver
This commit is contained in:
geoffrey45
2022-06-20 13:00:59 +03:00
parent 12c8406a0d
commit 84880f8cad
3 changed files with 56 additions and 12 deletions
+19 -10
View File
@@ -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)