Skip to content

Commit c53fbc6

Browse files
committed
update:支持传参源
1 parent e75bb85 commit c53fbc6

24 files changed

+34564
-40
lines changed

Diff for: README.md

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

1717
## 更新记录
1818

19-
### 20250102
19+
### 20250103
2020

21-
更新至V1.0.29
21+
更新至V1.0.30
2222

23-
1. 增加 `七猫小说.js`
24-
1. 支持传参源 `我的哔哩.js`
23+
1. 增加 `抖音` `直转点`
2524

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

Diff for: config/map.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
我的哔哩[官]@?render=1&type=url&params=../json/哔哩教育.json@哔哩教育[官]
22
我的哔哩[官]@?render=1&type=url&params=../json/哔哩大全.json@哔哩大全[官]
3+
直播转点播[合]@?type=url&params=../json/live2cms.json

Diff for: controllers/api.js

+42-11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export default (fastify, options, done) => {
3535
const jsonUrl = `${protocol}://${hostname}/json/`;
3636
const httpUrl = `${protocol}://${hostname}/http`;
3737
const mediaProxyUrl = `${protocol}://${hostname}/mediaProxy`;
38+
const hostUrl = `${hostname.split(':')[0]}`;
39+
const fServer = fastify.server;
3840

3941
// console.log(`proxyUrl:${proxyUrl}`);
4042
function getEnv(moduleName) {
@@ -43,7 +45,7 @@ export default (fastify, options, done) => {
4345
return proxyUrl
4446
};
4547
return {
46-
proxyUrl, publicUrl, jsonUrl, httpUrl, mediaProxyUrl, getProxyUrl, ext: moduleExt
48+
proxyUrl, publicUrl, jsonUrl, httpUrl, mediaProxyUrl, hostUrl, fServer, getProxyUrl, ext: moduleExt
4749
}
4850
}
4951

@@ -185,15 +187,29 @@ export default (fastify, options, done) => {
185187
const proxyPath = request.params['*']; // 捕获整个路径
186188
fastify.log.info(`try proxy for ${moduleName} -> ${proxyPath}: ${JSON.stringify(query)}`);
187189
const rangeHeader = request.headers.range; // 获取客户端的 Range 请求头
190+
191+
const moduleExt = query.extend || '';
188192
const protocol = request.protocol;
189193
const hostname = request.hostname;
190-
const proxyUrl = `${protocol}://${hostname}${request.url}`.split('?')[0].replace(proxyPath, '') + '?do=js';
191-
// console.log(`proxyUrl:${proxyUrl}`);
192-
const env = {
193-
proxyUrl, proxyPath, getProxyUrl: function () {
194+
195+
const publicUrl = `${protocol}://${hostname}/public/`;
196+
const jsonUrl = `${protocol}://${hostname}/json/`;
197+
const httpUrl = `${protocol}://${hostname}/http`;
198+
const mediaProxyUrl = `${protocol}://${hostname}/mediaProxy`;
199+
const hostUrl = `${hostname.split(':')[0]}`;
200+
const fServer = fastify.server;
201+
202+
function getEnv(moduleName) {
203+
const proxyUrl = `${protocol}://${hostname}/proxy/${moduleName}/?do=js`;
204+
const getProxyUrl = function () {
194205
return proxyUrl
195-
},
196-
};
206+
};
207+
return {
208+
proxyUrl, publicUrl, jsonUrl, httpUrl, mediaProxyUrl, hostUrl, fServer, getProxyUrl, ext: moduleExt
209+
}
210+
}
211+
212+
const env = getEnv(moduleName);
197213
try {
198214
const backRespList = await drpy.proxy(modulePath, env, query);
199215
const statusCode = backRespList[0];
@@ -267,14 +283,29 @@ export default (fastify, options, done) => {
267283
if (!existsSync(jxPath)) {
268284
return reply.status(404).send({error: `解析 ${jxName} not found`});
269285
}
286+
const moduleExt = query.extend || '';
270287
const protocol = request.protocol;
271288
const hostname = request.hostname;
272-
const proxyUrl = `${protocol}://${hostname}${request.url}`.split('?')[0].replace('/parse/', '/proxy/') + '/?do=js';
273-
const env = {
274-
proxyUrl, getProxyUrl: function () {
289+
290+
const publicUrl = `${protocol}://${hostname}/public/`;
291+
const jsonUrl = `${protocol}://${hostname}/json/`;
292+
const httpUrl = `${protocol}://${hostname}/http`;
293+
const mediaProxyUrl = `${protocol}://${hostname}/mediaProxy`;
294+
const hostUrl = `${hostname.split(':')[0]}`;
295+
const fServer = fastify.server;
296+
297+
function getEnv(moduleName) {
298+
// const proxyUrl = `${protocol}://${hostname}/proxy/${moduleName}/?do=js`;
299+
const proxyUrl = `${protocol}://${hostname}${request.url}`.split('?')[0].replace('/parse/', '/proxy/') + '/?do=js';
300+
const getProxyUrl = function () {
275301
return proxyUrl
302+
};
303+
return {
304+
proxyUrl, publicUrl, jsonUrl, httpUrl, mediaProxyUrl, hostUrl, getProxyUrl, fServer, ext: moduleExt
276305
}
277-
};
306+
}
307+
308+
const env = getEnv('');
278309
try {
279310
const backResp = await drpy.jx(jxPath, env, query);
280311
const statusCode = 200;

Diff for: controllers/config.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {ENV} from "../utils/env.js";
66
import {validatePwd} from "../utils/api_validate.js";
77
import {getSitesMap} from "../utils/sites-map.js";
88

9+
const {jsEncoder} = drpy;
10+
911
// 工具函数:生成 JSON 数据
1012
async function generateSiteJSON(jsDir, configDir, requestHost, sub, subFilePath, pwd) {
1113
const files = readdirSync(jsDir);
@@ -42,7 +44,8 @@ async function generateSiteJSON(jsDir, configDir, requestHost, sub, subFilePath,
4244
}
4345
let SitesMap = getSitesMap(configDir);
4446
// console.log(SitesMap);
45-
for (const file of valid_files) {
47+
// 使用 Promise.all 并发执行文件的处理
48+
const filePromises = valid_files.map(async (file) => {
4649
const baseName = path.basename(file, '.js'); // 去掉文件扩展名
4750
let api = `${requestHost}/api/${baseName}`; // 使用请求的 host 地址,避免硬编码端口
4851
if (pwd) {
@@ -74,6 +77,9 @@ async function generateSiteJSON(jsDir, configDir, requestHost, sub, subFilePath,
7477
} else {
7578
ext = it.queryStr;
7679
}
80+
if (ext) {
81+
ext = jsEncoder.gzip(ext);
82+
}
7783
fileSites.push({key: key, name: name, ext: ext})
7884
});
7985
} else {
@@ -95,7 +101,9 @@ async function generateSiteJSON(jsDir, configDir, requestHost, sub, subFilePath,
95101
};
96102
sites.push(site);
97103
});
98-
}
104+
});
105+
// 等待所有的文件处理完成
106+
await Promise.all(filePromises);
99107
sites = naturalSort(sites, 'name', sort_list);
100108
return {sites};
101109
}
@@ -243,8 +251,10 @@ export default (fastify, options, done) => {
243251
}
244252
}
245253
let t2 = (new Date()).getTime();
246-
configObj.cost = t2 - t1;
247-
reply.send(configObj);
254+
let cost = t2 - t1;
255+
// configObj.cost = cost;
256+
// reply.send(configObj);
257+
reply.send(Object.assign({cost}, configObj));
248258
} catch (error) {
249259
reply.status(500).send({error: 'Failed to generate site JSON', details: error.message});
250260
}

Diff for: controllers/http.js

+31
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,36 @@ export default (fastify, options, done) => {
5151
}
5252
});
5353

