Skip to content

Commit 508c222

Browse files
author
Taois
committed
feat: 更新了一些可能没卵用的优化
1 parent 78a1fdb commit 508c222

File tree

12 files changed

+110
-52
lines changed

12 files changed

+110
-52
lines changed

.env.development

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ QQ_SMTP_AUTH_CODE =
3636
CAT_DEBUG=1
3737
PYTHON_PATH=
3838
VIRTUAL_ENV=
39-
daemonMode=0
39+
daemonMode=0
40+
DS_REQ_LIB=0

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# drpyS(drpy-node)
22

33
nodejs作为服务端的drpy实现。全面升级异步写法
4-
~~积极开发中,每日一更~~,当前进度 `85%`
4+
~~积极开发中,每日一更~~,当前进度 `86%`
55
~~找工作中,随缘更新~~
66
上班当牛马,下班要带娃,阶段性佛系趁娃睡觉熬夜更新
77

88
* [接口文档](docs/apidoc.md) | [接口列表如定时任务](docs/apiList.md) | [小猫影视-待对接T4](https://github.com/waifu-project/movie/pull/135)
99
* [本地配置接口-动态本地](/config?pwd=$pwd)
1010
* [本地配置接口-动态外网/局域网](/config/1?pwd=$pwd)
1111
* [其他配置接口-订阅过滤](/docs/sub.md)
12-
* [python环境](/docs/pyenv.md)
12+
* [python环境](/docs/pyenv.md) | [DS项目环境变量说明](/docs/envdoc.md)
1313
* [猫源调试教程](/docs/catDebug.md)
1414
* [代码加解密工具](/admin/encoder)
1515
* [V我50支付凭证生成器](/authcoder?len=10&number=1)
@@ -25,6 +25,10 @@ nodejs作为服务端的drpy实现。全面升级异步写法
2525

2626
## 更新记录
2727

28+
### 20250825
29+
30+
更新至V1.2.20
31+
2832
### 20250824
2933

3034
更新至V1.2.19
@@ -35,16 +39,6 @@ nodejs作为服务端的drpy实现。全面升级异步写法
3539

3640
### 20250822
3741

38-
更新至V1.2.17
39-
40-
### 20250821
41-
42-
更新至V1.2.16
43-
44-
### 20250819
45-
46-
更新至V1.2.15
47-
4842
[点此查看完整更新记录](docs/updateRecord.md)
4943

5044
**注意事项**

docs/envdoc.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 环境变量 .env参数说明
2+
3+
| 参数键 | 参数说明 | 参数示例 |
4+
|------------------------|--------------------------------|-------------------------------------------------------------------|
5+
| LOG_WITH_FILE | 日志输出到本地文件 | 0:输出到控制台 1:输出到本地文件 |
6+
| ENABLE_TASKER | 启用定时任务 | 0:启用 1:禁用 |
7+
| TASKER_INTERVAL | 定时任务间隔毫秒 | 已弃用 |
8+
| FORCE_HEADER | 强制生成文件头,每次访问都重新生成 | 0:关闭 1:开启 (仅在第一次批量生成文件头启用此选项) |
9+
| DR2_API_TYPE | drpy2本地t3接口文件 | 0:使用本项目的drpy-core-lite 1:使用壳子内置assets |
10+
| LOG_LEVEL | 日志级别 | info/error |
11+
| COOKIE_AUTH_CODE | 设置中心入库授权码 | drpys |
12+
| API_AUTH_NAME | basic认证账号,访问ds首页需要登录,猫爪使用必必须配置 | admin |
13+
| API_AUTH_CODE | basic认证密码,访问ds首页需要登录,猫爪使用必必须配置 | drpys |
14+
| API_PWD | T4接口密码和T3文件访问密码,如果不配置就是公开文件和接口 | dzyyds |
15+
| EPG_URL | epg直播信息链接 | https://iptv.xxxx.cn/epgphp/index.php?ch={name}&date={date} |
16+
| LOGO_URL | 直播频道logo链接 | https://live.xxxx.top/logo/{name}.png |
17+
| MAX_TASK | 批量任务最大并发数,小鸡请设置低于2 | 8 |
18+
| dingding_webhook | 钉钉webhook推送定时任务消息链接 | https://oapi.dingtalk.com/robot/send?access_token=${access_token} |
19+
| wechat_webhook | 企业微信webhook推送定时任务消息链接 | |
20+
| tx_news_guonei_api_key | 国内新闻每日定时任务推送KEY | 去这里申请 https://www.tianapi.com/apiview/4 |
21+
| cookie_52pojie | 吾爱破解定时签到cookie | 暂时无法实现定时签到 |
22+
| QQ_EMAIL | qq邮箱定时任务推送账号 | |
23+
| QQ_SMTP_AUTH_CODE | qq邮箱定时任务推送授权码 | |
24+
| CAT_DEBUG | 调试猫源 | 0/1: 开启esm模式 2: base64模式,存在相对依赖无法使用问题 |
25+
| PYTHON_PATH | 本地python真实环境路径 | D:\Program Files\Python312 |
26+
| VIRTUAL_ENV | 本地python虚拟环境路径 | 同上,差别在于虚拟环境会自动拼scripts路径下的python.exe,跟真实环境二选一 |
27+
| daemonMode | 守护进程版本 | 0: 旗舰版 1:轻量版 |
28+
| DS_REQ_LIB | ds/cat 默认req实现 | 0:fetch 1:axios (已知模式1为前面版本默认功能,但是后面发现某些场景无法获取源码,新写了模式0,不保证完全兼容) |
29+

docs/updateRecord.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# drpyS更新记录
22

3+
### 20250825
4+
5+
更新至V1.2.20
6+
7+
1. 守护进程把`json` 换成 `ujson` 提高数据交互性能
8+
2. 实验性修改 ds源的 `req` 实现,把`axios`底层请求库换成 `fetch`,解决一些请求网页源码出现的问题(七猫DS已复活)
9+
3. 日志优化,减少lazy执行结果打印的文本长度
10+
4. 新增环境变量参数说明文档 [DS项目环境变量说明](/docs/envdoc.md)
11+
5. 守护进程启动时的空链接error降级为warning
12+
313
### 20250824
414

515
更新至V1.2.19

libs/drpyS.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ async function invokeWithInjectVars(rule, method, injectVars, args) {
633633
}
634634
});
635635
let result = {};
636+
let ret_str = '';
636637
let error = null;
637638
try {
638639
result = await method.apply(thisProxy, args);
@@ -667,7 +668,8 @@ async function invokeWithInjectVars(rule, method, injectVars, args) {
667668
break;
668669
case 'lazy':
669670
result = await playParseAfter(rule, result, args[1], args[0]);
670-
console.log(`免嗅 ${injectVars.input} 执行完毕,结果为:`, JSON.stringify(result));
671+
ret_str = JSON.stringify(result);
672+
console.log(`免嗅 ${injectVars.input} 执行完毕,结果为:`, ret_str.length < 100 ? ret_str : ret_str.slice(0, 100) + '...');
671673
break;
672674
case 'proxy_rule':
673675
break;

libs_drpy/drpyInject.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,44 @@ globalThis.qs = qs;
2828
const AgentOption = {keepAlive: true, maxSockets: 64, timeout: 30000}; // 最大连接数64,30秒定期清理空闲连接
2929
const httpAgent = new http.Agent(AgentOption);
3030
let httpsAgent = new https.Agent({rejectUnauthorized: false, ...AgentOption});
31-
31+
const dsReqLib = Number(process.env.DS_REQ_LIB) || 0;
32+
console.log('DS/CAT源底层req实现 DS_REQ_LIB (0 fetch 1 axios):', dsReqLib);
33+
let _axios;
3234
// 配置 axios 使用代理
33-
// const _axios = axios.create({
34-
// httpAgent, // 用于 HTTP 请求的代理
35-
// httpsAgent, // 用于 HTTPS 请求的代理
36-
// });
37-
38-
const _axios = createInstance({
39-
headers: {'User-Agent': 'Mozilla/5.0'},
40-
timeout: 10000,
41-
responseType: 'text',
42-
httpsAgent: new https.Agent({rejectUnauthorized: false}), // 忽略 HTTPS 证书错误
43-
});
35+
36+
if (dsReqLib === 0) {
37+
_axios = createInstance({
38+
headers: {'User-Agent': 'Mozilla/5.0'},
39+
timeout: 10000,
40+
responseType: 'text',
41+
httpsAgent: new https.Agent({rejectUnauthorized: false}), // 忽略 HTTPS 证书错误
42+
});
4443

4544
// 请求拦截器
46-
// _axios.interceptors.request.use((config) => {
47-
_axios.useRequestInterceptor((config) => {
45+
_axios.useRequestInterceptor(RequestInterceptor, (error) => {
46+
return Promise.reject(error);
47+
});
48+
} else {
49+
_axios = axios.create({
50+
httpAgent, // 用于 HTTP 请求的代理
51+
httpsAgent, // 用于 HTTPS 请求的代理
52+
});
53+
// 请求拦截器
54+
_axios.interceptors.request.use(RequestInterceptor, (error) => {
55+
return Promise.reject(error);
56+
});
57+
}
58+
59+
function RequestInterceptor(config) {
4860
// 生成 curl 命令
61+
const show_curl = Number(ENV.get('show_curl', '0')) === 1;
62+
// console.log(`拦截器 show_curl: ${show_curl}`);
4963
const curlCommand = generateCurlCommand(config);
50-
if (ENV.get('show_curl', '0') === '1') {
64+
if (show_curl) {
5165
console.log(`Generated cURL command:\n${curlCommand}`);
5266
}
5367
return config;
54-
}, (error) => {
55-
return Promise.reject(error);
56-
});
68+
}
5769

5870
/**
5971
* 生成 curl 命令

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drpy-node",
3-
"version": "1.2.19",
3+
"version": "1.2.20",
44
"main": "index.js",
55
"type": "module",
66
"scripts": {

public/index.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
</head>
99
<body>
1010
<h1 id="drpysdrpy-node">drpyS(drpy-node)</h1>
11-
<p>nodejs作为服务端的drpy实现。全面升级异步写法<br><del>积极开发中,每日一更</del>,当前进度 <code>85%</code><br><del>找工作中,随缘更新</del><br>上班当牛马,下班要带娃,阶段性佛系趁娃睡觉熬夜更新</p>
11+
<p>nodejs作为服务端的drpy实现。全面升级异步写法<br><del>积极开发中,每日一更</del>,当前进度 <code>86%</code><br><del>找工作中,随缘更新</del><br>上班当牛马,下班要带娃,阶段性佛系趁娃睡觉熬夜更新</p>
1212
<ul>
1313
<li><a href="docs/apidoc.md">接口文档</a> | <a href="docs/apiList.md">接口列表如定时任务</a> | <a href="https://github.com/waifu-project/movie/pull/135">小猫影视-待对接T4</a></li>
1414
<li><a href="/config?pwd=dzyyds">本地配置接口-动态本地</a></li>
1515
<li><a href="/config/1?pwd=dzyyds">本地配置接口-动态外网/局域网</a></li>
1616
<li><a href="/docs/sub.md">其他配置接口-订阅过滤</a></li>
17-
<li><a href="/docs/pyenv.md">python环境</a></li>
17+
<li><a href="/docs/pyenv.md">python环境</a> | <a href="/docs/envdoc.md">DS项目环境变量说明</a></li>
1818
<li><a href="/docs/catDebug.md">猫源调试教程</a></li>
1919
<li><a href="/admin/encoder">代码加解密工具</a></li>
2020
<li><a href="/authcoder?len=10&amp;number=1">V我50支付凭证生成器</a></li>
@@ -29,16 +29,13 @@ <h1 id="drpysdrpy-node">drpyS(drpy-node)</h1>
2929
<li><a href="/cat/index.html">在线猫ds源主页</a></li>
3030
</ul>
3131
<h2 id="更新记录">更新记录</h2>
32+
<h3 id="20250825">20250825</h3>
33+
<p>更新至V1.2.20</p>
3234
<h3 id="20250824">20250824</h3>
3335
<p>更新至V1.2.19</p>
3436
<h3 id="20250823">20250823</h3>
3537
<p>更新至V1.2.18</p>
3638
<h3 id="20250822">20250822</h3>
37-
<p>更新至V1.2.17</p>
38-
<h3 id="20250821">20250821</h3>
39-
<p>更新至V1.2.16</p>
40-
<h3 id="20250819">20250819</h3>
41-
<p>更新至V1.2.15</p>
4239
<p><a href="docs/updateRecord.md">点此查看完整更新记录</a></p>
4340
<p><strong>注意事项</strong></p>
4441
<p>总是有人遇到各种奇葩问题,像什么没弹幕,访问/config/1服务马上崩溃等等,能自行解决最好,解决不了我建议你使用下方安装教程

spider/js/七猫小说[书].js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
filterable: 1,
55
quickSearch: 0,
66
title: '七猫小说[书]',
7+
logo: 'https://cdn-front.qimao.com/global/static/images/favicon2022.ico',
78
lang: 'ds'
89
})
910
*/

spider/py/core/t4_daemon.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import hashlib
1212
import importlib
1313
import importlib.util
14-
import json
14+
import ujson
1515
import logging
1616
import os
1717
import pickle
@@ -130,7 +130,7 @@ def recv_packet(rfile) -> dict:
130130
raise ValueError("invalid length")
131131
payload = recv_exact(rfile, length)
132132
try:
133-
return json.loads(payload.decode("utf-8"))
133+
return ujson.loads(payload.decode("utf-8"))
134134
except Exception:
135135
return pickle.loads(payload)
136136

@@ -251,7 +251,7 @@ def _parse_env(env_str: str):
251251
ext = ""
252252
if isinstance(env_str, str) and env_str.strip():
253253
try:
254-
data = json.loads(env_str)
254+
data = ujson.loads(env_str)
255255
proxy_url = data.get("proxyUrl", "") or ""
256256
# 仅从解析出的字典取 ext 字段,若不存在则为空字符串
257257
ext = data.get("ext", "") or ""
@@ -629,7 +629,7 @@ def _invoke(self, inst: SpiderInstance, method_name: str, args_list):
629629
parsed_args.append(a)
630630
elif isinstance(a, str):
631631
try:
632-
parsed_args.append(json.loads(a))
632+
parsed_args.append(ujson.loads(a))
633633
except Exception:
634634
parsed_args.append(a)
635635
else:
@@ -684,12 +684,14 @@ class T4Handler(StreamRequestHandler):
684684
def handle(self):
685685
self.request.settimeout(REQUEST_TIMEOUT)
686686
try:
687+
logger.info('before recv_packet')
687688
req = recv_packet(self.rfile)
689+
logger.info('before recv_packet req')
688690
script_path = req.get("script_path", "")
689691
method_name = req.get("method_name", "")
690692
env = req.get("env", "") or ""
691693
args = req.get("args", []) or []
692-
694+
logger.info("T4Handler start: script_path:%s method_name:%s", script_path, method_name)
693695
result = _manager.call(script_path, method_name, env, args)
694696
# 统一外层返回格式
695697
resp = {
@@ -705,7 +707,10 @@ def handle(self):
705707

706708
send_packet(self.wfile, resp)
707709
except Exception as e:
708-
logger.error("T4Handler error: %s", e)
710+
if "peer closed during read" in str(e).lower():
711+
logger.warning("Client connected then closed without sending data")
712+
else:
713+
logger.error("T4Handler error: %s", e)
709714
try:
710715
send_packet(self.wfile, {"success": False, "error": str(e)})
711716
except Exception:
@@ -723,6 +728,7 @@ def _stop(*_):
723728
_manager.stop()
724729
# 让 serve_forever() 退出
725730
srv.shutdown()
731+
sys.exit(0) # 保证退出码是 0
726732

727733
if os.name == "posix":
728734
signal.signal(signal.SIGTERM, _stop)

0 commit comments

Comments
 (0)