| 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 | |
| } |