const express = require("express"); const axios = require("axios"); const cron = require("node-cron"); const app = express(); const PORT = process.env.PORT || 7860; // Target URLs (Hugging Face Spaces) const PING_URL = "https://txtorg-newspa.hf.space/login"; // First API const CODE_API_URL = "https://txtorg-code.hf.space/api/get?q=7224"; // Second API const STREAM_API_URL = "https://txtorg-stream.hf.space/timestamp?channel=AniTv"; // New API const SELF_URL = "https://pycra-pi.hf.space"; // Self-ping URL // Check server status app.get("/", (req, res) => { res.send("Keep-alive server is running! ✅"); }); // Function to ping a site with retries const pingSite = async (url, retries = 3) => { for (let attempt = 1; attempt <= retries; attempt++) { try { const response = await axios.get(url, { timeout: 5000 }); console.log(`✅ Pinged: ${url} | Status: ${response.status}`); return; // Success, exit function } catch (error) { console.error(`❌ Failed to ping: ${url} | Attempt ${attempt} of ${retries}`); if (attempt < retries) { await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait before retrying } } } }; // **Auto Ping Every 7 Seconds** cron.schedule("*/7 * * * * *", async () => { pingSite(PING_URL); // Ping first API pingSite(CODE_API_URL); // Ping second API pingSite(STREAM_API_URL); // Ping new API pingSite(SELF_URL); // Ping itself }); // Start Express server app.listen(PORT, () => { console.log(`🚀 Keep-alive server running at ${SELF_URL} on port ${PORT}`); });