scnario commited on
Commit
4551c7e
·
verified ·
1 Parent(s): c967d6a

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +24 -36
server.js CHANGED
@@ -1,40 +1,28 @@
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'));
 
1
+ const express = require("express");
2
+ const captcha = require("captcha");
3
+ const fs = require("fs");
4
+ const os = require("os");
5
+ const path = require("path");
6
 
 
7
  const app = express();
8
+ const tempDir = os.tmpdir();
9
+
10
+ app.get("/captcha", (req, res) => {
11
+ const captchaCode = Math.random().toString(36).substring(2, 6).toUpperCase();
12
+ const captchaImage = captcha.create({ width: 150, height: 50, text: captchaCode });
13
+
14
+ const fileName = `temp_${Math.random().toString(36).substring(2, 6).toUpperCase()}.png`;
15
+ const filePath = path.join(tempDir, fileName);
16
+
17
+ fs.writeFile(filePath, captchaImage.buffer, (err) => {
18
+ if (err) {
19
+ return res.status(500).json({ error: "Failed to save captcha" });
20
+ }
21
+ res.json({
22
+ answer: captchaCode,
23
+ url: filePath
24
+ });
25
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  });
27
 
28
+ app.listen(7860, () => console.log("Server running on port 7860"));