Skip to content

Commit d44fba5

Browse files
committed
update:新增订阅机制
1 parent 5bb6e42 commit d44fba5

15 files changed

+455
-120
lines changed

Diff for: README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ nodejs作为服务端的drpy实现。全面升级异步写法
44

55
* [本地配置接口-动态本地](/config)
66
* [本地配置接口-动态外网/局域网](/config/1)
7-
* [本地配置接口-静态](/index)
7+
* [其他配置接口-订阅过滤](/docs/sub.md)
88
* [代码加解密工具](/admin/encoder)
99
* [V我50支付凭证生成器](/authcoder?len=10&number=1)
1010
* [接口压测教程](/docs/httpTest.md)
@@ -13,12 +13,14 @@ nodejs作为服务端的drpy实现。全面升级异步写法
1313

1414
## 更新记录
1515

16-
### 20241218
16+
### 20241219
1717

18-
更新至V1.0.14
18+
更新至V1.0.15
1919

20-
1. 增加源
21-
2. 优化vercel部署兼容性
20+
1. 增加导出函数
21+
2. 新增源
22+
3. 新增订阅码过滤源机制,类似hipy
23+
4. 太冷了写不动,就这样吧
2224

2325
[点此查看完整更新记录](docs/updateRecord.md)
2426

Diff for: controllers/config.js

+36-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@ import path from 'path';
33
import * as drpy from '../libs/drpyS.js';
44

