txtorg commited on
Commit
3985502
Β·
verified Β·
1 Parent(s): 7710bff

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +15 -11
server.js CHANGED
@@ -3,11 +3,12 @@ const axios = require("axios");
3
  const cron = require("node-cron");
4
 
5
  const app = express();
6
- const PORT = process.env.PORT || 3000;
7
 
8
  // Target URLs (Hugging Face Spaces)
9
  const PING_URL = "https://txtorg-newspa.hf.space/login"; // First API
10
  const CODE_API_URL = "https://txtorg-code.hf.space/api/get?q=7224"; // Second API
 
11
  const SELF_URL = "https://pycra-pi.hf.space"; // Self-ping URL
12
 
13
  // Check server status
@@ -17,26 +18,29 @@ app.get("/", (req, res) => {
17
 
18
  // Function to ping a site with retries
19
  const pingSite = async (url, retries = 3) => {
20
- try {
21
- const response = await axios.get(url);
22
- console.log(`βœ… Pinged: ${url}`, response.data);
23
- } catch (error) {
24
- console.error(`❌ Failed to ping: ${url}`);
25
- if (retries > 0) {
26
- console.log(`πŸ” Retrying in 5 seconds... (${retries} retries left)`);
27
- setTimeout(() => pingSite(url, retries - 1), 5000);
 
 
28
  }
29
  }
30
  };
31
 
32
  // **Auto Ping Every 7 Seconds**
33
- cron.schedule("*/7 * * * * *", () => {
34
  pingSite(PING_URL); // Ping first API
35
  pingSite(CODE_API_URL); // Ping second API
 
36
  pingSite(SELF_URL); // Ping itself
37
  });
38
 
39
  // Start Express server
40
  app.listen(PORT, () => {
41
- console.log(`πŸš€ Keep-alive server running at ${SELF_URL}`);
42
  });
 
3
  const cron = require("node-cron");
4
 
5
  const app = express();
6
+ const PORT = process.env.PORT || 7860;
7
 
8
  // Target URLs (Hugging Face Spaces)
9
  const PING_URL = "https://txtorg-newspa.hf.space/login"; // First API
10
  const CODE_API_URL = "https://txtorg-code.hf.space/api/get?q=7224"; // Second API
11
+ const STREAM_API_URL = "https://txtorg-stream.hf.space/timestamp?channel=AniTv"; // New API
12
  const SELF_URL = "https://pycra-pi.hf.space"; // Self-ping URL
13
 
14
  // Check server status
 
18
 
19
  // Function to ping a site with retries
20
  const pingSite = async (url, retries = 3) => {
21
+ for (let attempt = 1; attempt <= retries; attempt++) {
22
+ try {
23
+ const response = await axios.get(url, { timeout: 5000 });
24
+ console.log(`βœ… Pinged: ${url} | Status: ${response.status}`);
25
+ return; // Success, exit function
26
+ } catch (error) {
27
+ console.error(`❌ Failed to ping: ${url} | Attempt ${attempt} of ${retries}`);
28
+ if (attempt < retries) {
29
+ await new Promise((resolve) => setTimeout(resolve, 5000)); // Wait before retrying
30
+ }
31
  }
32
  }
33
  };
34
 
35
  // **Auto Ping Every 7 Seconds**
36
+ cron.schedule("*/7 * * * * *", async () => {
37
  pingSite(PING_URL); // Ping first API
38
  pingSite(CODE_API_URL); // Ping second API
39
+ pingSite(STREAM_API_URL); // Ping new API
40
  pingSite(SELF_URL); // Ping itself
41
  });
42
 
43
  // Start Express server
44
  app.listen(PORT, () => {
45
+ console.log(`πŸš€ Keep-alive server running at ${SELF_URL} on port ${PORT}`);
46
  });