diff --git a/Docs/tasks.md b/Docs/tasks.md index 8c0f4fe..b7f7d38 100644 --- a/Docs/tasks.md +++ b/Docs/tasks.md @@ -1,12 +1,3 @@ -## Task 8: Download Log File — Endpoint should exist and return log file - -**Test Result:** FAIL — `Url: http://127.0.0.1:8765/api/logging/files/aniworld.log/download Expected status: 404 != 200` - -**Instructions:** -The `Download Log File` API test expects a `200 OK` from `/api/logging/files/{filename}/download`, but gets `404 Not Found`. The endpoint does not exist or the route is incorrect. Implement or fix the route so it accepts a filename parameter and returns the log file as a binary download. - ---- - ## Task 9: Cleanup Old Logs — Should accept cleanup request **Test Result:** FAIL — `Url: http://127.0.0.1:8765/api/logging/cleanup Expected status: 422 != 200` diff --git a/src/server/api/logging.py b/src/server/api/logging.py index f88d882..6496de7 100644 --- a/src/server/api/logging.py +++ b/src/server/api/logging.py @@ -8,7 +8,7 @@ from __future__ import annotations import logging import os from pathlib import Path -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional, Optional from fastapi import APIRouter, Depends, HTTPException, status from fastapi.responses import FileResponse @@ -181,20 +181,23 @@ def test_logging( @router.post("/cleanup") def cleanup_logs( - payload: Dict[str, Any], + payload: Optional[Dict[str, Any]] = None, auth: dict = Depends(require_auth), ) -> Dict[str, Any]: """Delete log files older than *days* days. Args: - payload: JSON body with ``days`` (int) field. + payload: Optional JSON body with ``days`` (int) field. Defaults to 30. Returns: Dict with ``success`` and ``message`` describing what was deleted. """ import time - days = payload.get("days", 30) + if payload is None: + days = 30 + else: + days = payload.get("days", 30) try: days = int(days) if days < 1: