mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor: migrate workflow actions to runtime config snapshot
This commit is contained in:
@@ -140,6 +140,8 @@ class ChainRuntimeConfig:
|
||||
"""Chain 在一次宿主生命周期内使用的基础配置快照。"""
|
||||
|
||||
media_extensions: tuple[str, ...]
|
||||
api_port: int = 3000
|
||||
api_token: str | None = None
|
||||
video_extensions: tuple[str, ...] = ()
|
||||
subtitle_extensions: tuple[str, ...] = ()
|
||||
audio_extensions: tuple[str, ...] = ()
|
||||
@@ -198,6 +200,7 @@ class ChainRuntimeConfig:
|
||||
refresh_batch_size: int = 50
|
||||
torrent_cache_size: int = 1000
|
||||
site_url: Optional[str] = None
|
||||
workflow_url: Optional[str] = None
|
||||
season_zero_names: tuple[str, ...] = ()
|
||||
movie_rename_format: str = ""
|
||||
television_rename_format: str = ""
|
||||
|
||||
@@ -87,6 +87,8 @@ def build_chain_runtime_config(settings: Settings) -> ChainRuntimeConfig:
|
||||
+ settings.RMT_SUBEXT
|
||||
+ settings.RMT_AUDIOEXT
|
||||
),
|
||||
api_port=settings.PORT,
|
||||
api_token=settings.API_TOKEN,
|
||||
video_extensions=tuple(settings.RMT_MEDIAEXT),
|
||||
subtitle_extensions=tuple(settings.RMT_SUBEXT),
|
||||
audio_extensions=tuple(settings.RMT_AUDIOEXT),
|
||||
@@ -147,6 +149,7 @@ def build_chain_runtime_config(settings: Settings) -> ChainRuntimeConfig:
|
||||
refresh_batch_size=settings.CONF.refresh,
|
||||
torrent_cache_size=settings.CONF.torrents,
|
||||
site_url=settings.MP_DOMAIN("#/site"),
|
||||
workflow_url=settings.MP_DOMAIN("#/workflow"),
|
||||
season_zero_names=tuple(settings.RENAME_FORMAT_S0_NAMES),
|
||||
movie_rename_format=settings.RENAME_FORMAT(MediaType.MOVIE),
|
||||
television_rename_format=settings.RENAME_FORMAT(MediaType.TV),
|
||||
|
||||
@@ -4,9 +4,10 @@ from pydantic import Field
|
||||
|
||||
from app.workflow.actions import BaseAction
|
||||
from app.chain.recommend import RecommendChain
|
||||
from app.application.configuration import get_chain_runtime_config_snapshot
|
||||
from app.schemas.workflow import ActionParams
|
||||
from app.schemas.workflow import ActionContext
|
||||
from app.runtime.config import settings, global_vars
|
||||
from app.runtime.config import global_vars
|
||||
from app.runtime.events import eventmanager
|
||||
from app.runtime.log import logger
|
||||
from app.schemas.event import RecommendSourceEventData
|
||||
@@ -152,7 +153,11 @@ class FetchMediasAction(BaseAction):
|
||||
results = source['func']()
|
||||
else:
|
||||
# 调用内部API获取数据
|
||||
api_url = f"http://127.0.0.1:{settings.PORT}/api/v1/{source['api_path']}?token={settings.API_TOKEN}"
|
||||
runtime_config = get_chain_runtime_config_snapshot()
|
||||
api_url = (
|
||||
f"http://127.0.0.1:{runtime_config.api_port}"
|
||||
f"/api/v1/{source['api_path']}?token={runtime_config.api_token}"
|
||||
)
|
||||
res = RequestUtils(timeout=15).post_res(api_url)
|
||||
if res:
|
||||
results = res.json()
|
||||
@@ -163,7 +168,11 @@ class FetchMediasAction(BaseAction):
|
||||
logger.error(f"{name} 获取数据失败")
|
||||
else:
|
||||
# 调用内部API获取数据
|
||||
api_url = f"http://127.0.0.1:{settings.PORT}{params.api_path}?token={settings.API_TOKEN}"
|
||||
runtime_config = get_chain_runtime_config_snapshot()
|
||||
api_url = (
|
||||
f"http://127.0.0.1:{runtime_config.api_port}{params.api_path}"
|
||||
f"?token={runtime_config.api_token}"
|
||||
)
|
||||
res = RequestUtils(timeout=15).post_res(api_url)
|
||||
if res:
|
||||
results = res.json()
|
||||
|
||||
@@ -3,10 +3,10 @@ from typing import List, Optional, Union
|
||||
from pydantic import Field
|
||||
|
||||
from app.workflow.actions import BaseAction, ActionChain
|
||||
from app.application.configuration import get_chain_runtime_config_snapshot
|
||||
from app.schemas.workflow import ActionParams
|
||||
from app.schemas.workflow import ActionContext
|
||||
from app.schemas.message import Message
|
||||
from app.runtime.config import settings
|
||||
|
||||
|
||||
class SendMessageParams(ActionParams):
|
||||
@@ -58,7 +58,7 @@ class SendMessageAction(BaseAction):
|
||||
userid=params.userid,
|
||||
title="【工作流执行结果】",
|
||||
text=msg_text,
|
||||
link=settings.MP_DOMAIN("#/workflow")
|
||||
link=get_chain_runtime_config_snapshot().workflow_url
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user