Update storage.js via upload script - 2026-07-31 17:57:13
This commit is contained in:
parent
5b23bde6b5
commit
2c865f76ba
57
storage.js
57
storage.js
|
|
@ -163,3 +163,60 @@ export async function translateTerms(terms, targetLang) {
|
|||
if (!res.ok) throw new Error(data.error || 'translate failed');
|
||||
return data.translations;
|
||||
}
|
||||
|
||||
/* ------------------------------ Telegram config ---------------------------- */
|
||||
|
||||
export async function getTelegramConfig() {
|
||||
const res = await fetch('/api/telegram-config');
|
||||
return res.json().catch(() => ({ hasToken: false, chatId: '' }));
|
||||
}
|
||||
|
||||
export async function saveTelegramConfig(botToken, chatId) {
|
||||
const res = await fetch('/api/telegram-config', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ botToken, chatId }),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) throw new Error(data.error || 'save failed');
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function deleteTelegramConfig() {
|
||||
const res = await fetch('/api/telegram-config', { method: 'DELETE' });
|
||||
return res.json().catch(() => ({}));
|
||||
}
|
||||
|
||||
export async function testTelegramConfig() {
|
||||
const res = await fetch('/api/telegram-config/test', { method: 'POST' });
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) throw new Error(data.error || 'test failed');
|
||||
return data;
|
||||
}
|
||||
|
||||
/* --------------------------------- JMS api --------------------------------- */
|
||||
|
||||
// 对单条线路立即做一次连通性检测(SS/VMess/VLESS Reality走TCP测试,VLESS-CDN走HTTP状态码+真实WS握手)
|
||||
export async function checkJmsLine(line) {
|
||||
const res = await fetch('/api/jms/check-line', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ line }),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) throw new Error(data.error || 'check failed');
|
||||
return data; // { status: 'normal' | 'abnormal', checkedAt }
|
||||
}
|
||||
|
||||
// 让服务器代为请求JMS的标准订阅地址,解析Subscription-Userinfo拿到流量信息
|
||||
// (浏览器直接fetch会被CORS挡住,服务器端没有这个限制)
|
||||
export async function fetchJmsTraffic(subscriptionUrl) {
|
||||
const res = await fetch('/api/jms/fetch-traffic', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ subscriptionUrl }),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) throw new Error(data.error || 'fetch traffic failed');
|
||||
return data; // { ok, upload, download, total, expire } 或 { ok:false, error }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue