formatting / CORS changes
This commit is contained in:
@@ -23,7 +23,9 @@ class Meme(FastAPI):
|
||||
for endpoint, handler in self.endpoints.items():
|
||||
dependencies = None
|
||||
if endpoint == "memes/list_memes":
|
||||
dependencies = [Depends(RateLimiter(times=10, seconds=2))] # Do not rate limit image retrievals (cached)
|
||||
dependencies = [
|
||||
Depends(RateLimiter(times=10, seconds=2))
|
||||
] # Do not rate limit image retrievals (cached)
|
||||
app.add_api_route(
|
||||
f"/{endpoint}",
|
||||
handler,
|
||||
|
@@ -3,9 +3,11 @@ from fastapi import FastAPI, Request, Response, Depends
|
||||
from fastapi_throttle import RateLimiter
|
||||
from fastapi.responses import JSONResponse
|
||||
from utils.hifi_wrapper import HifiUtil
|
||||
from auth.deps import get_current_user
|
||||
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
|
||||
|
||||
class RIP(FastAPI):
|
||||
"""
|
||||
Ripping Endpoints
|
||||
@@ -25,7 +27,9 @@ class RIP(FastAPI):
|
||||
}
|
||||
|
||||
for endpoint, handler in self.endpoints.items():
|
||||
dependencies = [Depends(RateLimiter(times=8, seconds=2))] # Do not rate limit image retrievals (cached)
|
||||
dependencies = [
|
||||
Depends(RateLimiter(times=8, seconds=2))
|
||||
] # Do not rate limit image retrievals (cached)
|
||||
app.add_api_route(
|
||||
f"/{endpoint}",
|
||||
handler,
|
||||
@@ -34,36 +38,46 @@ class RIP(FastAPI):
|
||||
dependencies=dependencies,
|
||||
)
|
||||
|
||||
async def artists_by_name_handler(self, artist: str, request: Request) -> Response:
|
||||
async def artists_by_name_handler(
|
||||
self, artist: str, request: Request, user=Depends(get_current_user)
|
||||
) -> Response:
|
||||
"""Get artists by name"""
|
||||
artists = await self.trip_util.get_artists_by_name(artist)
|
||||
if not artists:
|
||||
return Response(status_code=404, content="Not found")
|
||||
return JSONResponse(content=artists)
|
||||
|
||||
async def albums_by_artist_id_handler(self, artist_id: int, request: Request) -> Response:
|
||||
|
||||
async def albums_by_artist_id_handler(
|
||||
self, artist_id: int, request: Request, user=Depends(get_current_user)
|
||||
) -> Response:
|
||||
"""Get albums by artist ID"""
|
||||
albums = await self.trip_util.get_albums_by_artist_id(artist_id)
|
||||
if not albums:
|
||||
return Response(status_code=404, content="Not found")
|
||||
return JSONResponse(content=albums)
|
||||
|
||||
async def tracks_by_album_id_handler(self, album_id: int, request: Request) -> Response:
|
||||
|
||||
async def tracks_by_album_id_handler(
|
||||
self, album_id: int, request: Request, user=Depends(get_current_user)
|
||||
) -> Response:
|
||||
"""Get tracks by album id"""
|
||||
tracks = await self.trip_util.get_tracks_by_album_id(album_id)
|
||||
if not tracks:
|
||||
return Response(status_code=404, content="Not Found")
|
||||
return JSONResponse(content=tracks)
|
||||
|
||||
async def tracks_by_artist_song_handler(self, artist: str, song: str, request: Request) -> Response:
|
||||
async def tracks_by_artist_song_handler(
|
||||
self, artist: str, song: str, request: Request, user=Depends(get_current_user)
|
||||
) -> Response:
|
||||
"""Get tracks by artist and song name"""
|
||||
logging.critical("Searching for tracks by artist: %s, song: %s", artist, song)
|
||||
tracks = await self.trip_util.get_tracks_by_artist_song(artist, song)
|
||||
if not tracks:
|
||||
return Response(status_code=404, content="Not found")
|
||||
return JSONResponse(content=tracks)
|
||||
|
||||
async def track_by_id_handler(self, track_id: int, request: Request) -> Response:
|
||||
|
||||
async def track_by_id_handler(
|
||||
self, track_id: int, request: Request, user=Depends(get_current_user)
|
||||
) -> Response:
|
||||
"""Get track by ID"""
|
||||
track = await self.trip_util.get_stream_url_by_track_id(track_id)
|
||||
if not track:
|
||||
|
Reference in New Issue
Block a user