Skip to content

Commit 5f46bb6

Browse files
author
Taois
committed
feat: 发布新版本
1 parent ac7d6f0 commit 5f46bb6

File tree

16 files changed

+578
-73
lines changed

16 files changed

+578
-73
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,4 @@ dist
145145
/jx/芒果关姐.js
146146
/data/mv/
147147
/database.db
148+
/scripts/python/XYQ提取结果.json

config/map.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
哔哩收藏[官]@?render=1&type=url&params=../json/哔哩收藏.json@哔哩收藏[官]
22
我的哔哩[官]@?render=1&type=url&params=../json/哔哩教育.json@哔哩教育[官]
3+
我的哔哩[官]@?render=1&type=url&params=../json/哔哩少儿.json@哔哩少儿[官]
34
我的哔哩[官]@?render=1&type=url&params=../json/哔哩大全.json@哔哩大全[官]
45
我的哔哩[官]@?render=1&type=url&params=../json/哔哩大杂烩.json@哔哩大杂烩[官]
56
直播转点播[合]@?type=url&params=../json/live2cms.json

controllers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import staticController from './static.js';
12
import docsController from './docs.js';
23
import configController from './config.js';
34
import apiController from './api.js';
@@ -12,6 +13,7 @@ import httpController from './http.js';
1213
import cronTaskerController from './cron-tasker.js';
1314

