| 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://49226068-d95a-4e3c-a355-1df358cf858e-00-199knre78zohz.teams.replit.dev/?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'); |
| }); |
| })() |