Skip to content

Commit aad712b

Browse files
author
Taois
committed
feat: 支持快捷获取最新包的链接
1 parent 7c9c843 commit aad712b

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ nodejs作为服务端的drpy实现。全面升级异步写法
1111
### 常用超链接
1212

1313
* [本项目主页-免翻](https://github.com/hjdhnx/drpy-node)
14+
* [最新DS本地包-适配皮卡丘](/gh/release)
1415
* [接口文档](docs/apidoc.md) | [接口列表如定时任务](docs/apiList.md) |
1516
~~[小猫影视-待对接T4](https://github.com/waifu-project/movie/pull/135)~~
1617
* [代码质量评估工具说明](docs/codeCheck.md) | [DS项目代码评估报告](docs/codeCheckReport.md)

controllers/github.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import axios from 'axios';
2+
3+
/**
4+
* GitHub Release 控制器
5+
* 用于获取 GitHub 仓库的最新 Release 下载链接
6+
*/
7+
export default (fastify, options, done) => {
8+
9+
/**
10+
* 获取最新 Release 下载链接
11+
* 路径: /gh/release
12+
* 参数: repo (可选,默认 hjdhnx/drpy-node)
13+
*/
14+
fastify.get('/gh/release', async (request, reply) => {
15+
const repo = request.query.repo || 'hjdhnx/drpy-node';
16+
const proxyPrefix = 'https://github.catvod.com/';
17+
const apiUrl = `https://api.github.com/repos/${repo}/releases/latest`;
18+
19+
try {
20+
fastify.log.info(`Fetching release info for ${repo}`);
21+
22+
const response = await axios.get(apiUrl, {
23+
headers: {
24+
'User-Agent': 'drpy-node-client',
25+
'Accept': 'application/vnd.github.v3+json'
26+
}
27+
});
28+
29+
const data = response.data;
30+
31+
if (!data.assets || data.assets.length === 0) {
32+
return reply.status(404).send({ error: 'No assets found in the latest release' });
33+
}
34+
35+
// 打印全部文件列表的链接
36+
fastify.log.info(`Assets for ${repo} ${data.tag_name}:`);
37+
const fileList = data.assets.map(asset => {
38+
fastify.log.info(`- ${asset.name}: ${asset.browser_download_url}`);
39+
return {
40+
name: asset.name,
41+
url: asset.browser_download_url,
42+
proxy_url: proxyPrefix + asset.browser_download_url
43+
};
44+
});
45+
46+
// 优先选择后缀为 .7z 且文件名不包含 green 的文件
47+
let targetAsset = data.assets.find(asset => asset.name.toLowerCase().endsWith('.7z') && !asset.name.toLowerCase().includes('green'));
48+
49+
if (!targetAsset) {
50+
fastify.log.warn(`No asset found matching criteria (.7z, no 'green'), falling back to the first asset.`);
51+
targetAsset = data.assets[0];
52+
}
53+
54+
const originalUrl = targetAsset.browser_download_url;
55+
const finalUrl = proxyPrefix + originalUrl;
56+
57+
// 返回这个完整链接
58+
// 用户要求"返回这个完整链接",这里直接返回字符串
59+
return reply.send(finalUrl);
60+
61+
} catch (error) {
62+
fastify.log.error(`Error fetching release for ${repo}: ${error.message}`);
63+
if (error.response) {
64+
fastify.log.error(`GitHub API Status: ${error.response.status}`);
65+
return reply.status(error.response.status).send({
66+
error: 'GitHub API Error',
67+
message: error.response.data.message
68+
});
69+
}
70+
return reply.status(500).send({ error: 'Internal Server Error', message: error.message });
71+
}
72+
});
73+
74+
done();
75+
};

controllers/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import m3u8ProxyController from './m3u8-proxy.js';
4949
import unifiedProxyController from './unified-proxy.js';
5050
// WebSocket实时弹幕日志控制器
5151
import websocketServerController from "./websocketServer.js";
52+
import githubController from './github.js';
5253

5354
/**
5455
* 注册所有路由控制器
@@ -104,6 +105,8 @@ export const registerRoutes = (fastify, options) => {
104105
fastify.register(m3u8ProxyController, options);
105106
// 注册统一代理路由
106107
fastify.register(unifiedProxyController, options);
108+
// 注册GitHub Release路由
109+
fastify.register(githubController, options);
107110
};
108111

109112
/**

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

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ <h1 id="drpysdrpy-node">drpyS(drpy-node)</h1>
1414
<h3 id="常用超链接">常用超链接</h3>
1515
<ul>
1616
<li><a href="https://github.com/hjdhnx/drpy-node">本项目主页-免翻</a></li>
17+
<li><a href="/gh/release">最新DS本地包-适配皮卡丘</a></li>
1718
<li><a href="docs/apidoc.md">接口文档</a> | <a href="docs/apiList.md">接口列表如定时任务</a> |
1819
<del><a href="https://github.com/waifu-project/movie/pull/135">小猫影视-待对接T4</a></del></li>
1920
<li><a href="docs/codeCheck.md">代码质量评估工具说明</a> | <a href="docs/codeCheckReport.md">DS项目代码评估报告</a></li>

0 commit comments

Comments
 (0)