chore: make sure that there is only one app
This commit is contained in:
@@ -4,11 +4,7 @@ from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from src.core.entities.series import Serie
|
||||
from src.server.utils.dependencies import (
|
||||
get_optional_series_app,
|
||||
get_series_app,
|
||||
require_auth,
|
||||
)
|
||||
from src.server.utils.dependencies import get_series_app, require_auth
|
||||
|
||||
router = APIRouter(prefix="/api/anime", tags=["anime"])
|
||||
|
||||
@@ -50,51 +46,6 @@ async def get_anime_status(
|
||||
) from exc
|
||||
|
||||
|
||||
@router.get("/process/locks")
|
||||
async def get_process_locks(
|
||||
_auth: dict = Depends(require_auth),
|
||||
series_app: Any = Depends(get_series_app),
|
||||
) -> dict:
|
||||
"""Get process lock status for rescan and download operations.
|
||||
|
||||
Args:
|
||||
_auth: Ensures the caller is authenticated (value unused)
|
||||
series_app: Core `SeriesApp` instance provided via dependency
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: Lock status information
|
||||
|
||||
Raises:
|
||||
HTTPException: If lock status retrieval fails
|
||||
"""
|
||||
try:
|
||||
locks = {
|
||||
"rescan": {"is_locked": False},
|
||||
"download": {"is_locked": False}
|
||||
}
|
||||
|
||||
# Check if SeriesApp has lock status methods
|
||||
if series_app:
|
||||
if hasattr(series_app, "isRescanning"):
|
||||
locks["rescan"]["is_locked"] = series_app.isRescanning()
|
||||
if hasattr(series_app, "isDownloading"):
|
||||
locks["download"]["is_locked"] = series_app.isDownloading()
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"locks": locks
|
||||
}
|
||||
except Exception as exc:
|
||||
return {
|
||||
"success": False,
|
||||
"error": str(exc),
|
||||
"locks": {
|
||||
"rescan": {"is_locked": False},
|
||||
"download": {"is_locked": False}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class AnimeSummary(BaseModel):
|
||||
"""Summary of an anime series with missing episodes."""
|
||||
key: str # Unique identifier (used as id in frontend)
|
||||
@@ -402,7 +353,7 @@ class SearchAnimeRequest(BaseModel):
|
||||
@router.get("/search", response_model=List[AnimeSummary])
|
||||
async def search_anime_get(
|
||||
query: str,
|
||||
series_app: Optional[Any] = Depends(get_optional_series_app),
|
||||
series_app: Optional[Any] = Depends(get_series_app),
|
||||
) -> List[AnimeSummary]:
|
||||
"""Search the provider for additional series matching a query (GET).
|
||||
|
||||
@@ -425,7 +376,7 @@ async def search_anime_get(
|
||||
)
|
||||
async def search_anime_post(
|
||||
request: SearchAnimeRequest,
|
||||
series_app: Optional[Any] = Depends(get_optional_series_app),
|
||||
series_app: Optional[Any] = Depends(get_series_app),
|
||||
) -> List[AnimeSummary]:
|
||||
"""Search the provider for additional series matching a query (POST).
|
||||
|
||||
@@ -591,7 +542,7 @@ async def add_series(
|
||||
@router.get("/{anime_id}", response_model=AnimeDetail)
|
||||
async def get_anime(
|
||||
anime_id: str,
|
||||
series_app: Optional[Any] = Depends(get_optional_series_app)
|
||||
series_app: Optional[Any] = Depends(get_series_app)
|
||||
) -> AnimeDetail:
|
||||
"""Return detailed information about a specific series.
|
||||
|
||||
@@ -649,46 +600,6 @@ async def get_anime(
|
||||
) from exc
|
||||
|
||||
|
||||
# Test endpoint for input validation
|
||||
class AnimeCreateRequest(BaseModel):
|
||||
"""Request model for creating anime (test endpoint)."""
|
||||
|
||||
title: str
|
||||
description: Optional[str] = None
|
||||
|
||||
|
||||
# Maximum allowed input size for security
|
||||
MAX_INPUT_LENGTH = 100000 # 100KB
|
||||
|
||||
|
||||
@router.post("", include_in_schema=False, status_code=status.HTTP_201_CREATED)
|
||||
async def create_anime_test(request: AnimeCreateRequest):
|
||||
"""Test endpoint for input validation testing.
|
||||
|
||||
This endpoint validates input sizes and content for security testing.
|
||||
Not used in production - only for validation tests.
|
||||
"""
|
||||
# Validate input size
|
||||
if len(request.title) > MAX_INPUT_LENGTH:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,
|
||||
detail="Title exceeds maximum allowed length",
|
||||
)
|
||||
|
||||
if request.description and len(request.description) > MAX_INPUT_LENGTH:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,
|
||||
detail="Description exceeds maximum allowed length",
|
||||
)
|
||||
|
||||
# Return success for valid input
|
||||
return {
|
||||
"status": "success",
|
||||
"message": "Anime created (test mode)",
|
||||
"data": {
|
||||
"title": request.title[:100], # Truncated for response
|
||||
"description": (
|
||||
request.description[:100] if request.description else None
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user