mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
feat:增加订阅管理员 #4123
This commit is contained in:
@@ -28,6 +28,7 @@ from app.helper.message import MessageHelper, MessageQueueManager
|
|||||||
from app.helper.progress import ProgressHelper
|
from app.helper.progress import ProgressHelper
|
||||||
from app.helper.rule import RuleHelper
|
from app.helper.rule import RuleHelper
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
|
from app.helper.subscribe import SubscribeHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.monitor import Monitor
|
from app.monitor import Monitor
|
||||||
from app.scheduler import Scheduler
|
from app.scheduler import Scheduler
|
||||||
@@ -179,9 +180,10 @@ def get_global_setting():
|
|||||||
exclude={"SECRET_KEY", "RESOURCE_SECRET_KEY", "API_TOKEN", "TMDB_API_KEY", "TVDB_API_KEY", "FANART_API_KEY",
|
exclude={"SECRET_KEY", "RESOURCE_SECRET_KEY", "API_TOKEN", "TMDB_API_KEY", "TVDB_API_KEY", "FANART_API_KEY",
|
||||||
"COOKIECLOUD_KEY", "COOKIECLOUD_PASSWORD", "GITHUB_TOKEN", "REPO_GITHUB_TOKEN"}
|
"COOKIECLOUD_KEY", "COOKIECLOUD_PASSWORD", "GITHUB_TOKEN", "REPO_GITHUB_TOKEN"}
|
||||||
)
|
)
|
||||||
# 追加用户唯一ID
|
# 追加用户唯一ID和订阅分享管理权限
|
||||||
info.update({
|
info.update({
|
||||||
"USER_UNIQUE_ID": SystemUtils.generate_user_unique_id()
|
"USER_UNIQUE_ID": SubscribeHelper().get_user_uuid(),
|
||||||
|
"SUBSCRIBE_SHARE_MANAGE": SubscribeHelper().is_admin_user(),
|
||||||
})
|
})
|
||||||
return schemas.Response(success=True,
|
return schemas.Response(success=True,
|
||||||
data=info)
|
data=info)
|
||||||
|
|||||||
+50
-1
@@ -5,6 +5,7 @@ from app.core.cache import cached, cache_backend
|
|||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.db.subscribe_oper import SubscribeOper
|
from app.db.subscribe_oper import SubscribeOper
|
||||||
from app.db.systemconfig_oper import SystemConfigOper
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
|
from app.log import logger
|
||||||
from app.schemas.types import SystemConfigKey
|
from app.schemas.types import SystemConfigKey
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
@@ -32,13 +33,29 @@ class SubscribeHelper(metaclass=Singleton):
|
|||||||
|
|
||||||
_shares_cache_region = "subscribe_share"
|
_shares_cache_region = "subscribe_share"
|
||||||
|
|
||||||
|
_github_user = None
|
||||||
|
|
||||||
|
_share_user_id = None
|
||||||
|
|
||||||
|
_admin_users = [
|
||||||
|
"jxxghp",
|
||||||
|
"thsrite",
|
||||||
|
"InfinityPacer",
|
||||||
|
"DDSRem",
|
||||||
|
"Aqr-K",
|
||||||
|
"Putarku",
|
||||||
|
"4Nest",
|
||||||
|
"xyswordzoro"
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.systemconfig = SystemConfigOper()
|
self.systemconfig = SystemConfigOper()
|
||||||
self.share_user_id = SystemUtils.generate_user_unique_id()
|
|
||||||
if settings.SUBSCRIBE_STATISTIC_SHARE:
|
if settings.SUBSCRIBE_STATISTIC_SHARE:
|
||||||
if not self.systemconfig.get(SystemConfigKey.SubscribeReport):
|
if not self.systemconfig.get(SystemConfigKey.SubscribeReport):
|
||||||
if self.sub_report():
|
if self.sub_report():
|
||||||
self.systemconfig.set(SystemConfigKey.SubscribeReport, "1")
|
self.systemconfig.set(SystemConfigKey.SubscribeReport, "1")
|
||||||
|
self.get_user_uuid()
|
||||||
|
self.get_github_user()
|
||||||
|
|
||||||
@cached(maxsize=20, ttl=1800)
|
@cached(maxsize=20, ttl=1800)
|
||||||
def get_statistic(self, stype: str, page: Optional[int] = 1, count: Optional[int] = 30) -> List[dict]:
|
def get_statistic(self, stype: str, page: Optional[int] = 1, count: Optional[int] = 30) -> List[dict]:
|
||||||
@@ -196,3 +213,35 @@ class SubscribeHelper(metaclass=Singleton):
|
|||||||
if res and res.status_code == 200:
|
if res and res.status_code == 200:
|
||||||
return res.json()
|
return res.json()
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def get_user_uuid(self) -> str:
|
||||||
|
"""
|
||||||
|
获取用户uuid
|
||||||
|
"""
|
||||||
|
if not self._share_user_id:
|
||||||
|
self._share_user_id = SystemUtils.generate_user_unique_id()
|
||||||
|
logger.info(f"当前用户UUID: {self._share_user_id}")
|
||||||
|
return self._share_user_id
|
||||||
|
|
||||||
|
def get_github_user(self) -> str:
|
||||||
|
"""
|
||||||
|
获取github用户
|
||||||
|
"""
|
||||||
|
if self._github_user is None and settings.GITHUB_HEADERS:
|
||||||
|
res = RequestUtils(headers=settings.GITHUB_HEADERS,
|
||||||
|
proxies=settings.PROXY,
|
||||||
|
timeout=15).get_res(f"https://api.github.com/user")
|
||||||
|
if res:
|
||||||
|
self._github_user = res.json().get("login")
|
||||||
|
logger.info(f"当前Github用户: {self._github_user}")
|
||||||
|
return self._github_user
|
||||||
|
|
||||||
|
def is_admin_user(self) -> bool:
|
||||||
|
"""
|
||||||
|
判断是否是管理员
|
||||||
|
"""
|
||||||
|
if not self._github_user:
|
||||||
|
return False
|
||||||
|
if self._github_user in self._admin_users:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user