54+
fastify.get('/ai', async (request, reply) => {
55+
const userInput = request.query.text;
56+
57+
if (!userInput || userInput.trim() === '') {
58+
return reply.status(400).send({error: '请提供文本内容'});
59+
}
60+
61+
const postFields = {
62+
messages: [
63+
{role: 'user', content: userInput}
64+
],
65+
model: 'gpt-4o-mini-2024-07-18'
66+
};
67+
// console.log(JSON.stringify(postFields));
68+
try {
69+
const response = await _axios.post(
70+
'https://api.s01s.cn/API/ai_zdy/?type=2',
71+
postFields,
72+
{
73+
headers: {'Content-Type': 'application/json'},
74+
timeout: 30000,
75+
}
76+
);
77+
78+
return reply.send(response.data);
79+
} catch (error) {
80+
fastify.log.error('Error:', error.message);
81+
return reply.status(500).send({error: '请求失败,请稍后重试'});
82+
}
83+
});
84+
5485
done();
5586
};

Diff for: custom.json

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"sites_count": 43,
2+
"sites_count": 45,
33
"sites": [
44
{
55
"key": "drpyS_设置中心",
@@ -84,7 +84,7 @@
8484
"searchable": 2,
8585
"filterable": 1,
8686
"quickSearch": 0,
87-
"ext": "../json/哔哩大全.json"
87+
"ext": "H4sIAAAAAAAAA9PT088qzs/Tfzp5ytPJK58uWf60dYUeSAQAZ2A+OBkAAAA="
8888
},
8989
{
9090
"key": "drpyS_哔哩教育[官]",
@@ -94,7 +94,7 @@
9494
"searchable": 2,
9595
"filterable": 1,
9696
"quickSearch": 0,
97-
"ext": "../json/哔哩教育.json"
97+
"ext": "H4sIAAAAAAAAA9PT088qzs/Tfzp5ytPJK59NnfmiaZMeSAQAgv7xPBkAAAA="
9898
},
9999
{
100100
"key": "drpyS_哔哩直播[官]",
@@ -126,6 +126,16 @@
126126
"quickSearch": 0,
127127
"ext": ""
128128
},
129+
{
130+
"key": "drpyS_抖音直播弹幕[官]",
131+
"name": "抖音直播弹幕[官](DS)",
132+
"type": 4,
133+
"api": "http://localhost:5757/api/抖音直播弹幕[官]",
134+
"searchable": 1,
135+
"filterable": 1,
136+
"quickSearch": 0,
137+
"ext": ""
138+
},
129139
{
130140
"key": "drpyS_多多[盘]",
131141
"name": "多多[盘](DS)",
@@ -366,6 +376,16 @@
366376
"quickSearch": 0,
367377
"ext": ""
368378
},
379+
{
380+
"key": "drpyS_直播转点播[合]",
381+
"name": "直播转点播[合](DS)",
382+
"type": 4,
383+
"api": "http://localhost:5757/api/直播转点播[合]",
384+
"searchable": 1,
385+
"filterable": 1,
386+
"quickSearch": 0,
387+
"ext": "H4sIAAAAAAAAA9PT088qzs/Tz8ksSzVKzi3WA/EAuuBHLxUAAAA="
388+
},
369389
{
370390
"key": "drpyS_至臻[盘]",
371391
"name": "至臻[盘](DS)",

Diff for: data/douyin/danmu.html

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" name="viewport"
5+
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
6+
<title>Danmaku Display</title>
7+
<style>
8+
body {
9+
margin: 0;
10+
padding: 0;
11+
background-color: transparent;
12+
overflow: hidden;
13+
}
14+
15+
#danmu-container {
16+
position: relative;
17+
width: 100%;
18+
height: 100vh;
19+
background-color: transparent;
20+
color: white;
21+
overflow: hidden;
22+
pointer-events: none;
23+
}
24+
25+
.danmu {
26+
position: absolute;
27+
white-space: nowrap;
28+
color: red;
29+
font-size: 18px;
30+
}
31+
</style>
32+
</head>
33+
<body>
34+
<div id="danmu-container"></div>
35+
<script>
36+
const danmuContainer = document.getElementById('danmu-container');
37+
const socket = new WebSocket('ws://localhost:5757/dy-dm');
38+
const maxRows = 5;
39+
let currentRow = 0;
40+
const rowHeight = 30;
41+
const minDuration = 3; // 新增:最小动画持续时间,单位为秒
42+
43+
function moveDanmu(danmuElement, duration) {
44+
const start = performance.now();
45+
const startX = window.innerWidth;
46+
const endX = -danmuElement.offsetWidth;
47+
const interval = 1000 / 60; // 60fps
48+
const move = () => {
49+
const now = performance.now();
50+
const elapsed = now - start;
51+
if (elapsed < duration) {
52+
const progress = elapsed / duration;
53+
const x = startX - (startX - endX) * progress;
54+
danmuElement.style.left = x + 'px';
55+
requestAnimationFrame(move);
56+
} else {
57+
danmuContainer.removeChild(danmuElement);
58+
}
59+
};
60+
requestAnimationFrame(move);
61+
}
62+
63+
socket.onmessage = function (event) {
64+
const danmuData = JSON.parse(event.data);
65+
danmuData.forEach(danmu => {
66+
const danmuElement = document.createElement('div');
67+
danmuElement.textContent = danmu.text;
68+
danmuElement.className = 'danmu';
69+
danmuContainer.appendChild(danmuElement);
70+
71+
const y = currentRow * rowHeight;
72+
danmuElement.style.top = y + 'px';
73+
74+
const textLength = danmu.text.length;
75+
const baseSpeed = 0.2;
76+
let animationDuration = textLength * baseSpeed;
77+
if (animationDuration < minDuration) {
78+
animationDuration = minDuration;
79+
}
80+
81+
moveDanmu(danmuElement, animationDuration * 1000);
82+
83+
// 循环设置行
84+
currentRow = (currentRow + 1) % maxRows;
85+
});
86+
};
87+
88+
socket.onerror = function (error) {
89+
console.error('WebSocket error:', error);
90+
};
91+
</script>
92+
</body>
93+
</html>

Diff for: docs/updateRecord.md

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

3+
### 20250103
4+
5+
更新至V1.0.30
6+
7+
1. 增加 `抖音直播弹幕[官].js`
8+
2. drpyS注入可用的全局函数 `WebSocket` `WebSocketServer` `zlib`
9+
3. drpyS注入可用的this指针环境变量 `hostUrl`,不含协议头的主机地址
10+
4. 抖音弹幕共享全局fastify接口的服务和端口
11+
5. 增加新的依赖 `google-protobuf`
12+
6. 首页推荐数据报错不再抛错,避免影响其他数据加载
13+
7. `我的哔哩[官].js` 等传参源兼容装逼壳
14+
8. 增加 `runMain` 异步函数,可以调用drpyS.js里的内容
15+
9. 配置生成逻辑改成并发执行,可能某些场景会比较快
16+
10. 增加直转点
17+
318
### 20250102
419

520
更新至V1.0.29

0 commit comments

Comments
 (0)