fix SiteStatistic

This commit is contained in:
jxxghp
2024-03-26 08:13:00 +08:00
parent c63dfddb40
commit 68563af666
4 changed files with 25 additions and 10 deletions

View File

@@ -18,7 +18,7 @@
"SiteStatistic": {
"name": "站点数据统计",
"description": "自动统计和展示站点数据。",
"version": "2.2",
"version": "2.4",
"icon": "statistic.png",
"author": "lightolly",
"level": 2

View File

@@ -43,7 +43,7 @@ class SiteStatistic(_PluginBase):
# 插件图标
plugin_icon = "statistic.png"
# 插件版本
plugin_version = "2.3"
plugin_version = "2.4"
# 插件作者
plugin_author = "lightolly"
# 作者主页

View File

@@ -39,6 +39,8 @@ class ISiteUserInfo(metaclass=ABCMeta):
schema = SiteSchema.NexusPhp
# 站点解析时判断顺序,值越小越先解析
order = SITE_BASE_ORDER
# 请求模式 cookie/apikey
request_mode = "cookie"
def __init__(self, site_name: str,
url: str,
@@ -115,8 +117,8 @@ class ISiteUserInfo(metaclass=ABCMeta):
split_url = urlsplit(url)
self.site_name = site_name
self.site_url = url
self._base_url = f"{split_url.scheme}://{split_url.netloc}"
self.site_domain = split_url.netloc
self._base_url = f"{split_url.scheme}://{split_url.netloc}"
self._site_cookie = site_cookie
self._index_html = index_html
self._session = session if session else None
@@ -291,25 +293,36 @@ class ISiteUserInfo(metaclass=ABCMeta):
if self._addition_headers:
req_headers.update(self._addition_headers)
if self.request_mode == "apikey":
# 使用apikey请求通过请求头传递
cookie = None
session = None
else:
# 使用cookie请求
cookie = self._site_cookie
session = self._session
if params:
if req_headers.get("Content-Type") == "application/json":
res = RequestUtils(timeout=60,
res = RequestUtils(cookies=cookie,
session=session,
timeout=60,
proxies=proxies,
headers=req_headers).post_res(url=url, json=params)
else:
res = RequestUtils(cookies=self._site_cookie,
session=self._session,
res = RequestUtils(cookies=cookie,
session=session,
timeout=60,
proxies=proxies,
headers=req_headers).post_res(url=url, data=params)
else:
res = RequestUtils(cookies=self._site_cookie,
session=self._session,
res = RequestUtils(cookies=cookie,
session=session,
timeout=60,
proxies=proxies,
headers=req_headers).get_res(url=url)
if res is not None and res.status_code in (200, 500, 403):
if "application/json" in ((req_headers and req_headers.get("Accept")) or ""):
if req_headers and "application/json" in req_headers.get("Accept"):
return json.dumps(res.json())
else:
# 如果cloudflare 有防护,尝试使用浏览器仿真

View File

@@ -7,11 +7,13 @@ from lxml import etree
from app.log import logger
from app.db.systemconfig_oper import SystemConfigOper
from app.plugins.sitestatistic.siteuserinfo import ISiteUserInfo, SITE_BASE_ORDER, SiteSchema
from app.utils.string import StringUtils
class MTorrentSiteUserInfo(ISiteUserInfo):
schema = SiteSchema.MTorrent
order = SITE_BASE_ORDER + 60
request_mode = "apikey"
# 用户级别字典
MTeam_sysRoleList = {
@@ -63,7 +65,7 @@ class MTorrentSiteUserInfo(ISiteUserInfo):
"pageSize": 100
}
self._torrent_seeding_page = "api/member/getUserTorrentList"
domain = self.site_domain.split(".")[-2]
domain = StringUtils.get_url_host(self.site_url)
self._torrent_seeding_headers = {
"Content-Type": "application/json",
"Accept": "application/json, text/plain, */*",