Update server.js via upload script - 2026-08-01 00:10:07
This commit is contained in:
parent
05f474ee44
commit
4f93f9b480
33
server.js
33
server.js
|
|
@ -567,39 +567,6 @@ app.post('/api/jms/check-line', requireAuth, jmsCheckLimiter, async (req, res) =
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 代为请求JMS订阅地址,解析 Subscription-Userinfo 响应头拿到流量信息——
|
|
||||||
// 浏览器直接fetch会被CORS挡住,服务器端发请求没有这个限制
|
|
||||||
app.post('/api/jms/fetch-traffic', requireAuth, async (req, res) => {
|
|
||||||
const url = ((req.body && req.body.subscriptionUrl) || '').trim();
|
|
||||||
if (!url) return res.status(400).json({ error: '请先填写标准订阅地址' });
|
|
||||||
let parsed;
|
|
||||||
try {
|
|
||||||
parsed = new URL(url);
|
|
||||||
if (!/^https?:$/.test(parsed.protocol)) throw new Error('invalid protocol');
|
|
||||||
} catch (e) {
|
|
||||||
return res.status(400).json({ error: '订阅地址格式不对' });
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const response = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
|
|
||||||
const header = response.headers.get('subscription-userinfo');
|
|
||||||
if (!header) return res.json({ ok: false, error: '这个订阅地址没有返回流量信息(Subscription-Userinfo),可能服务商不支持或者地址不对' });
|
|
||||||
const info = {};
|
|
||||||
header.split(';').forEach(part => {
|
|
||||||
const [k, v] = part.trim().split('=');
|
|
||||||
if (k && v !== undefined) info[k.trim()] = Number(v.trim());
|
|
||||||
});
|
|
||||||
res.json({
|
|
||||||
ok: true,
|
|
||||||
upload: info.upload || 0,
|
|
||||||
download: info.download || 0,
|
|
||||||
total: info.total || 0,
|
|
||||||
expire: info.expire || null,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
res.status(400).json({ error: '获取订阅信息失败:' + e.message });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
const aiLimiter = rateLimit({
|
const aiLimiter = rateLimit({
|
||||||
windowMs: 10 * 60 * 1000,
|
windowMs: 10 * 60 * 1000,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue