const axios = require('axios'); async function igstalk(user) { try { const profileResponse = await axios.post( 'https://api.boostfluence.com/api/instagram-profile-v2', { username: user }, { headers: { 'Content-Type': 'application/json' } } ); const profile = profileResponse.data; let postsData = null; try { const initialPostsResponse = await axios.post( 'https://api.boostfluence.com/api/instagram-viewer-v2-2', { username: user, type: 'photo', pagination_token: null }, { headers: { 'Content-Type': 'application/json' } } ); if (initialPostsResponse.data.error === 'COMPUTE_REQUIRED') { const { timestamp, expectedCompute } = initialPostsResponse.data.challenge; const verifiedPostsResponse = await axios.post( 'https://api.boostfluence.com/api/instagram-viewer-v2-2', { username: user, type: 'photo', pagination_token: null }, { headers: { 'Content-Type': 'application/json', 'X-Compute': expectedCompute.toString(), 'X-Timestamp': timestamp.toString() } } ); postsData = verifiedPostsResponse.data; } else { postsData = initialPostsResponse.data; } } catch (postsError) { console.error('Error fetching posts:', postsError.message); } return { profile: { username: profile.username, full_name: profile.full_name, biography: profile.biography, follower_count: profile.follower_count, following_count: profile.following_count, media_count: profile.media_count, profile_pic_url: profile.profile_pic_url, profile_pic_url_hd: profile.profile_pic_url_hd, is_verified: profile.is_verified, is_private: profile.is_private, external_url: profile.external_url, category: profile.category } }; } catch (error) { throw new Error(`Failed to fetch Instagram data: ${error.message}`); } } const handler = async (req, res) => { try { const { username } = req.query; if (!username) { return res.status(400).json({ success: false, error: 'Missing required parameter: username' }); } const usernameRegex = /^[a-zA-Z0-9._]{1,30}$/; if (!usernameRegex.test(username)) { return res.status(400).json({ success: false, error: 'Invalid username format' }); } const result = await igstalk(username); res.json({ author: "Herza", success: true, data: result }); } catch (error) { res.status(500).json({ author: "Herza", success: false, error: error.message }); } }; module.exports = { name: 'Instagram Stalk', description: 'Get Instagram user profile information including stats, bio, and posts', type: 'GET', routes: ['api/stalk/instagram'], tags: ['social', 'instagram', 'stalk', 'profile'], parameters: ['username', 'key'], enabled: true, main: ['Stalk'], handler };