Skip to content

Commit b402d71

Browse files
committed
update:修改一些细节
1 parent 0efbbf4 commit b402d71

19 files changed

+163
-66
lines changed

Diff for: README.md

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

1212
## 更新记录
1313

14-
### 20241211
14+
### 20241212
1515

16-
更新至V1.0.8
16+
更新至V1.0.9
1717

18-
1. 满血版央视大全!!!
18+
1. 尝试修复已知问题
1919

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

Diff for: controllers/decoder.js

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export default (fastify, options, done) => {
1111
if (!code || !auth_code) {
1212
return reply.status(400).send({error: 'Missing required parameters: code and auth_code'});
1313
}
14+
// 检查文本大小
15+
const textSize = Buffer.byteLength(code, 'utf8'); // 获取 UTF-8 编码的字节大小
16+
if (textSize > options.MAX_TEXT_SIZE) {
17+
return reply
18+
.status(400)
19+
.send({error: `Text content exceeds the maximum size of ${options.MAX_TEXT_SIZE / 1024} KB`});
20+
}
21+
1422
const authFilePath = path.join(options.rootDir, '.nomedia');
1523

1624
// 检查文件是否存在

Diff for: controllers/encoder.js

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ export default (fastify, options, done) => {
1010
return reply.status(400).send({error: 'Missing required parameters: code and type'});
1111
}
1212

13+
// 检查文本大小
14+
const textSize = Buffer.byteLength(code, 'utf8'); // 获取 UTF-8 编码的字节大小
15+
if (textSize > options.MAX_TEXT_SIZE) {
16+
return reply
17+
.status(400)
18+
.send({error: `Text content exceeds the maximum size of ${options.MAX_TEXT_SIZE / 1024} KB`});
19+
}
20+
1321
try {
1422
let result;
1523

Diff for: docs/updateRecord.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# drpyS更新记录
22

3+
### 20241212
4+
5+
更新至V1.0.9
6+
7+
1. drpyS加解密工具增加文本大小限制,目前默认为100KB,防止垃圾大数据恶意攻击接口服务
8+
2. 修复央视大全本地代理接口没有动态获取导致可能外网播放地址出现127开头内网地址无法播放的问题
9+
3. 升级axios单文件版到1.7.9
10+
4. 往libsSanbox注入eval函数(非直接注入,仅针对海阔,直接注入会用不了),暂时解决海阔不支持vm里执行eval的问题,但是问题来了,存在作用域问题不要轻易使用,暂时无法解决。(已检测此eval不可以逃逸vm和直接获取drpyS内的变量,勉强能用)
11+
5. 尝试$.require支持网络导入远程js依赖,要求1s内的数据(千万不要导入自己服务的静态文件,会导致阻塞)
12+
313
### 20241211
414

515
更新至V1.0.8

Diff for: index.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {fastify, fileLogger} = fastlogger;
99
// 获取当前路径
1010
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1111
const PORT = 5757;
12+
const MAX_TEXT_SIZE = 100 * 1024; // 设置最大文本大小为 100 KB
1213

1314
// 静态资源
1415
fastify.register(fastifyStatic, {
@@ -25,6 +26,7 @@ registerRoutes(fastify, {
2526
jsDir: path.join(__dirname, 'js'),
2627
viewsDir: path.join(__dirname, 'views'),
2728
PORT,
29+
MAX_TEXT_SIZE,
2830
indexFilePath: path.join(__dirname, 'index.json'),
2931
customFilePath: path.join(__dirname, 'custom.json'),
3032
});

Diff for: js/_fq2.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// http://localhost:5757/api/番茄小说[书]?ac=list&t=主分类&pg=1
2-
32
const {getRandomFromList} = $.require('./_lib.random.js');
43

54
function testHls() {
@@ -45,7 +44,6 @@ var rule = {
4544
log('oheaders:', oheaders)
4645
log('rule_fetch_params:', rule_fetch_params)
4746
log('type of batchFetch:', batchFetch)
48-
4947
testHls()
5048
// return {}
5149
},

Diff for: js/_fq3.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const {getIp} = $.require('http://127.0.0.1:5757/public/ip.js');
2+
3+
var rule = {
4+
类型: '小说',
5+
title: '番茄小说[书]',
6+
desc: '番茄小说纯js版本',
7+
host: 'https://fanqienovel.com/',
8+
homeUrl: 'https://fanqienovel.com/api/author/book/category_list/v0/',
9+
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',
10+
class_parse: async () => {
11+
log('ip:', getIp());
12+
},
13+
headers: {
14+
'User-Agent': 'PC_UA',
15+
},
16+
预处理: async () => {
17+
},
18+
一级: async function (tid, pg, filter, extend) {
19+
},
20+
二级: async function () {
21+
return '这是二级:' + rule.title
22+
},
23+
搜索: async function () {
24+
return '这是搜索:' + rule.title
25+
},
26+
lazy: async function () {
27+
return template.getMubans()
28+
},
29+
};

Diff for: js/_lib.request.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// import axios from '../libs_drpy/axios.min.js';
2-
31
async function requestHtml(url, options) {
42
try {
53
let html = (await req(url, options)).content;

Diff for: js/央视大全[官].js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: libs/drpyS.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ export async function init(filePath, env, refresh) {
214214
// 创建一个沙箱上下文,注入需要的全局变量和函数
215215
const sandbox = {
216216
console, // 将 console 注入沙箱,便于调试
217+
// eval, // 直接引入原生 eval(不要这样用,环境是隔离的会导致执行不符合预期,需要包装)
218+
WebAssembly, // 允许使用原生 WebAssembly(这里即使不引用也可以在沙箱里用这个变量。写在这里骗骗自己吧)
217219
setTimeout, // 注入定时器方法
218220
setInterval,
219221
clearTimeout,
@@ -226,7 +228,11 @@ export async function init(filePath, env, refresh) {
226228
...drpyCustomSanbox,
227229
...libsSanbox,
228230
};
229-
231+
if (typeof fetchByHiker !== 'undefined'){ // 临时解决海阔不支持eval问题,但是这个eval存在作用域问题,跟非海阔环境的有很大区别,属于残废版本
232+
sandbox.eval = function (code) {
233+
return vm.runInContext(code, sandbox);
234+
};
235+
}
230236
// 创建一个上下文
231237
const context = vm.createContext(sandbox);
232238

Diff for: libs_drpy/axios.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: libs_drpy/drpyBatchFetch.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import PQueue from 'p-queue';
22
import Queue from 'queue';
3-
import axios from './axios.min.js';
3+
// import axios from './axios.min.js';
4+
import './axios.min.js';
45

56
export const batchFetch1 = async (items, maxWorkers = 5, timeoutConfig = 5000) => {
67
let t1 = (new Date()).getTime();

Diff for: libs_drpy/drpyInject.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// import axios, {toFormData} from 'axios';
2-
import axios, {toFormData} from './axios.min.js';
2+
// import axios, {toFormData} from './axios.min.js';
3+
import './axios.min.js';
34

5+
const {toFormData} = axios;
6+
// console.log('type of toFormData:', typeof toFormData);
47
import crypto from 'crypto';
58
import https from 'https';
69
import fs from 'node:fs';

Diff for: libs_drpy/hikerBatchFetch.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import DsQueue from './dsQueue.js';
22
import fastq from "fastq";
3-
import axios from './axios.min.js';
3+
// import axios from './axios.min.js';
4+
import './axios.min.js';
45

56
export const batchFetch3 = async (items, maxWorkers = 5, timeoutConfig = 5000) => {
67
let t1 = (new Date()).getTime();

Diff for: libs_drpy/moduleLoader.js

+11-51
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,27 @@
11
import {readFileSync, existsSync} from 'fs';
22
import path from "path";
33
import {fileURLToPath} from "url";
4-
import axios from "./axios.min.js"; // 引入 axios
4+
// import axios from "./axios.min.js"; // 引入 axios
5+
import "./axios.min.js"; // 引入 axios
56
// import deasync from "deasync"; // 使用 deasync 实现同步行为
7+
import fetchSync from 'sync-fetch'
68

79
const __dirname = path.dirname(fileURLToPath(import.meta.url));
810

911
// 创建一个函数,接受一个回调来模拟同步行为
1012
function fetchModuleCodeSync(jsm_path) {
11-
let result = null;
12-
let error = null;
13-
14-
// 返回一个 Promise,用于等待异步请求完成
15-
return new Promise((resolve, reject) => {
16-
axios.get(jsm_path)
17-
.then((response) => {
18-
result = response.data; // 保存结果
19-
resolve(result); // 成功时 resolve
20-
})
21-
.catch((err) => {
22-
error = new Error(`Error fetching module from URL: ${err.message}`); // 错误信息
23-
reject(error); // 失败时 reject
24-
});
13+
const res = fetchSync(jsm_path, {
14+
headers: {
15+
'user-agent': 'Mozilla/5.0',
16+
},
17+
timeout: 1000,
2518
});
19+
return res.text();
2620
}
2721

2822
// 模拟同步的处理方法
2923
function requireModule(jsm_path) {
30-
let result = null;
31-
let error = null;
32-
33-
// 阻塞直到 Promise 完成
34-
try {
35-
result = fetchModuleCodeSync(jsm_path); // 等待异步请求完成
36-
result.then(data => {
37-
console.log("Module Code:", data);
38-
}).catch(err => {
39-
throw err;
40-
});
41-
} catch (err) {
42-
error = err;
43-
console.error(error.message);
44-
}
45-
46-
return result; // 返回模块内容
24+
return fetchModuleCodeSync(jsm_path)
4725
}
4826

4927
globalThis.$ = {
@@ -61,25 +39,6 @@ globalThis.$ = {
6139

6240
if (isURL) {
6341
// 从网络同步获取模块代码
64-
/*
65-
let error = null;
66-
let result = null;
67-
68-
axios.get(jsm_path)
69-
.then((response) => {
70-
result = response.data;
71-
})
72-
.catch((err) => {
73-
error = new Error(`Error fetching module from URL: ${err.message}`);
74-
});
75-
76-
// 等待 Promise 解决
77-
deasync.loopWhile(() => !result && !error);
78-
79-
if (error) throw error;
80-
81-
js_code = result;
82-
*/
8342
js_code = requireModule(jsm_path);
8443
} else {
8544
// 本地路径处理
@@ -99,6 +58,7 @@ globalThis.$ = {
9958
// 读取文件内容
10059
js_code = readFileSync(jsm_path, 'utf8');
10160
}
61+
console.log('js_code:', js_code)
10262

10363
// 创建沙箱环境
10464
const sandbox = {

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drpy-node",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"main": "index.js",
55
"type": "module",
66
"scripts": {
@@ -21,6 +21,7 @@
2121
"qs": "^6.13.1",
2222
"queue": "^7.0.0",
2323
"rotating-file-stream": "^3.2.5",
24+
"sync-fetch": "^0.6.0-2",
2425
"tunnel": "^0.0.6"
2526
}
2627
}

Diff for: public/ip.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
async function getIp() {
2+
let ip_obj = (await req('http://httpbin.org/ip')).content.parseX.get();
3+
return ip_obj.origin
4+
}
5+
6+
$.exports = {
7+
getIp
8+
}

Diff for: views/encoder.html

+12-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,18 @@ <h2>drpyS源加解密工具</h2>
170170
}
171171
},
172172
error: function (xhr, status, error) {
173-
alert('请求失败,请稍后再试。');
173+
// 获取返回的 body
174+
const responseBody = xhr.responseText;
175+
console.error('Response body:', responseBody);
176+
// 可选:如果返回的是 JSON,解析它
177+
try {
178+
const jsonResponse = JSON.parse(responseBody);
179+
console.error('Parsed response:', jsonResponse);
180+
alert('请求失败,请稍后再试。' + jsonResponse.error);
181+
} catch (e) {
182+
console.error('Failed to parse response as JSON');
183+
alert('请求失败,请稍后再试。' + error);
184+
}
174185
}
175186
});
176187
});

0 commit comments

Comments
 (0)