Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -1,73 +1,40 @@
|
|
| 1 |
const TelegramBot = require('node-telegram-bot-api');
|
| 2 |
-
const
|
| 3 |
-
const path = require('path');
|
| 4 |
-
const os = require('os');
|
| 5 |
const express = require('express');
|
| 6 |
|
| 7 |
const bot = new TelegramBot('7727911031:AAFcPGWeyTynR1FR7Hhpr4HoGDeA4hk9Ebs', { polling: true });
|
| 8 |
const app = express();
|
| 9 |
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
if (bytes >= GB) {
|
| 17 |
-
const gigabytes = bytes / GB
|
| 18 |
-
return gigabytes.toFixed(2) + "GB"
|
| 19 |
-
} else if (bytes >= MB) {
|
| 20 |
-
const megabytes = bytes / MB
|
| 21 |
-
return megabytes.toFixed(2) + "MB"
|
| 22 |
-
} else if (bytes >= KB) {
|
| 23 |
-
const kilobytes = bytes / KB
|
| 24 |
-
return kilobytes.toFixed(2) + "KB"
|
| 25 |
-
} else {
|
| 26 |
-
return bytes.toFixed(2) + "bytes"
|
| 27 |
-
}
|
| 28 |
-
}
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
method: "POST",
|
| 33 |
-
headers: { "Content-Type": "application/json" },
|
| 34 |
-
body: JSON.stringify({ shareid, uk, sign, timestamp, fs_id }),
|
| 35 |
-
}).then(async function (res) {
|
| 36 |
-
return await res.json()
|
| 37 |
-
})
|
| 38 |
-
}
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
.then(async function (res) {
|
| 43 |
-
return await res.json()
|
| 44 |
-
})
|
| 45 |
-
}
|
| 46 |
|
| 47 |
-
bot.on('message', async(msg) => {
|
| 48 |
-
const cid = msg.chat.id
|
| 49 |
-
const
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
bot.sendMessage(cid, '
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
for(let i = 0; i < inpo?.list?.length; i++) {
|
| 64 |
-
let odon = await fetchDownload(d.shareid, d.uk, d.sign, d.timestamp, inpo.list[i].fs_id)
|
| 65 |
-
if(!odon.ok) return
|
| 66 |
-
dlurl.push(odon.downloadUrl)
|
| 67 |
-
}
|
| 68 |
-
for(let i = 0; i < dlurl?.length; i++) {
|
| 69 |
-
bot.sendVideo(cid, dlurl[i])
|
| 70 |
}
|
| 71 |
-
})
|
| 72 |
|
| 73 |
app.listen(7860, () => console.log('Running on port 7860'));
|
|
|
|
| 1 |
const TelegramBot = require('node-telegram-bot-api');
|
| 2 |
+
const axios = require('axios');
|
|
|
|
|
|
|
| 3 |
const express = require('express');
|
| 4 |
|
| 5 |
const bot = new TelegramBot('7727911031:AAFcPGWeyTynR1FR7Hhpr4HoGDeA4hk9Ebs', { polling: true });
|
| 6 |
const app = express();
|
| 7 |
|
| 8 |
+
const apiUrl = "https://terabox.hnn.workers.dev/api";
|
| 9 |
|
| 10 |
+
const fetchJSON = async (url, options = {}) => {
|
| 11 |
+
const { data } = await axios({ url, ...options });
|
| 12 |
+
return data;
|
| 13 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
const fetchDownload = async (params) =>
|
| 16 |
+
fetchJSON(`${apiUrl}/get-download`, { method: "POST", headers: { "Content-Type": "application/json" }, data: params });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
const fetchInfo = async (url) =>
|
| 19 |
+
fetchJSON(`${apiUrl}/get-info?shorturl=${url}&pwd=`);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
bot.on('message', async (msg) => {
|
| 22 |
+
const cid = msg.chat.id;
|
| 23 |
+
const match = msg.text.match(/(?:surl=|\/)([a-zA-Z0-9-_]+)$/);
|
| 24 |
+
|
| 25 |
+
if (!match) return;
|
| 26 |
+
|
| 27 |
+
bot.sendMessage(cid, 'Please wait...');
|
| 28 |
+
|
| 29 |
+
const inpo = await fetchInfo(match[1]);
|
| 30 |
+
if (!inpo.ok) return;
|
| 31 |
+
|
| 32 |
+
const params = { shareid: inpo.shareid, uk: inpo.uk, sign: inpo.sign, timestamp: inpo.timestamp };
|
| 33 |
+
|
| 34 |
+
for (const file of inpo.list || []) {
|
| 35 |
+
const odon = await fetchDownload({ ...params, fs_id: file.fs_id });
|
| 36 |
+
if (odon.ok) await bot.sendVideo(cid, odon.downloadUrl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
+
});
|
| 39 |
|
| 40 |
app.listen(7860, () => console.log('Running on port 7860'));
|