rm test.conf

This commit is contained in:
2025-12-18 07:30:39 -05:00
parent 041de95698
commit bc8b407a91
12 changed files with 348 additions and 303 deletions

View File

@@ -75,7 +75,11 @@ class RIP(FastAPI):
app.add_api_route(
f"/{endpoint}",
handler,
methods=["GET"] if endpoint not in ("trip/bulk_fetch", "trip/auth/check") else ["POST"],
methods=(
["GET"]
if endpoint not in ("trip/bulk_fetch", "trip/auth/check")
else ["POST"]
),
include_in_schema=False,
dependencies=dependencies,
)
@@ -131,9 +135,11 @@ class RIP(FastAPI):
"started_at": job.started_at,
"ended_at": job.ended_at,
"progress": progress,
"tracks": f"{succeeded_tracks} / {tracks_in}"
if isinstance(tracks_in, int)
else tracks_out,
"tracks": (
f"{succeeded_tracks} / {tracks_in}"
if isinstance(tracks_in, int)
else tracks_out
),
"target": job.meta.get("target"),
"quality": job.meta.get("quality", "Unknown"),
}
@@ -153,7 +159,7 @@ class RIP(FastAPI):
- **Response**: JSON response with artists or 404.
"""
if "trip" not in user.get("roles", []) and "admin" not in user.get("roles", []):
raise HTTPException(status_code=403, detail="Insufficient permissions")
raise HTTPException(status_code=403, detail="Insufficient permissions")
# support optional grouping to return one primary per display name
# with `alternatives` for disambiguation (use ?group=true)
group = bool(request.query_params.get("group", False))
@@ -177,7 +183,7 @@ class RIP(FastAPI):
- **Response**: JSON response with albums or 404.
"""
if "trip" not in user.get("roles", []) and "admin" not in user.get("roles", []):
raise HTTPException(status_code=403, detail="Insufficient permissions")
raise HTTPException(status_code=403, detail="Insufficient permissions")
albums = await self.trip_util.get_albums_by_artist_id(artist_id)
if not albums:
return Response(status_code=404, content="Not found")
@@ -203,7 +209,7 @@ class RIP(FastAPI):
- **Response**: JSON response with tracks or 404.
"""
if "trip" not in user.get("roles", []) and "admin" not in user.get("roles", []):
raise HTTPException(status_code=403, detail="Insufficient permissions")
raise HTTPException(status_code=403, detail="Insufficient permissions")
tracks = await self.trip_util.get_tracks_by_album_id(album_id, quality)
if not tracks:
return Response(status_code=404, content="Not Found")
@@ -225,7 +231,7 @@ class RIP(FastAPI):
- **Response**: JSON response with tracks or 404.
"""
if "trip" not in user.get("roles", []) and "admin" not in user.get("roles", []):
raise HTTPException(status_code=403, detail="Insufficient permissions")
raise HTTPException(status_code=403, detail="Insufficient permissions")
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:
@@ -252,7 +258,7 @@ class RIP(FastAPI):
- **Response**: JSON response with stream URL or 404.
"""
if "trip" not in user.get("roles", []) and "admin" not in user.get("roles", []):
raise HTTPException(status_code=403, detail="Insufficient permissions")
raise HTTPException(status_code=403, detail="Insufficient permissions")
track = await self.trip_util.get_stream_url_by_track_id(track_id, quality)
if not track:
return Response(status_code=404, content="Not found")
@@ -276,7 +282,7 @@ class RIP(FastAPI):
- **Response**: JSON response with job info or error.
"""
if "trip" not in user.get("roles", []) and "admin" not in user.get("roles", []):
raise HTTPException(status_code=403, detail="Insufficient permissions")
raise HTTPException(status_code=403, detail="Insufficient permissions")
if not data or not data.track_ids or not data.target:
return JSONResponse(
content={
@@ -329,7 +335,7 @@ class RIP(FastAPI):
- **JSONResponse**: Job status and result or error.
"""
if "trip" not in user.get("roles", []) and "admin" not in user.get("roles", []):
raise HTTPException(status_code=403, detail="Insufficient permissions")
raise HTTPException(status_code=403, detail="Insufficient permissions")
job = None
try:
# Try direct fetch first
@@ -368,7 +374,7 @@ class RIP(FastAPI):
- **JSONResponse**: List of jobs.
"""
if "trip" not in user.get("roles", []) and "admin" not in user.get("roles", []):
raise HTTPException(status_code=403, detail="Insufficient permissions")
raise HTTPException(status_code=403, detail="Insufficient permissions")
jobs_info = []
seen = set()
@@ -426,7 +432,7 @@ class RIP(FastAPI):
):
"""
Start Tidal device authorization flow.
Returns a URL that the user must visit to authorize the application.
After visiting the URL and authorizing, call /trip/auth/check to complete.
@@ -434,8 +440,10 @@ class RIP(FastAPI):
- **JSONResponse**: Contains device_code and verification_url.
"""
try:
if "trip" not in user.get("roles", []) and "admin" not in user.get("roles", []):
raise HTTPException(status_code=403, detail="Insufficient permissions")
if "trip" not in user.get("roles", []) and "admin" not in user.get(
"roles", []
):
raise HTTPException(status_code=403, detail="Insufficient permissions")
device_code, verification_url = await self.trip_util.start_device_auth()
# Store device code for this session
self._pending_device_codes[user.get("sub", "default")] = device_code
@@ -458,18 +466,20 @@ class RIP(FastAPI):
):
"""
Check if Tidal device authorization is complete.
Call this after the user has visited the verification URL.
Returns:
- **JSONResponse**: Contains success status and message.
"""
if "trip" not in user.get("roles", []) and "admin" not in user.get("roles", []):
raise HTTPException(status_code=403, detail="Insufficient permissions")
raise HTTPException(status_code=403, detail="Insufficient permissions")
device_code = self._pending_device_codes.get(user.get("sub", "default"))
if not device_code:
return JSONResponse(
content={"error": "No pending authorization. Call /trip/auth/start first."},
content={
"error": "No pending authorization. Call /trip/auth/start first."
},
status_code=400,
)
@@ -479,11 +489,18 @@ class RIP(FastAPI):
# Clear the pending code
self._pending_device_codes.pop(user.get("sub", "default"), None)
return JSONResponse(
content={"success": True, "message": "Tidal authorization complete!"}
content={
"success": True,
"message": "Tidal authorization complete!",
}
)
elif error == "pending":
return JSONResponse(
content={"success": False, "pending": True, "message": "Waiting for user to authorize..."}
content={
"success": False,
"pending": True,
"message": "Waiting for user to authorize...",
}
)
else:
return JSONResponse(