fix:优化单例模式和类引用

This commit is contained in:
jxxghp
2025-06-05 13:22:16 +08:00
parent 504827b7e5
commit a9300faaf8
25 changed files with 511 additions and 552 deletions
+6 -3
View File
@@ -61,7 +61,8 @@ class TemplateContextBuilder:
self._add_transfer_info(transferinfo)
self._add_torrent_info(torrentinfo)
self._add_file_info(file_extension)
if kwargs: self._context.update(kwargs)
if kwargs:
self._context.update(kwargs)
if include_raw_objects:
self._add_raw_objects(meta, mediainfo, torrentinfo, transferinfo, episodes_info)
@@ -73,7 +74,8 @@ class TemplateContextBuilder:
"""
增加媒体信息
"""
if not mediainfo: return
if not mediainfo:
return
season_fmt = f"S{mediainfo.season:02d}" if mediainfo.season is not None else None
base_info = {
# 标题
@@ -245,7 +247,8 @@ class TemplateContextBuilder:
"""
添加文件信息
"""
if not file_extension: return
if not file_extension:
return
file_info = {
# 文件后缀
"fileExt": file_extension,
+45
View File
@@ -1,5 +1,7 @@
from typing import Optional, List
from app.chain.mediaserver import MediaServerChain
from app.chain.tmdb import TmdbChain
from app.core.cache import cached
from app.core.config import settings
from app.utils.http import RequestUtils
@@ -11,6 +13,49 @@ class WallpaperHelper(metaclass=Singleton):
def __init__(self):
self.req = RequestUtils(timeout=5)
@staticmethod
def get_wallpaper() -> Optional[str]:
"""
获取登录页面壁纸
"""
if settings.WALLPAPER == "bing":
url = WallpaperHelper().get_bing_wallpaper()
elif settings.WALLPAPER == "mediaserver":
url = MediaServerChain().get_latest_wallpaper()
elif settings.WALLPAPER == "customize":
url = WallpaperHelper().get_customize_wallpaper()
else:
url = WallpaperHelper().get_tmdb_wallpaper()
return url
@staticmethod
def get_wallpapers(num: int = 10) -> List[str]:
"""
获取登录页面壁纸列表
"""
if settings.WALLPAPER == "bing":
return WallpaperHelper().get_bing_wallpapers(num)
elif settings.WALLPAPER == "mediaserver":
return MediaServerChain().get_latest_wallpapers(count=num)
elif settings.WALLPAPER == "customize":
return WallpaperHelper().get_customize_wallpapers(num)
else:
return WallpaperHelper().get_tmdb_wallpapers(num)
@cached(maxsize=1, ttl=3600)
def get_tmdb_wallpaper(self) -> Optional[str]:
"""
获取TMDB每日壁纸
"""
return TmdbChain().get_random_wallpager()
@cached(maxsize=1, ttl=3600)
def get_tmdb_wallpapers(self, num: int = 10) -> List[str]:
"""
获取7天的TMDB每日壁纸
"""
return TmdbChain().get_trending_wallpapers(num)
@cached(maxsize=1, ttl=3600)
def get_bing_wallpaper(self) -> Optional[str]:
"""