changes include: allow GET endpoints, redirect to codey.lol instead of returning status 422, clean junk from ai endpoint, add misc endpoint, add methods to lyric_search_new.sources.cache, other misc/cleanup
This commit is contained in:
13
util.py
13
util.py
@ -3,21 +3,20 @@
|
||||
import logging
|
||||
|
||||
from fastapi import FastAPI, Response, HTTPException
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
||||
|
||||
class Utilities:
|
||||
"""API Utilities"""
|
||||
def __init__(self, app: FastAPI, constants):
|
||||
self.constants = constants
|
||||
self.blocked_response_status = 422
|
||||
self.blocked_response_content = None
|
||||
self.blocked_redirect_uri = "https://codey.lol"
|
||||
self.app = app
|
||||
|
||||
def get_blocked_response(self, path: str | None = None): # pylint: disable=unused-argument
|
||||
"""Get Blocked HTTP Response"""
|
||||
logging.error("Rejected request: Blocked")
|
||||
return Response(content=self.blocked_response_content,
|
||||
status_code=self.blocked_response_status)
|
||||
return RedirectResponse(url=self.blocked_redirect_uri)
|
||||
|
||||
def get_no_endpoint_found(self, path: str | None = None): # pylint: disable=unused-argument
|
||||
"""Get 404 Response"""
|
||||
@ -29,27 +28,21 @@ class Utilities:
|
||||
Accepts path as an argument to allow fine tuning access for each API key, not currently in use.
|
||||
"""
|
||||
|
||||
# print(f"Testing with path: {path}, key: {key}")
|
||||
|
||||
if not key or not key.startswith("Bearer "):
|
||||
return False
|
||||
|
||||
key = key.split("Bearer ", maxsplit=1)[1].strip()
|
||||
|
||||
if not key in self.constants.API_KEYS:
|
||||
# print("Auth failed")
|
||||
return False
|
||||
|
||||
if req_type == 2:
|
||||
if not key.startswith("PRV-"):
|
||||
# print("Auth failed - not a PRV key")
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
if path.lower().startswith("/xc/") and not key.startswith("XC-"):
|
||||
# print("Auth failed - not an XC Key")
|
||||
return False
|
||||
|
||||
# print("Auth succeeded")
|
||||
return True
|
Reference in New Issue
Block a user