Update storage.js via upload script - 2026-07-31 17:57:13

This commit is contained in:
mike 2026-07-31 17:57:33 +08:00
parent 5b23bde6b5
commit 2c865f76ba
1 changed files with 57 additions and 0 deletions

View File

@ -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 }
}