api/base.py

77 lines
2.0 KiB
Python
Raw Normal View History

2024-08-10 22:49:00 -04:00
#!/usr/bin/env python3.12
import importlib
import logging
2024-08-11 13:55:11 -04:00
from typing import Any
from fastapi import FastAPI
2024-08-14 22:43:20 -04:00
from fastapi.security import APIKeyHeader, APIKeyQuery
2024-08-10 22:49:00 -04:00
from fastapi.middleware.cors import CORSMiddleware
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
2024-08-15 20:29:41 -04:00
app = FastAPI(title="codey.lol API",
version="0.1a",
contact={
'name': 'codey'
})
2024-08-14 22:43:20 -04:00
2024-08-10 22:49:00 -04:00
constants = importlib.import_module("constants").Constants()
2024-08-14 22:43:20 -04:00
util = importlib.import_module("util").Utilities(app, constants)
2024-08-13 19:21:48 -04:00
glob_state = importlib.import_module("state").State(app, util, constants)
2024-08-10 22:49:00 -04:00
2024-08-14 22:43:20 -04:00
2024-08-10 22:49:00 -04:00
origins = [
"https://codey.lol",
]
app.add_middleware(CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["POST"],
allow_headers=["*"])
2024-08-13 19:21:48 -04:00
2024-08-10 22:49:00 -04:00
"""
Blacklisted routes
"""
@app.get("/")
def disallow_get():
return util.get_blocked_response()
2024-08-14 22:47:48 -04:00
@app.get("/{any:path}")
2024-08-14 22:43:20 -04:00
def disallow_get_any(var: Any = None):
2024-08-10 22:49:00 -04:00
return util.get_blocked_response()
@app.post("/")
def disallow_base_post():
return util.get_blocked_response()
"""
End Blacklisted Routes
"""
"""
Actionable Routes
"""
2024-08-13 19:21:48 -04:00
counter_endpoints = importlib.import_module("endpoints.counters").Counters(app, util, constants, glob_state)
randmsg_endpoint = importlib.import_module("endpoints.rand_msg").RandMsg(app, util, constants, glob_state)
transcription_endpoints = importlib.import_module("endpoints.transcriptions").Transcriptions(app, util, constants, glob_state)
2024-08-14 22:43:20 -04:00
ai_endpoints = importlib.import_module("endpoints.ai").AI(app, util, constants, glob_state)
2024-08-11 17:04:06 -04:00
# Below also provides: /lyric_cache_list/ (in addition to /lyric_search/)
2024-08-13 19:21:48 -04:00
lyric_search_endpoint = importlib.import_module("endpoints.lyric_search").LyricSearch(app, util, constants, glob_state)
2024-08-11 17:28:43 -04:00
# Below provides numerous LastFM-fed endpoints
2024-08-13 19:21:48 -04:00
lastfm_endpoints = importlib.import_module("endpoints.lastfm").LastFM(app, util, constants, glob_state)
2024-08-13 10:50:11 -04:00
# Below: YT endpoint(s)
2024-08-13 19:21:48 -04:00
yt_endpoints = importlib.import_module("endpoints.yt").YT(app, util, constants, glob_state)
2024-08-10 22:49:00 -04:00
2024-08-11 12:46:24 -04:00
2024-08-10 22:49:00 -04:00
"""
End Actionable Routes
"""