mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor: expand api and chain config snapshots
This commit is contained in:
@@ -44,7 +44,7 @@ from app.agent.runtime_loader import (
|
||||
)
|
||||
from app.chain.message import MessageChain
|
||||
from app.command import Command
|
||||
from app.runtime.config import global_vars, settings
|
||||
from app.runtime.config import global_vars
|
||||
from app.runtime.events import Event, EventManager
|
||||
from app.api.principal import ApiPrincipal
|
||||
from app.api.dependencies.agent import get_agent_chat_service
|
||||
@@ -55,6 +55,7 @@ from app.application.messaging.chat import (
|
||||
get_configured_agent_chat_service,
|
||||
)
|
||||
from app.application.security.user import get_configured_user_id_lookup
|
||||
from app.application.configuration import get_api_runtime_config_snapshot
|
||||
from app.application.messaging.agent import attach_web_agent_edit_queue, detach_web_agent_edit_queue
|
||||
from app.application.messaging.agent import agent_interaction_manager
|
||||
from app.application.messaging.agent import (
|
||||
@@ -744,7 +745,7 @@ def _get_web_agent_upload_dir(user: ApiPrincipal, session_id: Optional[str]) ->
|
||||
"""
|
||||
server_session_id = _build_web_agent_session_id(user, session_id)
|
||||
safe_session_id = server_session_id.replace(":", "_")
|
||||
upload_dir = settings.TEMP_PATH / "agent_uploads" / safe_session_id
|
||||
upload_dir = get_api_runtime_config_snapshot().temp_path / "agent_uploads" / safe_session_id
|
||||
upload_dir.mkdir(parents=True, exist_ok=True)
|
||||
return upload_dir
|
||||
|
||||
@@ -972,7 +973,7 @@ def _prepare_web_agent_audio_attachment_path(voice_path: str) -> Path:
|
||||
logger.warning("WebAgent 语音转 WAV 跳过:ffmpeg 不可用,path=%s", source_path)
|
||||
return source_path
|
||||
|
||||
voice_dir = settings.TEMP_PATH / "voice"
|
||||
voice_dir = get_api_runtime_config_snapshot().temp_path / "voice"
|
||||
voice_dir.mkdir(parents=True, exist_ok=True)
|
||||
output_path = voice_dir / f"{source_path.stem}_web_{uuid.uuid4().hex[:8]}.wav"
|
||||
cmd = [
|
||||
@@ -2113,7 +2114,7 @@ async def web_agent_stream(
|
||||
|
||||
return build_sse_response(traditional_event_generator())
|
||||
|
||||
if not settings.AI_AGENT_ENABLE:
|
||||
if not get_api_runtime_config_snapshot().ai_agent_enable:
|
||||
return _build_web_agent_error_response(
|
||||
"智能助手未启用,请先在系统设置中开启。",
|
||||
locale=locale,
|
||||
|
||||
@@ -23,7 +23,7 @@ from app.api.openai_utils import (
|
||||
)
|
||||
from app.api.presentation.sse import build_sse_response, encode_named_event
|
||||
from app.agent.runtime_loader import get_running_agent_manager
|
||||
from app.runtime.config import settings
|
||||
from app.application.configuration import get_api_runtime_config_snapshot
|
||||
from app.adapters.web.security.access import anthropic_api_key_header
|
||||
|
||||
ANTHROPIC_ERROR_RESPONSES = {
|
||||
@@ -56,7 +56,7 @@ def _check_auth(api_key: Optional[str]) -> Optional[JSONResponse]:
|
||||
"""
|
||||
Anthropic 兼容接口以 API_TOKEN 认证受信客户端,认证通过即按管理员级 Agent 集成处理。
|
||||
"""
|
||||
if not api_key or api_key != settings.API_TOKEN:
|
||||
if not api_key or api_key != get_api_runtime_config_snapshot().api_token:
|
||||
return _anthropic_error_response(
|
||||
"invalid x-api-key",
|
||||
401,
|
||||
@@ -212,7 +212,7 @@ async def messages(
|
||||
if auth_error:
|
||||
return auth_error
|
||||
|
||||
if not settings.AI_AGENT_ENABLE:
|
||||
if not get_api_runtime_config_snapshot().ai_agent_enable:
|
||||
return _anthropic_error_response(
|
||||
"MoviePilot AI agent is disabled.",
|
||||
503,
|
||||
|
||||
@@ -31,7 +31,7 @@ from app.agent.runtime_loader import (
|
||||
get_running_agent_manager,
|
||||
)
|
||||
from app.agent.contracts import ReplyMode
|
||||
from app.runtime.config import settings
|
||||
from app.application.configuration import get_api_runtime_config_snapshot
|
||||
from app.adapters.web.security.access import openai_bearer_scheme
|
||||
from app.schemas.types import NotificationChannel
|
||||
|
||||
@@ -453,7 +453,7 @@ def _check_auth(
|
||||
error_type="authentication_error",
|
||||
code="invalid_api_key",
|
||||
)
|
||||
if credentials.credentials != settings.API_TOKEN:
|
||||
if credentials.credentials != get_api_runtime_config_snapshot().api_token:
|
||||
return _error_response(
|
||||
"Invalid bearer token.",
|
||||
401,
|
||||
@@ -506,7 +506,7 @@ async def chat_completions(
|
||||
if auth_error:
|
||||
return auth_error
|
||||
|
||||
if not settings.AI_AGENT_ENABLE:
|
||||
if not get_api_runtime_config_snapshot().ai_agent_enable:
|
||||
return _error_response(
|
||||
"MoviePilot AI agent is disabled.",
|
||||
503,
|
||||
@@ -607,7 +607,7 @@ async def responses(
|
||||
if auth_error:
|
||||
return auth_error
|
||||
|
||||
if not settings.AI_AGENT_ENABLE:
|
||||
if not get_api_runtime_config_snapshot().ai_agent_enable:
|
||||
return _error_response(
|
||||
"MoviePilot AI agent is disabled.",
|
||||
503,
|
||||
|
||||
@@ -11,7 +11,7 @@ from app.schemas.tmdb import TmdbEpisode as _SchemaTmdbEpisode
|
||||
from app.schemas.workflow import MediaInfo as _SchemaMediaInfo
|
||||
from app.api.response import ResponseAPIRouter
|
||||
from app.chain.tmdb import TmdbChain
|
||||
from app.runtime.config import settings
|
||||
from app.application.configuration import get_api_runtime_config_snapshot
|
||||
from app.adapters.web.security.access import verify_token
|
||||
from app.application.configuration import get_configured_system_config
|
||||
from app.api.dependencies.auth import get_current_active_superuser_async
|
||||
@@ -40,7 +40,7 @@ async def tmdb_recognition_cache(
|
||||
"shared_recognized": get_configured_system_config().get(
|
||||
SystemConfigKey.MediaRecognizeShareCount
|
||||
) or 0,
|
||||
"shared_recognize_enabled": settings.MEDIA_RECOGNIZE_SHARE,
|
||||
"shared_recognize_enabled": get_api_runtime_config_snapshot().media_recognize_share,
|
||||
"data": cache_items,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ from app.schemas.response import Response as _SchemaResponse
|
||||
from app.api.response import ResponseAPIRouter
|
||||
from app.chain.media import MediaChain
|
||||
from app.chain.torrents import TorrentsChain
|
||||
from app.runtime.config import settings
|
||||
from app.application.configuration import get_api_runtime_config_snapshot
|
||||
from app.domain.context import MediaInfo, MusicInfo
|
||||
from app.domain.meta.metamusic import MetaMusic
|
||||
from app.domain.metainfo import MetaInfo
|
||||
@@ -41,7 +41,7 @@ async def torrents_cache(_: object = Depends(get_current_active_superuser_async)
|
||||
torrents_chain = TorrentsChain()
|
||||
|
||||
# 获取spider和rss两种缓存
|
||||
if settings.SUBSCRIBE_MODE == "rss":
|
||||
if get_api_runtime_config_snapshot().subscribe_mode == "rss":
|
||||
cache_info = await torrents_chain.async_get_torrents("rss")
|
||||
else:
|
||||
cache_info = await torrents_chain.async_get_torrents("spider")
|
||||
|
||||
Reference in New Issue
Block a user