mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
Finish documentation for all endpoints
+ fix #193 (settings https redirect) + fix open api docs on binary + fix git error on binary + remove flask-restful hopefully, I didn't break something 😩
This commit is contained in:
committed by
Mungai Njoroge
parent
99ec11565c
commit
0af1ae1d8e
+76
-42
@@ -1,88 +1,122 @@
|
||||
from pathlib import Path
|
||||
from flask_openapi3 import Tag
|
||||
from flask_openapi3 import APIBlueprint
|
||||
from pydantic import BaseModel, Field
|
||||
from flask import send_from_directory
|
||||
|
||||
from flask import Blueprint, send_from_directory
|
||||
from app.settings import Defaults, Paths
|
||||
|
||||
from app.settings import Paths
|
||||
|
||||
api = Blueprint("imgserver", __name__, url_prefix="/img")
|
||||
|
||||
|
||||
@api.route("/")
|
||||
def hello():
|
||||
return "<h1>Image Server</h1>"
|
||||
bp_tag = Tag(
|
||||
name="Images", description="Image filenames are constructured as '{itemhash}.webp'"
|
||||
)
|
||||
api = APIBlueprint("imgserver", __name__, url_prefix="/img", abp_tags=[bp_tag])
|
||||
|
||||
|
||||
def send_fallback_img(filename: str = "default.webp"):
|
||||
path = Paths.get_assets_path()
|
||||
img = Path(path) / filename
|
||||
folder = Paths.get_assets_path()
|
||||
img = Path(folder) / filename
|
||||
|
||||
if not img.exists():
|
||||
return "", 404
|
||||
|
||||
return send_from_directory(path, filename)
|
||||
return send_from_directory(folder, filename)
|
||||
|
||||
|
||||
@api.route("/t/o/<imgpath>")
|
||||
def send_original_thumbnail(imgpath: str):
|
||||
path = Paths.get_original_thumb_path()
|
||||
fpath = Path(path) / imgpath
|
||||
class ImagePath(BaseModel):
|
||||
imgpath: str = Field(
|
||||
description="The image filename",
|
||||
example=Defaults.API_ALBUMHASH + ".webp",
|
||||
)
|
||||
|
||||
|
||||
@api.get("/t/o/<imgpath>")
|
||||
def send_original_thumbnail(path: ImagePath):
|
||||
"""
|
||||
Get original thumbnail
|
||||
"""
|
||||
folder = Paths.get_original_thumb_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(path, imgpath)
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img()
|
||||
|
||||
|
||||
@api.route("/t/<imgpath>")
|
||||
def send_lg_thumbnail(imgpath: str):
|
||||
path = Paths.get_lg_thumb_path()
|
||||
fpath = Path(path) / imgpath
|
||||
@api.get("/t/<imgpath>")
|
||||
def send_lg_thumbnail(path: ImagePath):
|
||||
"""
|
||||
Get large thumbnail (500 x 500)
|
||||
"""
|
||||
folder = Paths.get_lg_thumb_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(path, imgpath)
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img()
|
||||
|
||||
|
||||
@api.route("/t/s/<imgpath>")
|
||||
def send_sm_thumbnail(imgpath: str):
|
||||
path = Paths.get_sm_thumb_path()
|
||||
fpath = Path(path) / imgpath
|
||||
@api.get("/t/s/<imgpath>")
|
||||
def send_sm_thumbnail(path: ImagePath):
|
||||
"""
|
||||
Get small thumbnail (64 x 64)
|
||||
"""
|
||||
folder = Paths.get_sm_thumb_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(path, imgpath)
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img()
|
||||
|
||||
|
||||
@api.route("/a/<imgpath>")
|
||||
def send_lg_artist_image(imgpath: str):
|
||||
path = Paths.get_artist_img_lg_path()
|
||||
fpath = Path(path) / imgpath
|
||||
@api.get("/a/<imgpath>")
|
||||
def send_lg_artist_image(path: ImagePath):
|
||||
"""
|
||||
Get large artist image (500 x 500)
|
||||
"""
|
||||
folder = Paths.get_artist_img_lg_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(path, imgpath)
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img("artist.webp")
|
||||
|
||||
|
||||
@api.route("/a/s/<imgpath>")
|
||||
def send_sm_artist_image(imgpath: str):
|
||||
path = Paths.get_artist_img_sm_path()
|
||||
fpath = Path(path) / imgpath
|
||||
@api.get("/a/s/<imgpath>")
|
||||
def send_sm_artist_image(path: ImagePath):
|
||||
"""
|
||||
Get small artist image (64 x 64)
|
||||
"""
|
||||
folder = Paths.get_artist_img_sm_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(path, imgpath)
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img("artist.webp")
|
||||
|
||||
|
||||
@api.route("/p/<imgpath>")
|
||||
def send_playlist_image(imgpath: str):
|
||||
path = Paths.get_playlist_img_path()
|
||||
fpath = Path(path) / imgpath
|
||||
class PlaylistImagePath(BaseModel):
|
||||
imgpath: str = Field(
|
||||
description="The image path",
|
||||
example="1.webp",
|
||||
)
|
||||
|
||||
|
||||
@api.get("/p/<imgpath>")
|
||||
def send_playlist_image(path: PlaylistImagePath):
|
||||
"""
|
||||
Get playlist image
|
||||
|
||||
Images are constructed as '{playlist_id}.webp'
|
||||
"""
|
||||
folder = Paths.get_playlist_img_path()
|
||||
fpath = Path(folder) / path.imgpath
|
||||
|
||||
if fpath.exists():
|
||||
return send_from_directory(path, imgpath)
|
||||
return send_from_directory(folder, path.imgpath)
|
||||
|
||||
return send_fallback_img("playlist.svg")
|
||||
|
||||
Reference in New Issue
Block a user