56 行
1.7 KiB
Python
56 行
1.7 KiB
Python
"""Storage route handlers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from backend.routes.common import handle_request
|
|
from backend.services.media_service import MediaService
|
|
from backend.dto.common import ApiError, ErrorCode
|
|
from core.identity import RequestContext
|
|
from core.security import require_authenticated, require_config_manager
|
|
|
|
|
|
def get_storage_status(
|
|
ctx: RequestContext,
|
|
service: MediaService | None = None,
|
|
) -> dict:
|
|
media_service = service or MediaService()
|
|
|
|
def action() -> dict[str, Any]:
|
|
require_authenticated(ctx)
|
|
return media_service.storage_status()
|
|
|
|
return handle_request(ctx, action)
|
|
|
|
|
|
def migrate_storage(
|
|
ctx: RequestContext,
|
|
payload: dict[str, Any],
|
|
service: MediaService | None = None,
|
|
) -> dict:
|
|
media_service = service or MediaService()
|
|
|
|
def action() -> dict[str, Any]:
|
|
require_config_manager(ctx)
|
|
source_uri = str(payload.get("source_uri") or "").strip()
|
|
target_uri = str(payload.get("target_uri") or "").strip()
|
|
if not source_uri:
|
|
raise ApiError(ErrorCode.VALIDATION_FAILED, "source_uri is required", {"field": "source_uri"})
|
|
if not target_uri:
|
|
raise ApiError(ErrorCode.VALIDATION_FAILED, "target_uri is required", {"field": "target_uri"})
|
|
return media_service.plan_storage_migration(
|
|
source_uri,
|
|
target_uri,
|
|
dry_run=_as_bool(payload.get("dry_run"), default=True),
|
|
)
|
|
|
|
return handle_request(ctx, action)
|
|
|
|
|
|
def _as_bool(value: Any, *, default: bool = False) -> bool:
|
|
if value is None:
|
|
return default
|
|
if isinstance(value, bool):
|
|
return value
|
|
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|