various/stale

This commit is contained in:
2026-01-25 13:14:00 -05:00
parent 10ccf8c8eb
commit 97fd7dd67d
14 changed files with 501 additions and 64 deletions

27
base.py
View File

@@ -17,6 +17,7 @@ except ImportError:
from contextlib import asynccontextmanager
from typing import Any
from fastapi import FastAPI, Request
from fastapi.responses import RedirectResponse, HTMLResponse
from fastapi.middleware.cors import CORSMiddleware
from scalar_fastapi import get_scalar_api_reference
from lyric_search.sources import redis_cache
@@ -110,7 +111,31 @@ app.add_middleware(
# Scalar API documentation at /docs (replaces default Swagger UI)
@app.get("/docs", include_in_schema=False)
def scalar_docs():
return get_scalar_api_reference(openapi_url="/openapi.json", title="codey.lol API")
# Replace default FastAPI favicon with site favicon
html_response = get_scalar_api_reference(
openapi_url="/openapi.json", title="codey.lol API"
)
try:
body = (
html_response.body.decode("utf-8")
if isinstance(html_response.body, (bytes, bytearray))
else str(html_response.body)
)
body = body.replace(
"https://fastapi.tiangolo.com/img/favicon.png",
"https://codey.lol/images/favicon.png",
)
# Build fresh response so Content-Length matches modified body
return HTMLResponse(content=body, status_code=html_response.status_code)
except Exception:
# Fallback to original if anything goes wrong
return html_response
@app.get("/favicon.ico", include_in_schema=False)
async def favicon():
"""Redirect favicon requests to the site icon."""
return RedirectResponse("https://codey.lol/images/favicon.png")
"""