Resolves #14
This commit is contained in:
parent
17da906826
commit
2f4daca71c
@ -35,6 +35,41 @@ class ValidLyricRequest(BaseModel):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ValidLyricRequest(BaseModel):
|
||||
"""
|
||||
- **a**: artist
|
||||
- **s**: song
|
||||
- **t**: track (artist and song combined) [used only if a & s are not used]
|
||||
- **extra**: include extra details in response [optional, default: false]
|
||||
- **sub**: text to search within lyrics, if found lyrics will begin at found verse [optional]
|
||||
- **src**: the script/utility which initiated the request
|
||||
"""
|
||||
|
||||
a: str | None = None
|
||||
s: str | None = None
|
||||
t: str | None = None
|
||||
sub: str | None = None
|
||||
extra: bool | None = False
|
||||
src: str
|
||||
|
||||
class Config: # pylint: disable=missing-class-docstring too-few-public-methods
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"a": "eminem",
|
||||
"s": "rap god",
|
||||
"src": "WEB",
|
||||
"extra": True
|
||||
}
|
||||
}
|
||||
|
||||
class ValidLyricSearchLogRequest(BaseModel):
|
||||
"""
|
||||
- **webradio**: whether or not to include requests generated automatically by the radio page on codey.lol, defaults to False
|
||||
"""
|
||||
|
||||
webradio: bool = False
|
||||
|
||||
class LyricSearch(FastAPI):
|
||||
"""Lyric Search Endpoint"""
|
||||
def __init__(self, app: FastAPI, util, constants, glob_state): # pylint: disable=super-init-not-called
|
||||
@ -50,6 +85,7 @@ class LyricSearch(FastAPI):
|
||||
self.endpoints = {
|
||||
"lyric_search": self.lyric_search_handler,
|
||||
"lyric_cache_list": self.lyric_cache_list_handler,
|
||||
"lyric_search_history": self.lyric_search_log_handler
|
||||
}
|
||||
|
||||
self.acceptable_request_sources = [
|
||||
@ -73,6 +109,16 @@ class LyricSearch(FastAPI):
|
||||
'err': False,
|
||||
'data': await self.lyrics_engine.listCacheEntries()
|
||||
}
|
||||
|
||||
async def lyric_search_log_handler(self, data: ValidLyricSearchLogRequest):
|
||||
include_radio = data.webradio
|
||||
await self.glob_state.increment_counter('lyrichistory_requests')
|
||||
last_10k_sings = await self.lyrics_engine.getHistory(limit=10000, webradio=include_radio)
|
||||
return {
|
||||
'err': False,
|
||||
'history': last_10k_sings
|
||||
}
|
||||
|
||||
|
||||
async def lyric_search_handler(self, data: ValidLyricRequest):
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user