1415
export const registerRoutes = (fastify, options) => {
16+
fastify.register(staticController, options);
1517
fastify.register(docsController, options);
1618
fastify.register(configController, options);
1719
fastify.register(apiController, options);

controllers/static.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import fastifyStatic from '@fastify/static';
2+
3+
export default (fastify, options, done) => {
4+
// 静态资源
5+
fastify.register(fastifyStatic, {
6+
root: options.publicDir,
7+
prefix: '/public/',
8+
});
9+
10+
fastify.register(fastifyStatic, {
11+
root: options.appsDir,
12+
prefix: '/apps/', // 新的访问路径前缀
13+
decorateReply: false, // 禁用 sendFile
14+
});
15+
16+
fastify.register(fastifyStatic, {
17+
root: options.jsonDir,
18+
prefix: '/json/', // 新的访问路径前缀
19+
decorateReply: false, // 禁用 sendFile
20+
});
21+
22+
fastify.register(fastifyStatic, {
23+
root: options.dr2Dir,
24+
prefix: '/js/', // 新的访问路径前缀
25+
decorateReply: false, // 禁用 sendFile
26+
// setHeaders: (res, path) => {
27+
// res.setHeader('Cache-Control', 'no-store'); // 禁用缓存确保每次获取最新
28+
// }
29+
});
30+
31+
fastify.register(fastifyStatic, {
32+
root: options.pyDir,
33+
prefix: '/py/', // 新的访问路径前缀
34+
decorateReply: false, // 禁用 sendFile
35+
setHeaders: (res, path) => {
36+
// 自定义 .py 文件的 Content-Type
37+
if (path.endsWith('.py')) {
38+
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
39+
}
40+
}
41+
});
42+
43+
fastify.register(fastifyStatic, {
44+
root: options.catDir,
45+
prefix: '/cat/', // 新的访问路径前缀
46+
decorateReply: false, // 禁用 sendFile
47+
});
48+
49+
fastify.register(fastifyStatic, {
50+
root: options.catLibDir,
51+
prefix: '/catLib/', // 新的访问路径前缀
52+
decorateReply: false, // 禁用 sendFile
53+
});
54+
55+
fastify.register(fastifyStatic, {
56+
root: options.xbpqDir,
57+
prefix: '/xbpq/', // 新的访问路径前缀
58+
decorateReply: false, // 禁用 sendFile
59+
});
60+
61+
done();
62+
}

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+
### 20250819
4+
5+
更新至V1.2.15
6+
7+
1. 通过信号监听机制保证linux的pm2管理能正常结束hipy的守护进程
8+
2. 增加哔哩少儿
9+
3. 增加 `风车动漫` cat源
10+
4. 优化 `index.js` 代码结构,静态目录定义移动至 controllers中的 `static.js`
11+
312
### 20250818
413

514
更新至V1.2.14

index.js

Lines changed: 68 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fastifyStatic from '@fastify/static';
21
import * as fastlogger from './controllers/fastlogger.js'
32
import path from 'path';
43
import os from 'os';
@@ -19,61 +18,25 @@ const {fastify} = fastlogger;
1918
const __dirname = path.dirname(fileURLToPath(import.meta.url));
2019
const PORT = 5757;
2120
const MAX_TEXT_SIZE = 0.1 * 1024 * 1024; // 设置最大文本大小为 0.1 MB
21+
// 定义options的目录
22+
const docsDir = path.join(__dirname, 'docs');
23+
const jxDir = path.join(__dirname, 'jx');
24+
const publicDir = path.join(__dirname, 'public');
25+
const appsDir = path.join(__dirname, 'apps');
2226
const jsonDir = path.join(__dirname, 'json');
2327
const jsDir = path.join(__dirname, 'spider/js');
2428
const dr2Dir = path.join(__dirname, 'spider/js_dr2');
2529
const pyDir = path.join(__dirname, 'spider/py');
2630
const catDir = path.join(__dirname, 'spider/catvod');
31+
const catLibDir = path.join(__dirname, 'spider/catLib');
2732
const xbpqDir = path.join(__dirname, 'spider/xbpq');
28-
29-
// 静态资源
30-
fastify.register(fastifyStatic, {
31-
root: path.join(__dirname, 'public'),
32-
prefix: '/public/',
33-
});
34-
35-
fastify.register(fastifyStatic, {
36-
root: path.join(__dirname, 'apps'),
37-
prefix: '/apps/', // 新的访问路径前缀
38-
decorateReply: false, // 禁用 sendFile
39-
});
40-
41-
fastify.register(fastifyStatic, {
42-
root: jsonDir,
43-
prefix: '/json/', // 新的访问路径前缀
44-
decorateReply: false, // 禁用 sendFile
45-
});
46-
47-
fastify.register(fastifyStatic, {
48-
root: dr2Dir,
49-
prefix: '/js/', // 新的访问路径前缀
50-
decorateReply: false, // 禁用 sendFile
51-
// setHeaders: (res, path) => {
52-
// res.setHeader('Cache-Control', 'no-store'); // 禁用缓存确保每次获取最新
53-
// }
54-
});
55-
56-
fastify.register(fastifyStatic, {
57-
root: pyDir,
58-
prefix: '/py/', // 新的访问路径前缀
59-
decorateReply: false, // 禁用 sendFile
60-
setHeaders: (res, path) => {
61-
// 自定义 .py 文件的 Content-Type
62-
if (path.endsWith('.py')) {
63-
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
64-
}
65-
}
66-
});
67-
68-
fastify.register(fastifyStatic, {
69-
root: catDir,
70-
prefix: '/cat/', // 新的访问路径前缀
71-
decorateReply: false, // 禁用 sendFile
72-
});
33+
const viewsDir = path.join(__dirname, 'views');
34+
const configDir = path.join(__dirname, 'config');
7335

7436
// 注册插件以支持 application/x-www-form-urlencoded
7537
fastify.register(formBody);
7638

39+
// 添加钩子事件
7740
fastify.addHook('onReady', async () => {
7841
try {
7942
await daemon.startDaemon();
@@ -124,32 +87,74 @@ fastify.addHook('onRequest', async (req, reply) => {
12487
// 如果需要,可以在这里对 req.query 进行进一步处理
12588
});
12689

90+
process.on('unhandledRejection', (err) => {
91+
fastify.log.error(`未处理的Promise拒绝:${err.message}`);
92+
console.log(`发生了致命的错误,已阻止进程崩溃。${err.stack}`);
93+
// 根据情况决定是否退出进程
94+
// 清理后退出进程(避免程序处于未知状态)
95+
// process.exit(1);
96+
});
97+
98+
// 统一退出处理函数
99+
const handleExit = async (signal) => {
100+
try {
101+
console.log(`\nReceived ${signal}, closing server...`);
102+
// Fastify 提供的关闭方法,内部会触发 onClose 钩子
103+
await fastify.close();
104+
console.log('Fastify closed successfully');
105+
process.exit(0);
106+
} catch (err) {
107+
console.error('Error during shutdown:', err);
108+
process.exit(1);
109+
}
110+
};
111+
112+
// 捕获常见退出信号(Linux 上 pm2 stop 会发 SIGINT 或 SIGTERM)
113+
['SIGINT', 'SIGTERM'].forEach((sig) => {
114+
process.on(sig, () => handleExit(sig));
115+
});
116+
117+
// Windows 上的兼容处理:捕获 Ctrl+C
118+
if (process.platform === 'win32') {
119+
const rl = (await import('readline')).createInterface({
120+
input: process.stdin,
121+
output: process.stdout,
122+
});
123+
124+
rl.on('SIGINT', () => {
125+
handleExit('SIGINT');
126+
});
127+
}
128+
129+
// 捕获 Node.js 主动退出(比如 pm2 stop 也会触发 exit)
130+
process.on('exit', async (code) => {
131+
console.log(`Process exiting with code: ${code}`);
132+
// 这里不能直接用 await fastify.close()(Node 在 exit 里不等异步)
133+
// 但 Fastify 的 SIGINT/SIGTERM 会提前触发,所以这里只记录日志
134+
});
135+
127136
registerRoutes(fastify, {
128137
rootDir: __dirname,
129-
docsDir: path.join(__dirname, 'docs'),
130-
jxDir: path.join(__dirname, 'jx'),
131-
jsonDir: jsonDir,
132-
jsDir: jsDir,
133-
dr2Dir: dr2Dir,
134-
pyDir: pyDir,
135-
catDir: catDir,
136-
xbpqDir: xbpqDir,
137-
viewsDir: path.join(__dirname, 'views'),
138-
configDir: path.join(__dirname, 'config'),
138+
docsDir,
139+
jxDir,
140+
publicDir,
141+
appsDir,
142+
jsonDir,
143+
jsDir,
144+
dr2Dir,
145+
pyDir,
146+
catDir,
147+
catLibDir,
148+
xbpqDir,
139149
PORT,
140150
MAX_TEXT_SIZE,
151+
viewsDir,
152+
configDir,
141153
indexFilePath: path.join(__dirname, 'index.json'),
142154
customFilePath: path.join(__dirname, 'custom.json'),
143155
subFilePath: path.join(__dirname, 'public/sub/sub.json'),
144156
});
145157

146-
process.on('unhandledRejection', (err) => {
147-
fastify.log.error(`未处理的Promise拒绝:${err.message}`);
148-
console.log(`发生了致命的错误,已阻止进程崩溃。${err.stack}`);
149-
// 根据情况决定是否退出进程
150-
// 清理后退出进程(避免程序处于未知状态)
151-
// process.exit(1);
152-
});
153158

154159
// 启动服务
155160
const start = async () => {

json/哔哩少儿.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"classes": [
3+
{
4+
"type_name": "儿童",
5+
"type_id": "3-6岁益智动画合集"
6+
},
7+
{
8+
"type_name": "宝宝巴士",
9+
"type_id": "宝宝巴士动画合集"
10+
},
11+
{
12+
"type_name": "悟空识字",
13+
"type_id": "识字认字动画合集"
14+
},
15+
{
16+
"type_name": "少儿",
17+
"type_id": "CCTV14少儿频道合集"
18+
},
19+
{
20+
"type_name": "学而思",
21+
"type_id": "学而思课程"
22+
},
23+
{
24+
"type_name": "小学",
25+
"type_id": "小学六年辅导课程"
26+
},
27+
{
28+
"type_name": "初中",
29+
"type_id": "初中三年辅导课程"
30+
},
31+
{
32+
"type_name": "高中",
33+
"type_id": "高中三年辅导课程"
34+
},
35+
{
36+
"type_name": "教育",
37+
"type_id": "十二年教育课程"
38+
}
39+
]
40+
}

json/哔哩教育.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,6 @@
293293
{
294294
"type_name": "高中信息技术",
295295
"type_id": "高中信息技术"
296-
},
297-
{
298-
"type_name": "高中信息技术",
299-
"type_id": "高中信息技术"
300296
}
301297
],
302298
"filter": {

libs/catvod.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {getSitesMap} from "../utils/sites-map.js";
44
import {computeHash, deepCopy, getNowTime} from "../utils/utils.js";
55
import {fileURLToPath, pathToFileURL} from 'url';
66
import {md5} from "../libs_drpy/crypto-util.js";
7-
7+
import {fastify} from "../controllers/fastlogger.js";
88
// 缓存已初始化的模块和文件 hash 值
99
const moduleCache = new Map();
1010
const ruleObjectCache = new Map();
@@ -160,8 +160,14 @@ const home = async function (filePath, env, filter = 1) {
160160

161161
const homeVod = async function (filePath, env) {
162162
const moduleObject = await init(filePath, env);
163-
const homeVodResult = json2Object(await moduleObject.homeVod());
164-
return homeVodResult && homeVodResult.list ? homeVodResult.list : homeVodResult;
163+
try {
164+
const homeVodResult = json2Object(await moduleObject.homeVod());
165+
return homeVodResult && homeVodResult.list ? homeVodResult.list : homeVodResult;
166+
} catch (e) {
167+
console.error(e);
168+
// fastify.log.error(e);
169+
return []
170+
}
165171
}
166172

167173

@@ -172,7 +178,8 @@ const category = async function (filePath, env, tid, pg = 1, filter = 1, extend
172178

173179
const detail = async function (filePath, env, ids) {
174180
const moduleObject = await init(filePath, env);
175-
return json2Object(await moduleObject.detail(ids));
181+
const vod_id = Array.isArray(ids) ? ids[0] : ids;
182+
return json2Object(await moduleObject.detail(vod_id));
176183
}
177184

178185

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

0 commit comments

Comments
 (0)