Add global state module
This commit is contained in:
@ -37,10 +37,11 @@ class ValidLyricRequest(BaseModel):
|
||||
|
||||
class LyricSearch(FastAPI):
|
||||
"""Lyric Search Endpoint"""
|
||||
def __init__(self, app: FastAPI, util, constants): # pylint: disable=super-init-not-called
|
||||
def __init__(self, app: FastAPI, util, constants, glob_state): # pylint: disable=super-init-not-called
|
||||
self.app = app
|
||||
self.util = util
|
||||
self.constants = constants
|
||||
self.glob_state = glob_state
|
||||
self.lyrics_engine = importlib.import_module("lyrics_engine").LyricsEngine()
|
||||
|
||||
self.endpoint_name = "lyric_search"
|
||||
@ -87,7 +88,9 @@ class LyricSearch(FastAPI):
|
||||
|
||||
src = data.src.upper()
|
||||
if not src in self.acceptable_request_sources:
|
||||
raise HTTPException(detail="Invalid request source", status_code=403)
|
||||
raise HTTPException(detail="Invalid request source", status_code=403)
|
||||
|
||||
await self.glob_state.increment_counter('lyric_requests')
|
||||
|
||||
search_artist = data.a
|
||||
search_song = data.s
|
||||
@ -128,6 +131,7 @@ class LyricSearch(FastAPI):
|
||||
recipient='anyone')
|
||||
|
||||
if not search_worker or not 'l' in search_worker.keys():
|
||||
await self.glob_state.increment_counter('failedlyric_requests')
|
||||
return {
|
||||
'err': True,
|
||||
'errorText': 'Sources exhausted, lyrics not located.'
|
||||
@ -141,4 +145,5 @@ class LyricSearch(FastAPI):
|
||||
'lyrics': regex.sub(r"\s/\s", "<br>", " ".join(search_worker['l'])),
|
||||
'from_cache': search_worker['method'].strip().lower().startswith("local cache"),
|
||||
'src': search_worker['method'] if add_extras else None,
|
||||
'reqn': await self.glob_state.get_counter('lyric_requests')
|
||||
}
|
||||
|
Reference in New Issue
Block a user