mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-clawer.git
synced 2026-08-12 08:50:33 +00:00
refactor: 改进前端内容
This commit is contained in:
parent
e5ff7d07a6
commit
9f07f7d89f
20
.env.example
20
.env.example
@ -2,22 +2,4 @@
|
||||
PORT=3000
|
||||
|
||||
# 抓包代理服务器端口
|
||||
HOOK_PORT=9000:9001
|
||||
|
||||
# 可选:网易云音乐 Cookie(用于某些需要登录的接口)
|
||||
# NETEASE_COOKIE=
|
||||
|
||||
# 可选:上游代理 URL(如需要通过其他代理访问)
|
||||
# PROXY_URL=
|
||||
|
||||
# 可选:强制指定网易云音乐服务器 IP
|
||||
# FORCE_HOST=
|
||||
|
||||
# 可选:是否启用严格模式(限制只能访问指定域名)
|
||||
# STRICT=false
|
||||
|
||||
# 可选:中继服务器地址
|
||||
# CNRELAY=
|
||||
|
||||
# 可选:是否启用 HTTPDNS(目前建议关闭)
|
||||
# ENABLE_HTTPDNS=false
|
||||
HOOK_PORT=9000:9001
|
||||
@ -118,10 +118,5 @@ src/
|
||||
|--------|--------|------|
|
||||
| PORT | 3000 | 前端服务器端口 |
|
||||
| HOOK_PORT | 9000 | 抓包代理服务器端口 |
|
||||
| NETEASE_COOKIE | - | 网易云音乐 Cookie(可选) |
|
||||
| PROXY_URL | - | 上游代理 URL(可选) |
|
||||
| FORCE_HOST | - | 强制指定网易云音乐服务器 IP(可选) |
|
||||
| STRICT | false | 是否启用严格模式(可选) |
|
||||
| CNRELAY | - | 中继服务器地址(可选) |
|
||||
|
||||
详细配置请参考 `.env.example` 文件。
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "api-clawer",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"description": "网易云音乐客户端抓包工具",
|
||||
"main": "src/server/app.js",
|
||||
"scripts": {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
22
src/client/public/manifest.json
Normal file
22
src/client/public/manifest.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "网易云音乐抓包工具",
|
||||
"short_name": "抓包工具",
|
||||
"description": "网易云音乐客户端抓包与调试工具",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#f0f2f5",
|
||||
"theme_color": "#C20C0C",
|
||||
"categories": ["developer tools", "utilities"],
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icon-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
]
|
||||
}
|
||||
18
src/client/public/sw.js
Normal file
18
src/client/public/sw.js
Normal file
@ -0,0 +1,18 @@
|
||||
// 无缓存透传 Service Worker
|
||||
// 仅用于 PWA 安装能力,不缓存任何资源
|
||||
|
||||
self.addEventListener('install', function() {
|
||||
// 立即激活,不等待页面关闭
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('activate', function() {
|
||||
// 接管所有客户端
|
||||
self.clients.claim();
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', function(event) {
|
||||
// 纯透传:不缓存任何内容,每次都请求网络
|
||||
// 如果网络不可用,请求失败由浏览器自行处理
|
||||
event.respondWith(fetch(event.request));
|
||||
});
|
||||
@ -311,6 +311,15 @@ hook.request.before = (ctx) => {
|
||||
break;
|
||||
}
|
||||
netease.path = netease.path.replace(/\/\d*$/, '');
|
||||
// Save original URL path for toggle display and normalize prefixes
|
||||
if (netease.crypto === 'eapi') {
|
||||
netease.rawPath = url.pathname || url.path;
|
||||
} else if (netease.crypto === 'xeapi') {
|
||||
netease.rawPath = url.pathname || url.path;
|
||||
if (netease.path.startsWith('/xeapi/')) {
|
||||
netease.path = netease.path.replace(/^\/xeapi\//, '/api/');
|
||||
}
|
||||
}
|
||||
ctx.netease = netease;
|
||||
console.log(netease.path, netease.param) // 这里输出了网易云音乐的抓包数据, 重点看这里
|
||||
}
|
||||
@ -328,10 +337,12 @@ hook.request.before = (ctx) => {
|
||||
(url.path.startsWith('/weapi/') || url.path.startsWith('/api/'))
|
||||
) {
|
||||
req.headers['X-Real-IP'] = '118.88.88.88';
|
||||
const weapiUrlPath = url.path;
|
||||
ctx.netease = {
|
||||
crypto: url.path.startsWith('/weapi/') ? 'weapi' : 'api',
|
||||
web: true,
|
||||
path: url.path
|
||||
rawPath: url.path.startsWith('/weapi/') ? weapiUrlPath : undefined,
|
||||
path: weapiUrlPath
|
||||
.replace(/^\/weapi\//, '/api/')
|
||||
.split('?')
|
||||
.shift() // remove the query parameters
|
||||
@ -400,10 +411,12 @@ hook.request.after = (ctx) => {
|
||||
const dataToSend = {
|
||||
timestamp: new Date().toISOString(),
|
||||
path: netease.path,
|
||||
rawPath: netease.rawPath || undefined,
|
||||
crypto: netease.crypto || null,
|
||||
param: netease.param,
|
||||
response: netease.jsonBody,
|
||||
statusCode: proxyRes.statusCode
|
||||
statusCode: proxyRes.statusCode,
|
||||
method: req.method
|
||||
};
|
||||
axios.post(`http://localhost:${process.env.PORT || 3000}/api/capture`, dataToSend)
|
||||
.catch(err => logger.error('Failed to send data to frontend:', err));
|
||||
@ -413,11 +426,13 @@ hook.request.after = (ctx) => {
|
||||
const dataToSend = {
|
||||
timestamp: new Date().toISOString(),
|
||||
path: netease.path,
|
||||
rawPath: netease.rawPath || undefined,
|
||||
crypto: netease.crypto || null,
|
||||
param: netease.param,
|
||||
response: null,
|
||||
statusCode: proxyRes.statusCode,
|
||||
error: error.message
|
||||
error: error.message,
|
||||
method: req.method
|
||||
};
|
||||
axios.post(`http://localhost:${process.env.PORT || 3000}/api/capture`, dataToSend)
|
||||
.catch(err => logger.error('Failed to send data to frontend:', err));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user