Skip to content

Commit e19bed2

Browse files
committed
update:完善ds猫
1 parent bf95070 commit e19bed2

File tree

16 files changed

+378
-126
lines changed

16 files changed

+378
-126
lines changed

.github/workflows/build-nodejs.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build NodeJS
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-node@v3
13+
with:
14+
node-version: 18.17.1
15+
16+
- name: Run npm bild
17+
working-directory: nodejs
18+
run: |
19+
npm i
20+
npm run build
21+
22+
- name: Archive dist
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: dist
26+
path: |
27+
nodejs/dist

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/nodejs/node_modules/
2+
/nodejs/dist/
3+
/.idea/

nodejs/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
generated
3+
node_modules
4+
db.json

nodejs/esbuild-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ esbuild.build({
1212
format: 'cjs',
1313
platform: 'node',
1414
target: 'node18',
15-
sourcemap: true,
15+
sourcemap: process.env.NODE_ENV === 'development' ? 'inline' : false,
1616
plugins: [genMd5()],
1717
});
1818

nodejs/esbuild.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ esbuild.build({
1111
format: 'cjs',
1212
platform: 'node',
1313
target: 'node18',
14-
sourcemap: true,
14+
sourcemap: process.env.NODE_ENV === 'development' ? 'inline' : false,
1515
plugins: [genMd5()],
1616
});
1717

nodejs/package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
{
22
"name": "cat_vod_nodejs_fastify",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "CatVodOpen nodejs config api server demo.",
55
"type": "module",
66
"scripts": {
77
"dev": "cross-env DEV_HTTP_PORT=3006 nodemon --config nodemon.json src/dev.js",
8-
"build": "rimraf dist && cross-env NODE_ENV=production node esbuild.js && cross-env NODE_ENV=production node esbuild-config.js",
9-
"build:copy": "rimraf dist && cross-env NODE_ENV=production node esbuild.js && cross-env NODE_ENV=production node esbuild-config.js && node copyDist.js \"D:\\\\soft\\\\猫影视\\\\Release\\\\data\\\\flutter_assets\\\\asset\\\\js\"",
8+
"_build": "rimraf dist && node esbuild.js && node esbuild-config.js",
9+
"build": "cross-env NODE_ENV=production npm run _build",
10+
"build:copy": "cross-env NODE_ENV=production npm run _build && node copyDist.js D:\\soft\\猫影视\\Release\\data\\flutter_assets\\asset\\js",
11+
"build:dbg": "cross-env NODE_ENV=development npm run _build",
1012
"build:config": "cross-env NODE_ENV=production node esbuild-config.js",
11-
"build:rollup": "rimraf dist && cross-env NODE_ENV=production node rollup.js && cross-env NODE_ENV=production node rollup-config.js",
12-
"build:rollup:config": "cross-env NODE_ENV=production node rollup-config.js"
13+
"build:rollup(obsolete)": "rimraf dist && cross-env NODE_ENV=production node rollup.js && cross-env NODE_ENV=production node rollup-config.js",
14+
"build:rollup:config(obsolete)": "cross-env NODE_ENV=production node rollup-config.js",
15+
"build-old:copy": "rimraf dist && cross-env NODE_ENV=production node esbuild.js && cross-env NODE_ENV=production node esbuild-config.js && node copyDist.js E:\\soft\\windows_release_open_2.0.3_beta2\\Release\\data\\flutter_assets\\asset\\js"
1316
},
14-
"author": "",
17+
"author": "道长",
1518
"devDependencies": {
1619
"@babel/plugin-transform-runtime": "^7.23.9",
1720
"@babel/preset-env": "^7.23.9",
@@ -38,6 +41,7 @@
3841
"iconv-lite": "^0.6.3",
3942
"node-json-db": "^2.3.0",
4043
"node-rsa": "^1.1.1",
44+
"pako": "^2.1.0",
4145
"qs": "^6.14.0"
4246
}
4347
}

nodejs/safeApi.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// 引入必要模块
2+
import CryptoJS from 'crypto-js';
3+
import pako from 'pako';
4+
import { Buffer } from 'buffer';
5+
6+
/**
7+
* 随机生成加密和解密算法
8+
* @returns {Object} - 包含加密和解密函数的对象
9+
*/
10+
function createRandomEncryption() {
11+
// 可用的编码工具
12+
const tools = [
13+
{
14+
name: 'base64Encode',
15+
encode: (data) => Buffer.from(data).toString('base64'),
16+
decode: (data) => Buffer.from(data, 'base64').toString('utf-8')
17+
},
18+
{
19+
name: 'aesEncrypt',
20+
encode: (data, key) => CryptoJS.AES.encrypt(data, key).toString(),
21+
decode: (data, key) => CryptoJS.AES.decrypt(data, key).toString(CryptoJS.enc.Utf8)
22+
},
23+
{
24+
name: 'gzipCompress',
25+
encode: (data) => Buffer.from(pako.gzip(data)).toString('base64'),
26+
decode: (data) => pako.ungzip(Buffer.from(data, 'base64'), { to: 'string' })
27+
},
28+
{
29+
name: 'addRandomString',
30+
encode: (data) => {
31+
const length = Math.floor(Math.random() * 7) + 4; // 随机长度在4到10之间
32+
const randomStr = Math.random().toString(36).substring(2, 2 + length);
33+
addRandomStringTracker.push({ value: randomStr, position: addRandomStringTracker.length });
34+
return data + randomStr;
35+
},
36+
decode: (data) => {
37+
const { value } = addRandomStringTracker.pop();
38+
return data.slice(0, -value.length);
39+
}
40+
}
41+
];
42+
43+
// 跟踪插入的随机字符串
44+
const addRandomStringTracker = [];
45+
46+
// 随机生成加密和解密的组合序列
47+
const encodeSequence = Array.from({ length: Math.floor(Math.random() * tools.length) + 1 }, () => {
48+
return tools[Math.floor(Math.random() * tools.length)];
49+
});
50+
51+
// 生成加密函数
52+
const encrypt = (data, key = 'default_key') => {
53+
let encrypted = data;
54+
for (const tool of encodeSequence) {
55+
encrypted = tool.encode(encrypted, key);
56+
}
57+
return encrypted;
58+
};
59+
60+
// 生成解密函数
61+
const decrypt = (data, key = 'default_key') => {
62+
let decrypted = data;
63+
for (const tool of encodeSequence.slice().reverse()) {
64+
decrypted = tool.decode(decrypted, key);
65+
}
66+
return decrypted;
67+
};
68+
69+
// 返回加解密函数
70+
return {
71+
encrypt,
72+
decrypt,
73+
sequence: encodeSequence.map(tool => tool.name),
74+
randomStrings: addRandomStringTracker
75+
};
76+
}
77+
78+
// 示例使用
79+
const { encrypt, decrypt, sequence, randomStrings } = createRandomEncryption();
80+
const originalText = 'Hello, world!';
81+
const key = 'my_secret_key';
82+
83+
const encryptedText = encrypt(originalText, key);
84+
console.log('加密算法顺序:', sequence);
85+
console.log('插入的随机字符串:', randomStrings.map(({ value, position }) => `位置: ${position}, 值: ${value}`));
86+
console.log('加密后的文本:', encryptedText);
87+
88+
const decryptedText = decrypt(encryptedText, key);
89+
console.log('解密后的文本:', decryptedText);

nodejs/source/ds-cat-20250117-2.7z

1.42 MB
Binary file not shown.
-878 KB
Binary file not shown.
822 KB
Binary file not shown.

0 commit comments

Comments
 (0)