File size: 1,664 Bytes
39100fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const Database = require("@replit/database")
const db = new Database()
const axios = require('axios');
(async() => {
  db.get("urls").then(value => {
    if (!value) db.set('urls', []).then(() => {
      console.log("SETUP DONE")
    });
  });

  const fetch = async data => {
    for (url of data) {
      await axios.get(url)
        .then(res => res = null)
        .catch(e => e = null);
    }
    data = null;
  }
  
  setInterval(() => {
    db.get('urls').then(async(data) => { 
      let m = Math.ceil(data.length / 3);
      let n = Math.ceil(2 * data.length / 3);
      let DATA = [];
      DATA[0] = data.slice(0, m);
      DATA[1] = data.slice(m, n);
      DATA[2] = data.slice(n, data.length);

      DATA.forEach(fetch);
      DATA = m = n = null;
    })
  }, 20000);
  
  const express = require('express');
  
  const app = express();
  
  app.get('/', async(req, res) => {
    if ('add' in req.query) {
      let urls = await db.get('urls');
      if (urls.includes(req.query.add)) {
        res.send({
          status: false,
          msg: 'Đã có rồi'
        });
        return;
      } else {
        urls.push(req.query.add);
        db.set('urls', urls).then(() => {
          console.log(`Đã thêm ${req.query.add}`);
        });
        res.send({
          status: true,
          msg: 'Đã được thêm, bạn có thể out trang rồi nhé!'
        });
        return;
      }
    }
    res.send('Hello mấy cưng! Cách dùng: https://uptimesny.onrender.com/?add=link cần treo')
  });
  
  app.listen(3000, () => {
    console.log('Server uptime đã bắt đầu, hãy treo uptime robot thủ công nhé:0');
  });
})()