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):
|
||||
|
||||
Reference in New Issue
Block a user