Skip to content

Commit eca0619

Browse files
committed
update:更新版本号,优化了一堆细节问题。支持action
1 parent 2922ddf commit eca0619

27 files changed

+2002
-1283
lines changed

Diff for: README.md

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

1414
## 更新记录
1515

16-
### 20241224
16+
### 20241225
1717

18-
更新至V1.0.20
18+
更新至V1.0.21
1919

20-
1. 更新了一些框架细节
20+
1. 接口升级,支持更多协议调用
21+
2. 增加 `action`动作交互功能
22+
3. uc 和 夸克自动更新cookie
2123

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

Diff for: controllers/api.js

+89-73
Original file line numberDiff line numberDiff line change
@@ -5,89 +5,105 @@ import * as drpy from '../libs/drpyS.js';
55

66
export default (fastify, options, done) => {
77
// 动态加载模块并根据 query 执行不同逻辑
8-
fastify.get('/api/:module', async (request, reply) => {
9-
const moduleName = request.params.module;
10-
const query = request.query; // 获取 query 参数
11-
const modulePath = path.join(options.jsDir, `${moduleName}.js`);
12-
if (!existsSync(modulePath)) {
13-
reply.status(404).send({error: `Module ${moduleName} not found`});
14-
return;
15-
}
16-
const protocol = request.protocol;
17-
const hostname = request.hostname;
18-
const proxyUrl = `${protocol}://${hostname}${request.url}`.split('?')[0].replace('/api/', '/proxy/') + '/?do=js';
19-
// console.log(`proxyUrl:${proxyUrl}`);
20-
const env = {
21-
proxyUrl, getProxyUrl: function () {
22-
return proxyUrl
23-
}
24-
};
25-
const pg = Number(query.pg) || 1;
26-
try {
27-
// 根据 query 参数决定执行逻辑
28-
if ('play' in query) {
29-
// 处理播放逻辑
30-
const result = await drpy.play(modulePath, env, query.flag, query.play);
31-
return reply.send(result);
8+
fastify.route({
9+
method: ['GET', 'POST'], // 同时支持 GET 和 POST
10+
url: '/api/:module',
11+
schema: {
12+
consumes: ['application/json', 'application/x-www-form-urlencoded'], // 声明支持的内容类型
13+
},
14+
handler: async (request, reply) => {
15+
const moduleName = request.params.module;
16+
const modulePath = path.join(options.jsDir, `${moduleName}.js`);
17+
if (!existsSync(modulePath)) {
18+
reply.status(404).send({error: `Module ${moduleName} not found`});
19+
return;
3220
}
21+
// 根据请求方法选择参数来源
22+
const query = request.method === 'GET' ? request.query : request.body;
23+
const protocol = request.protocol;
24+
const hostname = request.hostname;
25+
const proxyUrl = `${protocol}://${hostname}${request.url}`.split('?')[0].replace('/api/', '/proxy/') + '/?do=js';
26+
const publicUrl = `${protocol}://${hostname}/public/`;
27+
// console.log(`proxyUrl:${proxyUrl}`);
28+
const env = {
29+
proxyUrl, publicUrl, getProxyUrl: function () {
30+
return proxyUrl
31+
}
32+
};
33+
const pg = Number(query.pg) || 1;
34+
try {
35+
// 根据 query 参数决定执行逻辑
36+
if ('play' in query) {
37+
// 处理播放逻辑
38+
const result = await drpy.play(modulePath, env, query.flag, query.play);
39+
return reply.send(result);
40+
}
3341

34-
if ('ac' in query && 't' in query) {
35-
let ext = query.ext;
36-
// console.log('ext:', ext);
37-
let extend = {};
38-
if (ext) {
39-
try {
40-
extend = JSON.parse(base64Decode(ext))
41-
} catch (e) {
42-
fastify.log.error(`筛选参数错误:${e.message}`);
42+
if ('ac' in query && 't' in query) {
43+
let ext = query.ext;
44+
// console.log('ext:', ext);
45+
let extend = {};
46+
if (ext) {
47+
try {
48+
extend = JSON.parse(base64Decode(ext))
49+
} catch (e) {
50+
fastify.log.error(`筛选参数错误:${e.message}`);
51+
}
4352
}
53+
// 分类逻辑
54+
const result = await drpy.cate(modulePath, env, query.t, pg, 1, extend);
55+
return reply.send(result);
4456
}
45-
// 分类逻辑
46-
const result = await drpy.cate(modulePath, env, query.t, pg, 1, extend);
47-
return reply.send(result);
48-
}
4957

50-
if ('ac' in query && 'ids' in query) {
51-
// 详情逻辑
52-
const result = await drpy.detail(modulePath, env, query.ids.split(','));
53-
return reply.send(result);
54-
}
58+
if ('ac' in query && 'ids' in query) {
59+
// 详情逻辑
60+
const result = await drpy.detail(modulePath, env, query.ids.split(','));
61+
return reply.send(result);
62+
}
5563

56-
if ('wd' in query) {
57-
// 搜索逻辑
58-
const quick = 'quick' in query ? query.quick : 0;
59-
const result = await drpy.search(modulePath, env, query.wd, quick, pg);
60-
return reply.send(result);
61-
}
64+
if ('ac' in query && 'action' in query) {
65+
// 处理动作逻辑
66+
const result = await drpy.action(modulePath, env, query.action, query.value);
67+
return reply.send(result);
68+
}
6269

63-
if ('refresh' in query) {
64-
// 强制刷新初始化逻辑
65-
const refreshedObject = await drpy.init(modulePath, env, true);
66-
return reply.send(refreshedObject);
67-
}
68-
if (!('filter' in query)) {
69-
query.filter = 1
70-
}
71-
// 默认逻辑,返回 home + homeVod 接口
72-
const filter = 'filter' in query ? query.filter : 1;
73-
const resultHome = await drpy.home(modulePath, env, filter);
74-
const resultHomeVod = await drpy.homeVod(modulePath, env);
75-
let result = {
76-
...resultHome,
77-
// list: resultHomeVod,
78-
};
79-
if (Array.isArray(resultHomeVod) && resultHomeVod.length > 0) {
80-
Object.assign(result, {list: resultHomeVod})
81-
}
8270

83-
reply.send(result);
71+
if ('wd' in query) {
72+
// 搜索逻辑
73+
const quick = 'quick' in query ? query.quick : 0;
74+
const result = await drpy.search(modulePath, env, query.wd, quick, pg);
75+
return reply.send(result);
76+
}
8477

85-
} catch (error) {
86-
// console.log('Error processing request:', error);
87-
// reply.status(500).send({error: `Failed to process request for module ${moduleName}: ${error.message}`});
78+
if ('refresh' in query) {
79+
// 强制刷新初始化逻辑
80+
const refreshedObject = await drpy.init(modulePath, env, true);
81+
return reply.send(refreshedObject);
82+
}
83+
if (!('filter' in query)) {
84+
query.filter = 1
85+
}
86+
// 默认逻辑,返回 home + homeVod 接口
87+
const filter = 'filter' in query ? query.filter : 1;
88+
const resultHome = await drpy.home(modulePath, env, filter);
89+
const resultHomeVod = await drpy.homeVod(modulePath, env);
90+
let result = {
91+
...resultHome,
92+
// list: resultHomeVod,
93+
};
94+
if (Array.isArray(resultHomeVod) && resultHomeVod.length > 0) {
95+
Object.assign(result, {list: resultHomeVod})
96+
}
97+
98+
reply.send(result);
8899

89-
fastify.log.error(`Error api module ${moduleName}:${error.message}`);
90-
reply.status(500).send({error: `Failed to process module ${moduleName}: ${error.message}`});
100+
} catch (error) {
101+
// console.log('Error processing request:', error);
102+
// reply.status(500).send({error: `Failed to process request for module ${moduleName}: ${error.message}`});
103+
104+
fastify.log.error(`Error api module ${moduleName}:${error.message}`);
105+
reply.status(500).send({error: `Failed to process module ${moduleName}: ${error.message}`});
106+
}
91107
}
92108
});
93109

Diff for: controllers/config.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {readdirSync, readFileSync, writeFileSync, existsSync} from 'fs';
22
import path from 'path';
33
import * as drpy from '../libs/drpyS.js';
44
import {naturalSort, urljoin} from '../utils/utils.js'
5+
import {ENV} from "../utils/env.js";
56

67
// 工具函数:生成 JSON 数据
78
async function generateSiteJSON(jsDir, requestHost, sub, subFilePath) {
@@ -27,6 +28,10 @@ async function generateSiteJSON(jsDir, requestHost, sub, subFilePath) {
2728
}
2829
}
2930
let sites = [];
31+
// console.log('hide_adult:', ENV.get('hide_adult'));
32+
if (ENV.get('hide_adult') === '1') {
33+
valid_files = valid_files.filter(it => !(new RegExp('\\[[密]\\]|密+')).test(it));
34+
}
3035
for (const file of valid_files) {
3136
const baseName = path.basename(file, '.js'); // 去掉文件扩展名
3237
const key = `drpyS_${baseName}`;

0 commit comments

Comments
 (0)