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:
mungai-njoroge
2024-03-24 15:57:58 +03:00
committed by Mungai Njoroge
parent 99ec11565c
commit 0af1ae1d8e
22 changed files with 547 additions and 418 deletions
+24 -21
View File
@@ -1,5 +1,8 @@
from flask import Blueprint, request
from flask_openapi3 import Tag
from flask_openapi3 import APIBlueprint
from pydantic import Field
from app.api.apischemas import TrackHashSchema
from app.lib.lyrics import (
get_lyrics,
check_lyrics_file,
@@ -7,21 +10,24 @@ from app.lib.lyrics import (
get_lyrics_from_tags,
)
api = Blueprint("lyrics", __name__, url_prefix="")
bp_tag = Tag(name="Lyrics", description="Get lyrics")
api = APIBlueprint("lyrics", __name__, url_prefix="/lyrics", abp_tags=[bp_tag])
@api.route("/lyrics", methods=["POST"])
def send_lyrics():
class SendLyricsBody(TrackHashSchema):
filepath: str = Field(
description="The path to the file",
example="/path/to/file.mp3",
)
@api.post("")
def send_lyrics(body: SendLyricsBody):
"""
Returns the lyrics for a track
"""
data = request.get_json()
filepath = data.get("filepath", None)
trackhash = data.get("trackhash", None)
if filepath is None or trackhash is None:
return {"error": "No filepath or trackhash provided"}, 400
filepath = body.filepath
trackhash = body.trackhash
is_synced = True
lyrics, copyright = get_lyrics(filepath)
@@ -38,15 +44,13 @@ def send_lyrics():
return {"lyrics": lyrics, "synced": is_synced, "copyright": copyright}, 200
@api.route("/lyrics/check", methods=["POST"])
def check_lyrics():
data = request.get_json()
filepath = data.get("filepath", None)
trackhash = data.get("trackhash", None)
if filepath is None or trackhash is None:
return {"error": "No filepath or trackhash provided"}, 400
@api.post("/check")
def check_lyrics(body: SendLyricsBody):
"""
Checks if lyrics exist for a track
"""
filepath = body.filepath
trackhash = body.trackhash
exists = check_lyrics_file(filepath, trackhash)
@@ -56,4 +60,3 @@ def check_lyrics():
exists = get_lyrics_from_tags(filepath, just_check=True)
return {"exists": exists}, 200