Skip to content

Commit f5b00f0

Browse files
author
Taois
committed
feat: drpy2接口升级
1 parent 1344cc8 commit f5b00f0

23 files changed

+284
-553
lines changed

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ENV='staging'
77

88
LOG_WITH_FILE = 1
99
FORCE_HEADER = 0
10+
# dr2的api,默认0取public目录。设置1取壳子内部assets
1011
DR2_API_TYPE = 0
1112
# trace/debug/info/warn/error/fatal
1213
LOG_LEVEL = info

README.md

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

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

@@ -16,10 +16,15 @@ nodejs作为服务端的drpy实现。全面升级异步写法
1616
* [本站防止爬虫协议](/robots.txt)
1717
* [本项目主页-免翻](https://github.com/hjdhnx/drpy-node)
1818
* [DS源适配猫影视](https://github.com/hjdhnx/CatPawOpen/tree/ds-cat)
19+
* [drpy2打包项目](https://github.com/hjdhnx/drpy-webpack)
1920
* [在线猫ds源主页](/cat/index.html)
2021

2122
## 更新记录
2223

24+
### 20250729
25+
26+
更新至V1.2.3
27+
2328
### 20250728
2429

2530
更新至V1.2.2

controllers/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async function generateSiteJSON(options, requestHost, sub, pwd) {
199199
func: async ({file, dr2Dir, requestHost, pwd, drpy, SitesMap}) => {
200200
const baseName = path.basename(file, '.js'); // 去掉文件扩展名
201201
// dr2ApiType=0 使用接口drpy2 dr2ApiType=1 使用壳子内置的drpy2
202-
let api = dr2ApiType ? `assets://js/lib/drpy2.js` : `${requestHost}/public/drpy2/drpy2.min.js`;
202+
let api = dr2ApiType ? `assets://js/lib/drpy2.js` : `${requestHost}/public/drpy/drpy2.min.js`;
203203
let ext = `${requestHost}/js/${file}`;
204204
if (pwd) {
205205
ext += `?pwd=${pwd}`;

docs/updateRecord.md

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

3+
### 20250729
4+
5+
更新至V1.2.3
6+
7+
1. drpy2接口增加 `buildQueryString` `TextEncoder` `TextDecoder` `WXXH` `WebAssembly`
8+
2. drpy2 依赖库打包成一个 `drpy-core.js`
9+
10+
具体打包过程参考:[drpy2打包项目](https://github.com/hjdhnx/drpy-webpack)
11+
312
### 20250728
413

514
更新至V1.2.2

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.2",
3+
"version": "1.2.3",
44
"main": "index.js",
55
"type": "module",
66
"scripts": {

public/dist/drpy-core.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/drpy/drpy-core.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// drpy-core.js
2+
import cheerio from './libs/cheerio.min.js';
3+
import template from './libs/模板.js'; // 使用英文名导入
4+
5+
// 导入所有依赖库
6+
import './libs/gb18030.min.js';
7+
import './libs/crypto-js.min.js';
8+
import './libs/jsencrypt.min.js';
9+
import './libs/node-rsa.min.js';
10+
import './libs/pako.min.js';
11+
import './libs/json5.min.js';
12+
import './libs/jsonpathplus.min.js';
13+
import './libs/jinja.min.js';
14+
import './libs/polywasm.min.js';
15+
import './libs/encoding.min.js'
16+
import './libs/xxhash-wasm.min.js';
17+
18+
// 确保全局依赖可用
19+
20+
const gbkTool = globalThis.gbkTool;
21+
const CryptoJS = globalThis.CryptoJS;
22+
const JSEncrypt = globalThis.JSEncrypt;
23+
const NODERSA = globalThis.NODERSA;
24+
const pako = globalThis.pako;
25+
const JSON5 = globalThis.JSON5;
26+
const JSONPath = globalThis.JSONPath;
27+
const jinja = globalThis.jinja;
28+
const WebAssembly = globalThis.WebAssembly;
29+
const TextEncoder = globalThis.TextEncoder;
30+
const TextDecoder = globalThis.TextDecoder;
31+
32+
33+
// const cheerio = {
34+
// jinja2(template, obj) {
35+
// return jinja.render(template, obj);
36+
// },
37+
// jp(path, json) {
38+
// return JSONPath.JSONPath({
39+
// path,
40+
// json
41+
// })[0];
42+
// }
43+
// }
44+
45+
const _jinja2 = cheerio.jinja2;
46+
cheerio.jinja2 = function (template, obj) {
47+
try {
48+
return jinja.render(template, obj);
49+
} catch (e) {
50+
console.log('新的jinja2库渲染失败,换回原始cheerio:' + e.message);
51+
return _jinja2(template, obj)
52+
}
53+
};
54+
cheerio.jp = function (path, json) {
55+
return JSONPath.JSONPath({
56+
path,
57+
json
58+
})[0];
59+
};
60+
61+
62+
// 导出所有需要暴露的内容
63+
export {
64+
cheerio,
65+
template as 模板, // 使用别名导出中文标识符
66+
gbkTool,
67+
CryptoJS,
68+
JSEncrypt,
69+
NODERSA,
70+
pako,
71+
JSON5,
72+
JSONPath,
73+
jinja,
74+
WebAssembly,
75+
TextEncoder,
76+
TextDecoder,
77+
};

public/drpy/drpy-test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {cheerio, 模板} from '../dist/drpy-core.min.js';
2+
// import {cheerio, JSONPath, TextDecoder, TextEncoder, 模板} from './drpy-core.js';
3+
4+
console.log('typeof 模板:', typeof (模板))
5+
console.log('typeof cheerio:', typeof (cheerio))
6+
// console.log(模板)
7+
console.log('typeof gbkTool:', typeof gbkTool);
8+
console.log('typeof CryptoJS:', typeof CryptoJS);
9+
console.log('typeof JSEncrypt:', typeof JSEncrypt);
10+
console.log('typeof NODERSA:', typeof NODERSA);
11+
console.log('typeof pako:', typeof pako);
12+
console.log('typeof JSON5:', typeof JSON5);
13+
console.log('typeof JSONPath:', typeof JSONPath);
14+
console.log('typeof jinja:', typeof jinja);
15+
console.log('typeof WebAssembly:', typeof WebAssembly);
16+
console.log('typeof TextEncoder:', typeof TextEncoder);
17+
console.log('typeof TextDecoder:', typeof TextDecoder);
18+
console.log('typeof WXXH:', typeof WXXH);
19+
20+
console.log(gbkTool.encode('你好'));
21+
console.log(gbkTool.decode('%C4%E3%BA%C3'));
22+
23+
const s = '{"method":"GET","timestamp":1745206708456,"path":"/index/fuck","parameters":{"timestamp":["1745206708456"]},"body":""}';
24+
const seed = 1745206708;
25+
const hash = WXXH.h64(s, seed).toString(16);
26+
console.log(`WASM:${hash}`);
27+
28+
console.log(cheerio.jinja2('渲染一个变量{{hash}}', {hash}));
29+
console.log('jsonpath取值测试:', cheerio.jp('$.name', {name: '道长', project: 'drpys'}));

public/drpy2/drpy2.js renamed to public/drpy/drpy2.js

Lines changed: 67 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,21 @@
1-
import cheerio from './cheerio.min.js';
2-
import 模板 from './模板.js'
3-
import {gbkTool} from './gbk.min.js'
4-
import './crypto-js.min.js';
5-
import './jsencrypt.min.js';
6-
import './node-rsa.js';
7-
import './pako.min.js';
8-
// import JSEncrypt from './jsencrypt.js'; // 会导致壳子崩溃的
9-
import './json5.min.js'
10-
// 下面是尝试对jinja2库进行更换
11-
import './jinja.min.js'
12-
// 新增wasm支持
13-
import './polywasm.min.js'
14-
// TextEncoder,TextDecoder对象 引入不进来,下面两行代码都不行
15-
// import './encoding.min.js'
16-
// import './xxhash-wasm.min.js'
17-
18-
19-
const _jinja2 = cheerio.jinja2;
20-
cheerio.jinja2 = function (template, obj) {
21-
try {
22-
return jinja.render(template, obj);
23-
} catch (e) {
24-
console.log('新的jinja2库渲染失败,换回原始cheerio:' + e.message);
25-
return _jinja2(template, obj)
26-
}
27-
};
28-
// import cheerio from "https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/cheerio.min.js";
29-
// import "https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/crypto-js.js";
30-
// import 模板 from"https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/js/模板.js";
31-
// import {gbkTool} from 'https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/gbk.js'
1+
import {cheerio, 模板} from '../dist/drpy-core.min.js';
322

333
let vercode = typeof (pdfl) === 'function' ? 'drpy2.1' : 'drpy2';
34-
const VERSION = vercode + ' 3.9.52beta1 20250728';
4+
const VERSION = vercode + ' 3.9.52beta2 20250729';
355
const UpdateInfo = [
6+
{
7+
date: '20250729',
8+
title: 'drpy更新,所有依赖打包成一个js文件',
9+
version: '3.9.52beta2 20250729',
10+
msg: `
11+
1. wasm支持
12+
2. 引入 TextEncoder、TextDecoder对象
13+
3. 引入 WXXH 加解密库
14+
4. 所有依赖打包成一个js
15+
5. 增加 buildQueryString
16+
17+
`
18+
},
3619
{
3720
date: '20250728',
3821
title: 'drpy更新,增加tab_order线路模糊排序,优化解密算法支持文件头',
@@ -81,10 +64,35 @@ function init_test() {
8164
// print(模板);
8265
// print(typeof(模板.getMubans));
8366
console.log("当前版本号:" + VERSION);
84-
console.log("typeof TextEncoder:" + typeof TextEncoder);
85-
console.log("typeof TextDecoder:" + typeof TextDecoder);
86-
console.log("typeof WebAssembly:" + typeof WebAssembly);
87-
console.log("typeof WXXH:" + typeof WXXH);
67+
/*
68+
console.log('typeof 模板:', typeof (模板))
69+
console.log('typeof cheerio:', typeof (cheerio))
70+
// console.log(模板)
71+
console.log('typeof gbkTool:', typeof gbkTool);
72+
console.log('typeof CryptoJS:', typeof CryptoJS);
73+
console.log('typeof JSEncrypt:', typeof JSEncrypt);
74+
console.log('typeof NODERSA:', typeof NODERSA);
75+
console.log('typeof pako:', typeof pako);
76+
console.log('typeof JSON5:', typeof JSON5);
77+
console.log('typeof JSONPath:', typeof JSONPath);
78+
console.log('typeof jinja:', typeof jinja);
79+
console.log('typeof WebAssembly:', typeof WebAssembly);
80+
console.log('typeof TextEncoder:', typeof TextEncoder);
81+
console.log('typeof TextDecoder:', typeof TextDecoder);
82+
console.log('typeof WXXH:', typeof WXXH);
83+
84+
console.log(gbkTool.encode('你好'));
85+
console.log(gbkTool.decode('%C4%E3%BA%C3'));
86+
87+
const s = '{"method":"GET","timestamp":1745206708456,"path":"/index/fuck","parameters":{"timestamp":["1745206708456"]},"body":""}';
88+
const seed = 1745206708;
89+
const hash = WXXH.h64(s, seed).toString(16);
90+
console.log(`WASM:${hash}`);
91+
92+
console.log(cheerio.jinja2('渲染一个变量{{hash}}', {hash}));
93+
console.log('jsonpath取值测试:', cheerio.jp('$.name', {name: '道长', project: 'drpys'}));
94+
*/
95+
8896
console.log('本地代理地址:' + getProxyUrl());
8997
console.log(RKEY);
9098
// ocr_demo_test();
@@ -896,8 +904,7 @@ function ungzip(b64Data) {
896904
function encodeStr(input, encoding) {
897905
encoding = encoding || 'gbk';
898906
if (encoding.startsWith('gb')) {
899-
const strTool = gbkTool();
900-
input = strTool.encode(input);
907+
input = gbkTool.encode(input);
901908
}
902909
return input
903910
}
@@ -911,8 +918,7 @@ function encodeStr(input, encoding) {
911918
function decodeStr(input, encoding) {
912919
encoding = encoding || 'gbk';
913920
if (encoding.startsWith('gb')) {
914-
const strTool = gbkTool();
915-
input = strTool.decode(input);
921+
input = gbkTool.decode(input);
916922
}
917923
return input
918924
}
@@ -1716,6 +1722,27 @@ function keysToLowerCase(obj) {
17161722
}, {});
17171723
}
17181724

1725+
//对象To字符串query
1726+
function buildQueryString(params) {
1727+
const queryArray = [];
1728+
for (const key in params) {
1729+
if (params.hasOwnProperty(key)) {
1730+
// 处理参数值:兼容null、undefined,转为字符串并编码
1731+
let value = params[key];
1732+
if (value === undefined || value === null) {
1733+
value = "";
1734+
} else {
1735+
value = value.toString();
1736+
}
1737+
// 编码键值(兼容ES5)
1738+
const encodedKey = encodeURIComponent(key);
1739+
const encodedValue = encodeURIComponent(value);
1740+
queryArray.push(encodedKey + "=" + encodedValue);
1741+
}
1742+
}
1743+
return queryArray.join("&");
1744+
}
1745+
17191746
//字符串To对象
17201747
function parseQueryString(query) {
17211748
const params = {};

0 commit comments

Comments
 (0)