soem fixes
This commit is contained in:
@@ -26,11 +26,12 @@ optional_bearer = HTTPBearer(auto_error=False)
|
||||
|
||||
|
||||
@router.post("/setup", status_code=http_status.HTTP_201_CREATED)
|
||||
def setup_auth(req: SetupRequest):
|
||||
async def setup_auth(req: SetupRequest):
|
||||
"""Initial setup endpoint to configure the master password.
|
||||
|
||||
This endpoint also initializes the configuration with default values
|
||||
and saves the anime directory and master password hash.
|
||||
If anime_directory is provided, runs migration for existing data files.
|
||||
"""
|
||||
if auth_service.is_configured():
|
||||
raise HTTPException(
|
||||
@@ -57,17 +58,37 @@ def setup_auth(req: SetupRequest):
|
||||
config.other['master_password_hash'] = password_hash
|
||||
|
||||
# Store anime directory in config's other field if provided
|
||||
anime_directory = None
|
||||
if hasattr(req, 'anime_directory') and req.anime_directory:
|
||||
config.other['anime_directory'] = req.anime_directory
|
||||
anime_directory = req.anime_directory.strip()
|
||||
if anime_directory:
|
||||
config.other['anime_directory'] = anime_directory
|
||||
|
||||
# Save the config with the password hash and anime directory
|
||||
config_service.save_config(config, create_backup=False)
|
||||
|
||||
# Run migration if anime directory was provided
|
||||
response = {"status": "ok"}
|
||||
if anime_directory:
|
||||
from src.server.services.startup_migration import (
|
||||
run_migration_for_directory,
|
||||
)
|
||||
migration_result = await run_migration_for_directory(
|
||||
anime_directory
|
||||
)
|
||||
if migration_result:
|
||||
response["migration"] = {
|
||||
"total_found": migration_result.total_found,
|
||||
"migrated": migration_result.migrated,
|
||||
"skipped": migration_result.skipped,
|
||||
"failed": migration_result.failed,
|
||||
}
|
||||
|
||||
return response
|
||||
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@router.post("/login", response_model=LoginResponse)
|
||||
def login(req: LoginRequest):
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
@@ -210,18 +210,18 @@ def update_advanced_config(
|
||||
) from e
|
||||
|
||||
|
||||
@router.post("/directory", response_model=Dict[str, str])
|
||||
def update_directory(
|
||||
@router.post("/directory", response_model=Dict[str, Any])
|
||||
async def update_directory(
|
||||
directory_config: Dict[str, str], auth: dict = Depends(require_auth)
|
||||
) -> Dict[str, str]:
|
||||
"""Update anime directory configuration.
|
||||
) -> Dict[str, Any]:
|
||||
"""Update anime directory configuration and run migration.
|
||||
|
||||
Args:
|
||||
directory_config: Dictionary with 'directory' key
|
||||
auth: Authentication token (required)
|
||||
|
||||
Returns:
|
||||
Success message
|
||||
Success message with optional migration results
|
||||
"""
|
||||
try:
|
||||
directory = directory_config.get("directory")
|
||||
@@ -235,13 +235,27 @@ def update_directory(
|
||||
app_config = config_service.load_config()
|
||||
|
||||
# Store directory in other section
|
||||
if "anime_directory" not in app_config.other:
|
||||
app_config.other["anime_directory"] = directory
|
||||
else:
|
||||
app_config.other["anime_directory"] = directory
|
||||
app_config.other["anime_directory"] = directory
|
||||
|
||||
config_service.save_config(app_config)
|
||||
return {"message": "Anime directory updated successfully"}
|
||||
|
||||
# Run migration for the new directory
|
||||
from src.server.services.startup_migration import run_migration_for_directory
|
||||
migration_result = await run_migration_for_directory(directory)
|
||||
|
||||
response: Dict[str, Any] = {
|
||||
"message": "Anime directory updated successfully"
|
||||
}
|
||||
|
||||
if migration_result:
|
||||
response["migration"] = {
|
||||
"total_found": migration_result.total_found,
|
||||
"migrated": migration_result.migrated,
|
||||
"skipped": migration_result.skipped,
|
||||
"failed": migration_result.failed,
|
||||
}
|
||||
|
||||
return response
|
||||
except ConfigServiceError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
Reference in New Issue
Block a user