mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
refactor: add configuration dependency ratchet
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from typing import List, Optional, Tuple, Union
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, List, Optional, Tuple, Union
|
||||
|
||||
from app.schemas.context import MediaPerson as _SchemaMediaPerson
|
||||
from app.runtime.config import settings
|
||||
@@ -19,6 +20,13 @@ from app.adapters.network.http import RequestUtils
|
||||
from app.domain.media import is_media_source_enabled
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class BangumiConfigSnapshot:
|
||||
"""Bangumi 模块一次配置 generation 使用的稳定网络快照。"""
|
||||
|
||||
proxy: Any
|
||||
|
||||
|
||||
class BangumiModule(_ModuleBase):
|
||||
"""
|
||||
Bangumi媒体信息匹配
|
||||
@@ -27,11 +35,13 @@ class BangumiModule(_ModuleBase):
|
||||
|
||||
bangumiapi: BangumiApi = None
|
||||
scraper: MediaScraperHelper = None
|
||||
_config: BangumiConfigSnapshot = BangumiConfigSnapshot(proxy=None)
|
||||
|
||||
def init_module(self) -> None:
|
||||
"""
|
||||
初始化Bangumi客户端
|
||||
"""
|
||||
self._config = BangumiConfigSnapshot(proxy=settings.PROXY)
|
||||
self.bangumiapi = BangumiApi()
|
||||
self.scraper = MediaScraperHelper()
|
||||
|
||||
@@ -46,7 +56,7 @@ class BangumiModule(_ModuleBase):
|
||||
"""
|
||||
测试模块连接性
|
||||
"""
|
||||
ret = RequestUtils(proxies=settings.PROXY).get_res("https://api.bgm.tv/")
|
||||
ret = RequestUtils(proxies=self._config.proxy).get_res("https://api.bgm.tv/")
|
||||
if ret and ret.status_code == 200:
|
||||
return True, ""
|
||||
elif ret:
|
||||
|
||||
Reference in New Issue
Block a user