randydev commited on
Commit
901ed02
·
verified ·
1 Parent(s): 3b24101

Update plugins/antiban.js

Browse files
Files changed (1) hide show
  1. plugins/antiban.js +28 -9
plugins/antiban.js CHANGED
@@ -3,11 +3,10 @@ import axios from 'axios';
3
  import { Database } from '../database/database.js';
4
  import { predictCreationDate } from '../lib/create-date.js';
5
  import { authenticateApiKey, apiLimiter } from '../middleware/midware.js';
 
6
  const AntibanRoutes = express.Router();
7
  import * as uuid from 'uuid';
8
 
9
- const myUUID = uuid.v4();
10
-
11
  const protectedUsers = [6477856957, 1191668125, 1448273246, 1054295664, 6444305696];
12
 
13
  const TelegramUser = async (user_id) => {
@@ -232,15 +231,35 @@ AntibanRoutes.get("/api/v1/user/story-dl", authenticateApiKey, apiLimiter, async
232
  if (!Links) {
233
  return res.status(400).json({ error: "Invalid or missing link" });
234
  }
235
-
236
- try {
237
- const result = await TelegramUserStoryDL(Links);
238
- res.json(result);
239
- } catch (error) {
240
- res.status(500).json({ error: "Failed to fetch user info" });
241
- }
 
 
 
 
 
 
 
 
 
 
242
  });
243
 
 
 
 
 
 
 
 
 
 
 
244
 
245
  /**
246
  * @swagger
 
3
  import { Database } from '../database/database.js';
4
  import { predictCreationDate } from '../lib/create-date.js';
5
  import { authenticateApiKey, apiLimiter } from '../middleware/midware.js';
6
+ import { Job } from '../models.js';
7
  const AntibanRoutes = express.Router();
8
  import * as uuid from 'uuid';
9
 
 
 
10
  const protectedUsers = [6477856957, 1191668125, 1448273246, 1054295664, 6444305696];
11
 
12
  const TelegramUser = async (user_id) => {
 
231
  if (!Links) {
232
  return res.status(400).json({ error: "Invalid or missing link" });
233
  }
234
+ const job_id = uuid.v4();
235
+ const newJob = new Job({ job_id, status: "pending" });
236
+ await newJob.save();
237
+ setTimeout(async () => {
238
+ try {
239
+ const result = await TelegramUserStoryDL(Links);
240
+ const story_bytes = result.download;
241
+
242
+ await Job.findOneAndUpdate(
243
+ { job_id },
244
+ { status: "completed", story_bytes }
245
+ );
246
+ } catch (err) {
247
+ await Job.findOneAndUpdate({ job_id }, { status: "failed" });
248
+ }
249
+ }, 10000);
250
+ res.json({ message: "Download started", job_id });
251
  });
252
 
253
+ app.get("/api/v1/user/story/:job_id", authenticateApiKey, apiLimiter, async (req, res) => {
254
+ const job = await Job.findOne({ job_id: req.params.job_id });
255
+
256
+ if (!job) return res.status(404).json({ error: "Job not found" });
257
+ res.json({
258
+ job_id: job.job_id,
259
+ status: job.status,
260
+ story_bytes: job.story_bytes
261
+ });
262
+ });
263
 
264
  /**
265
  * @swagger