scnario commited on
Commit
7c9d1d2
·
verified ·
1 Parent(s): 1f94ec1

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +27 -60
server.js CHANGED
@@ -1,73 +1,40 @@
1
  const TelegramBot = require('node-telegram-bot-api');
2
- const fs = require('fs');
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
- function formatStorageSize(bytes) {
12
- const KB = 1024
13
- const MB = KB * 1024
14
- const GB = MB * 1024
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
- function fetchDownload({ shareid, uk, sign, timestamp, fs_id }) {
31
- return fetch("https://terabox.hnn.workers.dev/api/get-download", {
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
- function fetchInfo({ url }) {
41
- return fetch("https://terabox.hnn.workers.dev/api/get-info?shorturl=" + url + "&pwd=")
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 url = msg.text
50
- const regex = /(?:surl=|\/)([a-zA-Z0-9-_]+)$/
51
- const match = url.match(regex)
52
- if(!match) return
53
- bot.sendMessage(cid, 'please wait..')
54
- let inpo = await fetchInfo(match[1])
55
- if(!inpo.ok) return
56
- let d = {
57
- shareid: inpo.shareid,
58
- uk: inpo.uk,
59
- sign: inpo.sign,
60
- timestamp: inpo.timestamp
61
- }
62
- let dlurl = []
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'));