diff --git a/src/server/api/health.py b/src/server/api/health.py index 2ff3b40..aad7626 100644 --- a/src/server/api/health.py +++ b/src/server/api/health.py @@ -17,12 +17,15 @@ logger = logging.getLogger(__name__) router = APIRouter(prefix="/health", tags=["health"]) +from src.server.utils.version import APP_VERSION + + class HealthStatus(BaseModel): """Basic health status response.""" status: str timestamp: str - version: str = "1.0.1" + version: str = APP_VERSION service: str = "aniworld-api" series_app_initialized: bool = False anime_directory_configured: bool = False @@ -63,7 +66,7 @@ class DetailedHealthStatus(BaseModel): status: str timestamp: str - version: str = "1.0.1" + version: str = APP_VERSION dependencies: DependencyHealth startup_time: datetime diff --git a/src/server/fastapi_app.py b/src/server/fastapi_app.py index 6968dc9..9cb5827 100644 --- a/src/server/fastapi_app.py +++ b/src/server/fastapi_app.py @@ -214,6 +214,7 @@ async def lifespan(_application: FastAPI): """ # Setup logging first with INFO level logger = setup_logging(log_level="INFO") + logger.info("Starting FastAPI application v%s", APP_VERSION) # Track successful initialization steps initialized = { @@ -410,9 +411,7 @@ async def lifespan(_application: FastAPI): # anime_directory may be configured there even if the env var is empty. try: logger.info("Initializing scheduler service...") - from src.server.services.scheduler_service import ( - get_scheduler_service, - ) + from src.server.services.scheduler_service import get_scheduler_service scheduler_service = get_scheduler_service() logger.info("Scheduler service instance obtained, starting...") await scheduler_service.start() @@ -542,8 +541,8 @@ async def lifespan(_application: FastAPI): # 4. Shutdown download service and persist active downloads try: - from src.server.services.download_service import ( # noqa: E501 - _download_service_instance, + from src.server.services.download_service import ( + _download_service_instance, # noqa: E501 ) if _download_service_instance is not None: logger.info("Stopping download service...") @@ -600,11 +599,13 @@ async def lifespan(_application: FastAPI): raise startup_error +from src.server.utils.version import APP_VERSION + # Initialize FastAPI app with lifespan app = FastAPI( title="Aniworld Download Manager", description="Modern web interface for Aniworld anime download management", - version="1.0.1", + version=APP_VERSION, docs_url="/api/docs", redoc_url="/api/redoc", lifespan=lifespan diff --git a/src/server/utils/template_helpers.py b/src/server/utils/template_helpers.py index 561cc03..0145419 100644 --- a/src/server/utils/template_helpers.py +++ b/src/server/utils/template_helpers.py @@ -21,6 +21,8 @@ from typing import Any, Dict, List, Optional from fastapi import Request from fastapi.templating import Jinja2Templates +from src.server.utils.version import APP_VERSION + logger = logging.getLogger(__name__) # Configure templates directory @@ -48,7 +50,7 @@ def get_base_context( "request": request, "title": title, "app_name": "Aniworld Download Manager", - "version": "1.0.1", + "version": APP_VERSION, "static_v": STATIC_VERSION, } diff --git a/src/server/utils/version.py b/src/server/utils/version.py new file mode 100644 index 0000000..1f55d82 --- /dev/null +++ b/src/server/utils/version.py @@ -0,0 +1,26 @@ +"""Version management utilities for Aniworld application.""" + +from pathlib import Path +from typing import Optional + + +def get_version() -> str: + """ + Get the current application version from Docker/VERSION file. + + Returns: + Version string from the VERSION file, or "unknown" if not found. + """ + version_file = Path(__file__).parent.parent.parent.parent / "Docker" / "VERSION" + + try: + if version_file.exists(): + return version_file.read_text().strip() + except Exception: + pass + + return "unknown" + + +# Module-level version constant (loaded once at import) +APP_VERSION: str = get_version() \ No newline at end of file