// å®ä¹å¤é¨åé let sitename = "VPSå°æçæ§"; // åéåSITENAMEï¼èªå®ä¹ç«ç¹å称ï¼é»è®¤ä¸ºâååçæ§â let vpsinfo = ""; // åéåVPSINFOï¼å¡«å ¥ååä¿¡æ¯jsonæ件ç´é¾ï¼å¿ 须设置çåé let tgid = ""; // åéåTGIDï¼å¡«å ¥TGæºå¨äººIDï¼ä¸éè¦æéåä¸å¡« let tgtoken = ""; // åéåTGTOKENï¼å¡«å ¥TGçTOKENï¼ä¸éè¦æéåä¸å¡« let days = "5"; // åéåDAYSï¼æåå 天åéTGæéï¼é»è®¤ä¸º5天ï¼å¿ 须为大äº0çæ´æ° // 访é®ç»å®ç KV å½åç©ºé´ async function sendtgMessage(message, tgid, tgtoken) { if (!tgid || !tgtoken) return; const url = `https://api.telegram.org/bot${tgtoken}/sendMessage`; const params = { chat_id: tgid, text: message, }; try { await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(params), }); } catch (error) { console.error('Telegram æ¶æ¯æ¨é失败:', error); } } export default { async fetch(request, env) { sitename = env.SITENAME || sitename; vpsinfo = env.VPSINFO || vpsinfo; tgid = env.TGID || tgid; tgtoken = env.TGTOKEN || tgtoken; days = parseInt(env.DAYS || days, 10); // 读ååéVPSINFOä¸çVPSæ°æ®ï¼æ ¼å¼ä¸ºjson if (!vpsinfo) { return new Response("VPSINFO ç¯å¢åéæªè®¾ç½®", { status: 500 }); } try { const response = await fetch(vpsinfo); if (!response.ok) { throw new Error('Network response was not ok'); } const data = await response.json(); if (!Array.isArray(data)) { throw new Error('JSON æ°æ®æ ¼å¼ä¸æ£ç¡®'); } vpsinfo = data; // æ£æ¥å³å°å°æçVPS并åé Telegram æ¶æ¯ for (const info of vpsinfo) { const expirationDate = new Date(info.expirationDate); const today = new Date(); const daysRemaining = Math.ceil((expirationDate - today) / (1000 * 60 * 60 * 24)); if (daysRemaining > 0 && daysRemaining <= days) { const message = `[VPS] ${info.country} ${info.system} ${info.type} å°å¨ ${daysRemaining} 天åå°æãå°ææ¥æï¼${info.expirationDate}`; // å¨åééç¥ä¹åæ£æ¥æ¯å¦å·²ç»åéè¿éç¥ const lastSent = await env.VPS_TG_KV.get(info.system); // 使ç¨KVåå¨æ£æ¥ä¸æ¬¡åéçç¶æ if (!lastSent || (new Date(lastSent).toISOString().split('T')[0] !== today.toISOString().split('T')[0])) { // å¦æ没æè®°å½ï¼æè è®°å½çæ¶é´ä¸æ¯ä»å¤©ï¼ååééç¥å¹¶æ´æ° KV await sendtgMessage(message, tgid, tgtoken); await env.VPS_TG_KV.put(info.system, new Date().toISOString()); // æ´æ° KV åå¨çåéæ¶é´ } } } // å¤ç generateHTML çè¿åå¼ const htmlContent = await generateHTML(vpsinfo, sitename); return new Response(htmlContent, { headers: { 'Content-Type': 'text/html' }, }); } catch (error) { console.error("Fetch error:", error); return new Response("æ æ³è·åæ解æVPSç json æ件", { status: 500 }); } } }; async function generateHTML(vpsinfo, SITENAME) { const rows = await Promise.all(vpsinfo.map(async info => { const registrationDate = new Date(info.registrationDate); const expirationDate = new Date(info.expirationDate); const today = new Date(); const totalDays = (expirationDate - registrationDate) / (1000 * 60 * 60 * 24); const daysElapsed = (today - registrationDate) / (1000 * 60 * 60 * 24); const progressPercentage = Math.min(100, Math.max(0, (daysElapsed / totalDays) * 100)); const daysRemaining = Math.ceil((expirationDate - today) / (1000 * 60 * 60 * 24)); const isExpired = today > expirationDate; const statusColor = isExpired ? '#e74c3c' : '#2ecc71'; const statusText = isExpired ? 'å·²è¿æ' : 'æ£å¸¸'; return `
ç¶æ | å½å®¶ | ç³»ç» | ASN | ç±»å | 注åæ¶é´ | å°ææ¶é´ | å©ä½å¤©æ° | 使ç¨è¿åº¦ |
---|