55
// 工具函数:生成 JSON 数据
6-
async function generateSiteJSON(jsDir, requestHost) {
6+
async function generateSiteJSON(jsDir, requestHost, sub) {
77
const files = readdirSync(jsDir);
8-
const valid_files = files.filter((file) => file.endsWith('.js') && !file.startsWith('_')); // 筛选出不是 "_" 开头的 .js 文件
8+
let valid_files = files.filter((file) => file.endsWith('.js') && !file.startsWith('_')); // 筛选出不是 "_" 开头的 .js 文件
9+
if (sub) {
10+
if (sub.mode === 0) {
11+
valid_files = valid_files.filter(it => (new RegExp(sub.reg || '.*')).test(it));
12+
} else if (sub.mode === 1) {
13+
valid_files = valid_files.filter(it => !(new RegExp(sub.reg || '.*')).test(it));
14+
}
15+
}
916
let sites = [];
1017
for (const file of valid_files) {
1118
const baseName = path.basename(file, '.js'); // 去掉文件扩展名
@@ -81,6 +88,17 @@ function generateParseJSON(jxDir, requestHost) {
8188
return {parses};
8289
}
8390

91+
function getSubs(subFilePath) {
92+
let subs = [];
93+
try {
94+
const subContent = readFileSync(subFilePath);
95+
subs = JSON.parse(subContent)
96+
} catch (e) {
97+
log(`读取订阅失败:${e.message}`);
98+
}
99+
return subs
100+
}
101+
84102
export default (fastify, options, done) => {
85103

86104
fastify.get('/index', async (request, reply) => {
@@ -96,18 +114,30 @@ export default (fastify, options, done) => {
96114
// 接口:返回配置 JSON,同时写入 index.json
97115
fastify.get('/config*', async (request, reply) => {
98116
let t1 = (new Date()).getTime();
117+
const query = request.query; // 获取 query 参数
118+
const sub_code = query.sub || '';
99119
const cfg_path = request.params['*']; // 捕获整个路径
100-
console.log(cfg_path);
101120
try {
102121
// 获取主机名,协议及端口
103122
const protocol = request.headers['x-forwarded-proto'] || (request.socket.encrypted ? 'https' : 'http'); // http 或 https
104123
const hostname = request.hostname; // 主机名,不包含端口
105124
const port = request.socket.localPort; // 获取当前服务的端口
106-
console.log('port:', port);
125+
console.log(`cfg_path:${cfg_path},port:${port}`);
107126
let requestHost = cfg_path === '/1' ? `${protocol}://${hostname}` : `http://127.0.0.1:${options.PORT}`; // 动态生成根地址
108-
const siteJSON = await generateSiteJSON(options.jsDir, requestHost);
127+
let sub = null;
128+
if (sub_code) {
129+
let subs = getSubs(options.subFilePath);
130+
sub = subs.find(it => it.code === sub_code);
131+
console.log('sub:', sub);
132+
if (sub && sub.status === 0) {
133+
return reply.status(500).send({error: `此订阅码:【${sub_code}】已禁用`});
134+
}
135+
}
136+
137+
const siteJSON = await generateSiteJSON(options.jsDir, requestHost, sub);
109138
const parseJSON = generateParseJSON(options.jxDir, requestHost);
110-
const configObj = {...siteJSON, ...parseJSON};
139+
const configObj = {sites_count: siteJSON.sites.length, ...siteJSON, ...parseJSON};
140+
// console.log(configObj);
111141
const configStr = JSON.stringify(configObj, null, 2);
112142
if (!process.env.VERCEL) { // Vercel 环境不支持写文件,关闭此功能
113143
writeFileSync(options.indexFilePath, configStr, 'utf8'); // 写入 index.json

Diff for: controllers/docs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default (fastify, options, done) => {
3737
<head>
3838
<meta charset="UTF-8">
3939
<meta name="viewport" content="width=device-width, initial-scale=1.0">
40-
<title>${fullPath}</title>
40+
<title>drpyS-${fullPath}</title>
4141
<style>
4242
body { font-family: Arial, sans-serif; line-height: 1.6; margin: 20px; padding: 0; }
4343
h1, h2, h3 { color: #333; }

Diff for: controllers/root.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default (fastify, options, done) => {
3838
<head>
3939
<meta charset="UTF-8">
4040
<meta name="viewport" content="width=device-width, initial-scale=1.0">
41-
<title>README</title>
41+
<title>drpyS-README</title>
4242
</head>
4343
<body>
4444
${htmlContent}

Diff for: custom.json

+11-50
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"sites_count": 19,
23
"sites": [
34
{
45
"key": "drpyS_ikanbot",
@@ -30,16 +31,6 @@
3031
"quickSearch": 0,
3132
"ext": ""
3233
},
33-
{
34-
"key": "drpyS_xvideos[密]",
35-
"name": "xvideos[密](DS)",
36-
"type": 4,
37-
"api": "http://localhost:5757/api/xvideos[密]",
38-
"searchable": 1,
39-
"filterable": 1,
40-
"quickSearch": 0,
41-
"ext": ""
42-
},
4334
{
4435
"key": "drpyS_人人视频",
4536
"name": "人人视频(DS)",
@@ -120,6 +111,16 @@
120111
"quickSearch": 0,
121112
"ext": ""
122113
},
114+
{
115+
"key": "drpyS_番薯动漫",
116+
"name": "番薯动漫(DS)",
117+
"type": 4,
118+
"api": "http://localhost:5757/api/番薯动漫",
119+
"searchable": 2,
120+
"filterable": 1,
121+
"quickSearch": 0,
122+
"ext": ""
123+
},
123124
{
124125
"key": "drpyS_素白白",
125126
"name": "素白白(DS)",
@@ -150,36 +151,6 @@
150151
"quickSearch": 0,
151152
"ext": ""
152153
},
153-
{
154-
"key": "drpyS_色花堂[密+]",
155-
"name": "色花堂[密+](DS)",
156-
"type": 4,
157-
"api": "http://localhost:5757/api/色花堂[密+]",
158-
"searchable": 2,
159-
"filterable": 1,
160-
"quickSearch": 0,
161-
"ext": ""
162-
},
163-
{
164-
"key": "drpyS_色花堂[密]",
165-
"name": "色花堂[密](DS)",
166-
"type": 4,
167-
"api": "http://localhost:5757/api/色花堂[密]",
168-
"searchable": 2,
169-
"filterable": 1,
170-
"quickSearch": 0,
171-
"ext": ""
172-
},
173-
{
174-
"key": "drpyS_草榴社区[密]",
175-
"name": "草榴社区[密](DS)",
176-
"type": 4,
177-
"api": "http://localhost:5757/api/草榴社区[密]",
178-
"searchable": 2,
179-
"filterable": 1,
180-
"quickSearch": 0,
181-
"ext": ""
182-
},
183154
{
184155
"key": "drpyS_荐片",
185156
"name": "荐片(DS)",
@@ -219,16 +190,6 @@
219190
"filterable": 1,
220191
"quickSearch": 0,
221192
"ext": ""
222-
},
223-
{
224-
"key": "drpyS_黑料不打烊[密]",
225-
"name": "黑料不打烊[密](DS)",
226-
"type": 4,
227-
"api": "http://localhost:5757/api/黑料不打烊[密]",
228-
"searchable": 1,
229-
"filterable": 0,
230-
"quickSearch": 0,
231-
"ext": ""
232193
}
233194
],
234195
"parses": [

Diff for: docs/sub.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* [本地配置接口-静态](/index)
2+
* [远程订阅接口-绿色](/config/1?sub=green)
3+
* [电视订阅接口-仅多媒体源](/config/1?sub=tv)

Diff for: docs/updateRecord.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
# drpyS更新记录
2+
### 20241219
3+
4+
更新至V1.0.15
5+
6+
1. drpyS源增加可使用的函数`Buffer` `URLSearchParams`
7+
2. 所有html页面头部加入drpyS-前缀
8+
3. 新增番薯源
9+
4. 新增几个订阅码
210

311
### 20241218
412

Diff for: index.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ registerRoutes(fastify, {
3636
MAX_TEXT_SIZE,
3737
indexFilePath: path.join(__dirname, 'index.json'),
3838
customFilePath: path.join(__dirname, 'custom.json'),
39+
subFilePath: path.join(__dirname, 'sub.json'),
3940
});
4041

4142
// 启动服务

Diff for: index.json

+11-50
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"sites_count": 19,
23
"sites": [
34
{
45
"key": "drpyS_ikanbot",
@@ -30,16 +31,6 @@
3031
"quickSearch": 0,
3132
"ext": ""
3233
},
33-
{
34-
"key": "drpyS_xvideos[密]",
35-
"name": "xvideos[密](DS)",
36-
"type": 4,
37-
"api": "http://localhost:5757/api/xvideos[密]",
38-
"searchable": 1,
39-
"filterable": 1,
40-
"quickSearch": 0,
41-
"ext": ""
42-
},
4334
{
4435
"key": "drpyS_人人视频",
4536
"name": "人人视频(DS)",
@@ -120,6 +111,16 @@
120111
"quickSearch": 0,
121112
"ext": ""
122113
},
114+
{
115+
"key": "drpyS_番薯动漫",
116+
"name": "番薯动漫(DS)",
117+
"type": 4,
118+
"api": "http://localhost:5757/api/番薯动漫",
119+
"searchable": 2,
120+
"filterable": 1,
121+
"quickSearch": 0,
122+
"ext": ""
123+
},
123124
{
124125
"key": "drpyS_素白白",
125126
"name": "素白白(DS)",
@@ -150,36 +151,6 @@
150151
"quickSearch": 0,
151152
"ext": ""
152153
},
153-
{
154-
"key": "drpyS_色花堂[密+]",
155-
"name": "色花堂[密+](DS)",
156-
"type": 4,
157-
"api": "http://localhost:5757/api/色花堂[密+]",
158-
"searchable": 2,
159-
"filterable": 1,
160-
"quickSearch": 0,
161-
"ext": ""
162-
},
163-
{
164-
"key": "drpyS_色花堂[密]",
165-
"name": "色花堂[密](DS)",
166-
"type": 4,
167-
"api": "http://localhost:5757/api/色花堂[密]",
168-
"searchable": 2,
169-
"filterable": 1,
170-
"quickSearch": 0,
171-
"ext": ""
172-
},
173-
{
174-
"key": "drpyS_草榴社区[密]",
175-
"name": "草榴社区[密](DS)",
176-
"type": 4,
177-
"api": "http://localhost:5757/api/草榴社区[密]",
178-
"searchable": 2,
179-
"filterable": 1,
180-
"quickSearch": 0,
181-
"ext": ""
182-
},
183154
{
184155
"key": "drpyS_荐片",
185156
"name": "荐片(DS)",
@@ -219,16 +190,6 @@
219190
"filterable": 1,
220191
"quickSearch": 0,
221192
"ext": ""
222-
},
223-
{
224-
"key": "drpyS_黑料不打烊[密]",
225-
"name": "黑料不打烊[密](DS)",
226-
"type": 4,
227-
"api": "http://localhost:5757/api/黑料不打烊[密]",
228-
"searchable": 1,
229-
"filterable": 0,
230-
"quickSearch": 0,
231-
"ext": ""
232193
}
233194
],
234195
"parses": [

Diff for: js/_fq3.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const rule = {
88
homeUrl: 'https://fanqienovel.com/api/author/book/category_list/v0/',
99
url: '/api/author/library/book_list/v0/?page_count=18&page_index=(fypage-1)&gender=-1&category_id=fyclass&creation_status=-1&word_count=-1&sort=0#fyfilter',
1010
class_parse: async () => {
11+
log('Buffer:',typeof Buffer)
12+
log('URLSearchParams:',typeof URLSearchParams)
1113
log('ip:', await getIp());
1214
log(qs.stringify({a: 1, b: 2}))
1315
},

0 commit comments

Comments
 (0)