Skip to content

Commit e19bed2

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

16 files changed

+378
-126
lines changed

Diff for: .github/workflows/build-nodejs.yml

+27
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

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/nodejs/node_modules/
2+
/nodejs/dist/
3+
/.idea/

Diff for: nodejs/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
generated
3+
node_modules
4+
db.json

Diff for: nodejs/esbuild-config.js

+1-1
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

Diff for: nodejs/esbuild.js

+1-1
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

Diff for: nodejs/package.json

+10-6
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
}

Diff for: nodejs/safeApi.js

+89
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);

Diff for: nodejs/source/ds-cat-20250117-2.7z

1.42 MB
Binary file not shown.

Diff for: nodejs/source/xxx猫影视-20250108.zip

-878 KB
Binary file not shown.

Diff for: nodejs/source/xxx猫爪-20250117.zip

822 KB
Binary file not shown.

Diff for: nodejs/src/index.config.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
export default {
22
drpyS: {
3-
config_url: 'http://127.0.0.1:5757/config/1?sub=all&pwd=',
3+
config_url: 'http://localhost:5757/config/1?sub=all&pwd=',
4+
home_site: 'http://localhost:5757/api/设置中心',
5+
enable_dspush: 1,
6+
enable_home_site: 0,
47
},
58
ffm3u8: {
6-
url: 'https://cj.ffzyapi.com/api.php/provide/vod/',
9+
url: 'https://cj.ffzyapi.com/api.php/provide/vod/from/ffm3u8',
710
categories: ['国产剧', '香港剧', '韩国剧', '欧美剧', '台湾剧', '日本剧', '海外剧', '泰国剧', '短剧', '动作片', '喜剧片', '爱情片', '科幻片', '恐怖片', '剧情片', '战争片', '动漫片', '大陆综艺', '港台综艺', '日韩综艺', '欧美综艺', '国产动漫', '日韩动漫', '欧美动漫', '港台动漫', '海外动漫', '记录片'],
811
},
912
alist: [

Diff for: nodejs/src/router.js

+78-39
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import copymanga from './spider/book/copymanga.js';
66
import ffm3u8 from './spider/video/ffm3u8.js';
77
import drpyS from './spider/video/drpyS.js';
88
import {request} from "./util/request.js";
9+
import {extractTags} from "./util/tool.js";
910

1011
const spiders = [ffm3u8, push, alist, _13bqg, copymanga, drpyS];
1112
const spiderPrefix = '/spider';
13+
let dsSites = [];
14+
let dsParses = [];
15+
let drpyS_data = {};
1216

1317
/**
1418
* A function to initialize the router.
@@ -18,22 +22,72 @@ const spiderPrefix = '/spider';
1822
*/
1923
export default async function router(fastify) {
2024
// register all spider router
21-
spiders.forEach((spider) => {
25+
// spiders.forEach((spider) => {
26+
// const path = spiderPrefix + '/' + spider.meta.key + '/' + spider.meta.type;
27+
// if ((spider === drpyS && cfg.default.drpyS.enable_home_site) || spider !== drpyS) {
28+
// fastify.register(spider.api, {prefix: path});
29+
// console.log('Register spider: ' + path);
30+
// }
31+
//
32+
// });
33+
for (const spider of spiders) {
2234
const path = spiderPrefix + '/' + spider.meta.key + '/' + spider.meta.type;
35+
if (spider === drpyS && !cfg.default.drpyS.enable_home_site) { // 没启用ds首页就不显示这个源
36+
continue
37+
} else if (spider === push && cfg.default.drpyS.enable_dspush) { // 启动ds 推送就禁用系统推送
38+
continue
39+
}
2340
fastify.register(spider.api, {prefix: path});
2441
console.log('Register spider: ' + path);
25-
});
26-
// console.log(cfg.default);
27-
// if (cfg.default.drpyS && cfg.default.drpyS.config_url) {
28-
// let drpyS_config_url = cfg.default.drpyS.config_url;
29-
// if (drpyS_config_url && drpyS_config_url.startsWith('http')) {
30-
// let drpyS_data = await request(drpyS_config_url);
31-
// if (drpyS_data.sites_count && drpyS_data.homepage === 'https://github.com/hjdhnx/drpy-node') {
32-
// let drpyS_sites = drpyS_data.sites;
33-
// console.log(drpyS_sites);
34-
// }
35-
// }
36-
// }
42+
}
43+
console.log(cfg.default);
44+
if (cfg.default.drpyS && cfg.default.drpyS.config_url) {
45+
let drpyS_config_url = cfg.default.drpyS.config_url;
46+
if (drpyS_config_url && drpyS_config_url.startsWith('http')) {
47+
try {
48+
49+
drpyS_data = await request(drpyS_config_url);
50+
if (drpyS_data.sites_count && drpyS_data.homepage === 'https://github.com/hjdhnx/drpy-node') {
51+
let drpyS_sites = drpyS_data.sites.filter(site => site.type === 4);
52+
53+
// console.log(drpyS_sites);
54+
dsSites = drpyS_sites.map((site) => {
55+
let meta = {};
56+
let skey = site.key;
57+
let sname = site.name;
58+
let stags = extractTags(sname);
59+
if (skey === 'push_agent') {
60+
meta.type = 4;
61+
} else if (stags.includes('书')) {
62+
meta.type = 10;
63+
} else if (stags.includes('画')) {
64+
meta.type = 20;
65+
} else if (stags.includes('听')) {
66+
meta.type = 30;
67+
} else {
68+
meta.type = 7;
69+
}
70+
meta.key = skey === 'push_agent' ? 'push' : skey;
71+
meta.name = site.name;
72+
meta.api = spiderPrefix + '/' + 'drpyS' + '/' + meta.type + '/' + meta.key;
73+
meta.ext = {api: site.api, extend: site.ext};
74+
return meta;
75+
});
76+
77+
dsParses = drpyS_data.parses;
78+
79+
80+
dsSites.forEach((site) => {
81+
const path = site.api;
82+
fastify.register(drpyS.api, {prefix: path});
83+
console.log('Register spider: ' + path);
84+
});
85+
}
86+
} catch (e) {
87+
console.log(`加载配置发生了错误: ${e.message}`)
88+
}
89+
}
90+
}
3791
/**
3892
* @api {get} /check 检查
3993
*/
@@ -80,11 +134,17 @@ export default async function router(fastify) {
80134
},
81135
color: fastify.config.color || [],
82136
};
83-
spiders.forEach((spider) => {
137+
for (const spider of spiders) {
138+
if (spider === drpyS && !cfg.default.drpyS.enable_home_site) { // 没启用ds首页就不显示这个源
139+
continue
140+
} else if (spider === push && cfg.default.drpyS.enable_dspush) { // 启动ds 推送就禁用系统推送
141+
continue
142+
}
143+
84144
let meta = Object.assign({}, spider.meta);
85145
meta.api = spiderPrefix + '/' + meta.key + '/' + meta.type;
86146
meta.key = 'nodejs_' + meta.key;
87-
meta.ext = '';
147+
meta.ext = {};
88148
const stype = spider.meta.type;
89149
if (stype < 10) {
90150
config.video.sites.push(meta);
@@ -97,32 +157,11 @@ export default async function router(fastify) {
97157
} else if (stype >= 40 && stype < 50) {
98158
config.pan.sites.push(meta);
99159
}
100-
});
101-
102-
console.log(cfg.default);
103-
if (cfg.default.drpyS && cfg.default.drpyS.config_url) {
104-
let drpyS_config_url = cfg.default.drpyS.config_url;
105-
if (drpyS_config_url && drpyS_config_url.startsWith('http')) {
106-
let drpyS_data = await request(drpyS_config_url);
107-
if (drpyS_data.sites_count && drpyS_data.homepage === 'https://github.com/hjdhnx/drpy-node') {
108-
let drpyS_sites = drpyS_data.sites.filter(site => site.type === 4);
109-
console.log(drpyS_sites);
110-
const sites = drpyS_sites.map((site) => {
111-
let meta = {};
112-
meta.key = site.key;
113-
meta.name = site.name;
114-
meta.type = site.type;
115-
meta.api = '/spider/drpyS/4';
116-
meta.ext = {api: site.api, extend: site.ext};
117-
return meta;
118-
});
119-
config.video.sites = config.video.sites.concat(sites);
120-
drpyS.updateSiteMap(sites);
121-
config.parses = drpyS_data.parses;
122-
}
123-
}
124160
}
125161

162+
config.video.sites = config.video.sites.concat(dsSites);
163+
drpyS.updateSiteMap(dsSites);
164+
config.parses = dsParses;
126165
console.log(JSON.stringify(config));
127166
reply.send(config);
128167
}

0 commit comments

Comments
 (0)