File size: 1,654 Bytes
b376866
 
 
 
 
3985502
b376866
 
 
 
3985502
b376866
 
 
 
 
 
 
 
 
3985502
 
 
 
 
 
 
 
 
 
b376866
 
 
 
 
3985502
b376866
 
3985502
b376866
 
 
 
 
3985502
b376866
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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}`);
});