Skip to content

Commit aaffb1e

Browse files
author
Taois
committed
feat: 增加fast版本core打包
1 parent 396df28 commit aaffb1e

File tree

7 files changed

+213
-14
lines changed

7 files changed

+213
-14
lines changed

dist/drpy-core-fast.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.

drpy2-fast/drpy-core-fast.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.

drpy2-fast/drpy2-fast.min.js

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

src/drpy-core-fast.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// drpy-core.js
2+
import template from './libs/模板.js'; // 使用英文名导入
3+
4+
// 轻量依赖
5+
// import './libs-lite/EncoderDecoder.min.js'
6+
// import './libs-lite/jsencrypt.min.js'; // 此库亲自不行
7+
// 导入所有依赖库
8+
// import './libs/jsencrypt.min.js';
9+
import './libs/gb18030.min.js';
10+
import './libs/crypto-js.min.js';
11+
// import './libs/node-rsa.min.js';
12+
// import './libs/pako.min.js';
13+
import './libs/json5.min.js';
14+
import './libs/jsonpathplus.min.js';
15+
import './libs/jinja.min.js';
16+
// import './libs/polywasm.min.js';
17+
import './libs/xxhash-wasm.min.js';
18+
// export {Buffer} from './libs/buffer.min.js'
19+
20+
21+
// 确保全局依赖可用
22+
const g = globalThis;
23+
const gbkTool = g.gbkTool;
24+
const CryptoJS = g.CryptoJS;
25+
// const JSEncrypt = g.JSEncrypt;
26+
// const NODERSA = g.NODERSA; // lite版弃用
27+
// const pako = g.pako;
28+
const JSON5 = g.JSON5;
29+
const JSONPath = g.JSONPath;
30+
const jinja = g.jinja;
31+
// const WebAssembly = g.WebAssembly;
32+
// const TextEncoder = g.TextEncoder;
33+
// const TextDecoder = g.TextDecoder;
34+
35+
/*
36+
patch打补丁开始
37+
1. cheerio对象 只保留在用的jinja2和jp函数,其他pdf系列交给壳子
38+
2. JSEncrypt换库但是保留encryptUnicodeLong和decryptUnicodeLong函数
39+
*/
40+
const cheerio = {
41+
jinja2(template, obj) {
42+
return jinja.render(template, obj);
43+
},
44+
jp(path, json) {
45+
return JSONPath.JSONPath({
46+
path,
47+
json
48+
})[0];
49+
}
50+
}
51+
// JSEncrypt.encryptUnicodeLong = JSEncrypt.encryptLong;
52+
// JSEncrypt.decryptUnicodeLong = JSEncrypt.decryptLong;
53+
/*
54+
patch打补丁结束
55+
*/
56+
57+
// 导出所有需要暴露的内容
58+
export {
59+
cheerio,
60+
template as 模板, // 使用别名导出中文标识符
61+
gbkTool,
62+
CryptoJS,
63+
// JSEncrypt,
64+
// NODERSA,
65+
// pako,
66+
JSON5,
67+
JSONPath,
68+
jinja,
69+
// WebAssembly,
70+
// TextEncoder,
71+
// TextDecoder,
72+
};

src/drpy2-fast.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// import {cheerio, 模板} from '../dist/drpy-core.min.js';
2-
import {cheerio, 模板, Buffer} from '../dist/drpy-core-lite.min.js';
1+
import {cheerio, 模板} from '../dist/drpy-core-fast.min.js';
32

43
let vercode = typeof (pdfl) === 'function' ? 'drpy2.1' : 'drpy2';
54
const VERSION = vercode + ' 3.9.53 20251007';
@@ -3452,16 +3451,40 @@ function getOriginalJs(js_code) {
34523451
let decode_content = '';
34533452

34543453
function aes_decrypt(data) {
3455-
let key = CryptoJS.enc.Hex.parse("686A64686E780A0A0A0A0A0A0A0A0A0A");
3456-
let iv = CryptoJS.enc.Hex.parse("647A797964730A0A0A0A0A0A0A0A0A0A");
3457-
let encrypted = CryptoJS.AES.decrypt({
3458-
ciphertext: CryptoJS.enc.Base64.parse(data)
3459-
}, key, {
3460-
iv: iv,
3461-
mode: CryptoJS.mode.CBC,
3462-
padding: CryptoJS.pad.Pkcs7
3463-
}).toString(CryptoJS.enc.Utf8);
3464-
return encrypted;
3454+
// 将密钥和IV从十六进制字符串转换为Uint8Array
3455+
const keyHex = "686A64686E780A0A0A0A0A0A0A0A0A0A";
3456+
const ivHex = "647A797964730A0A0A0A0A0A0A0A0A0A";
3457+
const keyArray = new Uint8Array(Buffer.from(keyHex, "hex"));
3458+
const ivArray = new Uint8Array(Buffer.from(ivHex, "hex"));
3459+
3460+
// 将Base64编码的数据转换为Uint8Array
3461+
const encryptedArray = new Uint8Array(Buffer.from(data, "base64"));
3462+
3463+
// 导入密钥
3464+
const key = crypto.subtle.importKey(
3465+
"raw",
3466+
keyArray,
3467+
{ name: "AES-CBC" },
3468+
false,
3469+
["decrypt"]
3470+
);
3471+
try {
3472+
// 解密
3473+
const decryptedArray = crypto.subtle.decrypt(
3474+
{
3475+
name: "AES-CBC",
3476+
iv: ivArray,
3477+
},
3478+
key,
3479+
encryptedArray
3480+
);
3481+
// 将解密后的Uint8Array转换为字符串
3482+
const decryptedString = new TextDecoder().decode(decryptedArray);
3483+
return decryptedString;
3484+
} catch (e) {
3485+
console.error("解密失败:", e);
3486+
return null;
3487+
}
34653488
}
34663489

34673490
let error_log = false;
@@ -3736,6 +3759,7 @@ function init(ext) {
37363759
init_test();
37373760
} catch (e) {
37383761
console.log(`init_test发生错误:${e.message}`);
3762+
throw e;
37393763
}
37403764
}
37413765

src/drpy2-fast.min.js

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

webpack.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = {
2828
entry: {
2929
'drpy-core': './src/drpy-core.js', // 完整版入口
3030
'drpy-core-lite': './src/drpy-core-lite.js', // lite版入口
31+
'drpy-core-fast': './src/drpy-core-fast.js', // lite版入口
3132
},
3233

3334
output: {

0 commit comments

Comments
 (0)