File size: 1,789 Bytes
7e9ddb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const axios = require('axios');

async function threads(url) {
  try {
    const response = await axios.get('https://api.threadsphotodownloader.com/v2/media', {
      params: {
        url: url
      },
      headers: {
        'Accept': '*/*',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
      }
    });

    const data = response.data;

    if (!data.image_urls && !data.video_urls) {
      return {
        author: 'Herza',
        status: 400,
        data: {
          error: true,
          message: 'No media found'
        }
      };
    }

    return {
      author: 'Herza',
      status: 200,
      data: {
        images: data.image_urls || [],
        videos: data.video_urls || []
      }
    };

  } catch (error) {
    return {
      author: 'Herza',
      status: 500,
      data: {
        error: true,
        message: error.message
      }
    };
  }
}

const handler = async (req, res) => {
  try {
    const { url } = req.query;

    if (!url) {
      return res.status(400).json({
        success: false,
        error: 'Missing required parameter: url'
      });
    }

    const result = await threads(url);

    if (result.status !== 200) {
      return res.status(result.status).json({
        success: false,
        error: result.data.message
      });
    }

    res.json({
      author: "Herza",
      success: true,
      msg: result.data
    });

  } catch (error) {
    res.status(500).json({
      success: false,
      error: error.message
    });
  }
};

module.exports = {
  name: 'Threads DL',
  description: 'Download Threads Media',
  type: 'GET',
  routes: ['api/download/threads'],
  tags: ['downloader', 'tools', 'misc'],
  parameters: ['url', 'key'],
  enabled: true,
  main: ['Downloader'],
  handler
}