feat:插件安装统计

This commit is contained in:
jxxghp
2024-03-25 18:02:57 +08:00
parent 0b70f74553
commit cf259af2d1
3 changed files with 38 additions and 0 deletions

View File

@ -67,6 +67,14 @@ def installed(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
return SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or [] return SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or []
@router.get("/statistic", summary="插件安装统计", response_model=dict)
def statistic(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
"""
插件安装统计
"""
return PluginHelper().get_statistic()
@router.get("/install/{plugin_id}", summary="安装插件", response_model=schemas.Response) @router.get("/install/{plugin_id}", summary="安装插件", response_model=schemas.Response)
def install(plugin_id: str, def install(plugin_id: str,
repo_url: str = "", repo_url: str = "",

View File

@ -20,6 +20,10 @@ class PluginHelper(metaclass=Singleton):
_base_url = "https://raw.githubusercontent.com/%s/%s/main/" _base_url = "https://raw.githubusercontent.com/%s/%s/main/"
_install_reg = "https://movie-pilot.org/plugin/install/%s"
_install_statistic = "https://movie-pilot.org/plugin/statistic"
@cached(cache=TTLCache(maxsize=100, ttl=1800)) @cached(cache=TTLCache(maxsize=100, ttl=1800))
def get_plugins(self, repo_url: str) -> Dict[str, dict]: def get_plugins(self, repo_url: str) -> Dict[str, dict]:
""" """
@ -61,10 +65,31 @@ class PluginHelper(metaclass=Singleton):
return None, None return None, None
return user, repo return user, repo
@cached(cache=TTLCache(maxsize=1, ttl=1800))
def get_statistic(self) -> Dict:
"""
获取插件安装统计
"""
res = RequestUtils(timeout=10).get_res(self._install_statistic)
if res and res.status_code == 200:
return res.json()
return {}
def install(self, pid: str, repo_url: str) -> Tuple[bool, str]: def install(self, pid: str, repo_url: str) -> Tuple[bool, str]:
""" """
安装插件 安装插件
""" """
def __install_reg() -> bool:
"""
安装插件统计
"""
if not pid:
return False
res = RequestUtils(timeout=5).get_res(self._install_reg % pid)
if res and res.status_code == 200:
return True
return False
if SystemUtils.is_frozen(): if SystemUtils.is_frozen():
return False, "可执行文件模式下,只能安装本地插件" return False, "可执行文件模式下,只能安装本地插件"
@ -154,4 +179,7 @@ class PluginHelper(metaclass=Singleton):
requirements_file = plugin_dir / "requirements.txt" requirements_file = plugin_dir / "requirements.txt"
if requirements_file.exists(): if requirements_file.exists():
SystemUtils.execute(f"pip install -r {requirements_file} > /dev/null 2>&1") SystemUtils.execute(f"pip install -r {requirements_file} > /dev/null 2>&1")
# 安装成功后统计
__install_reg()
return True, "" return True, ""

View File

@ -38,3 +38,5 @@ class Plugin(BaseModel):
is_local: Optional[bool] = False is_local: Optional[bool] = False
# 仓库地址 # 仓库地址
repo_url: Optional[str] = None repo_url: Optional[str] = None
# 安装次数
install_count: Optional[int] = 0