Update index.js
Browse files317 unmodified lines31831932032132232342 unmodified lines366367368369370371122 unmodified lines494495496497498499317 unmodified lines};};const app = express();app.set('json spaces', 4);app.use(morgan('dev'));42 unmodified lines"title": "Mega Downloader","method": "GET","example": `${host}/mega?url=`+ '${encodeURIComponent(${url})}',}]});122 unmodified linesreturn res.json({ message: e.message });}});app.get('/mega', async (req, res) => {try {let { url } = req.query;317 unmodified lines31831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336442 unmodified lines407408409410411412413414415416417122 unmodified lines540541542543544545546547548549550551552553554555556557558317 unmodified lines};};//TWITTER APIasync twitterAPI(url, options = {text:true}) {let input = {};if (typeof url === 'object')if (url.url)input = url;elsereturn { found: false, error: 'No URL provided' };else if (typeof url === 'string')input.url = url;elsereturn { found: false, error: 'Invalid first argument' };if (options)Object.keys(options).forEach((key) => input[key] = options[key]);if (/\/\/twitter.com/.test(input.url)) {let apiURL = input.url.replace('//twitter.com', '//api.vxtwitter.com');let result = await axios.get(apiURL, {}).then((res) => res.data).catch((err) => {return { found: false, error: 'An issue occured. Make sure the twitter link is valid.' };});if (!result.media_extended)return { found: false, error: 'No media found' };let output = {found: true,type: result.media_extended[0].type,url: result.media_extended[0].url};if (input.text)output.text = result.text;if (input.buffer)output.buffer = await axios.get(output.url, { responseType: 'arraybuffer', headers: headers }).then((res) => {return Buffer.from(res.data, 'binary');}).catch((err) => {console.log('Error getting buffer: ', err);return undefined;});return output;}elsereturn { found: false, error: `Invalid URL: ${input.url}` };}const app = express();app.set('json spaces', 4);app.use(morgan('dev'));42 unmodified lines"title": "Mega Downloader","method": "GET","example": `${host}/mega?url=`+ '${encodeURIComponent(${url})}',},{"title": "Twitter/X Downloader","method": "GET","example": `${host}/twitter?url=`,}]});122 unmodified linesreturn res.json({ message: e.message });}});app.get('/twitter', async (req,res) => {try {let {url} = req.queryif (!/https?:\/\/(www\.)?(twitter|X)\.com\/.*\/status/.test(url)) {return res.json({ message: 'Invalid URL' });}let data = await twitterAPI(url)return res.json(data)} catch (e) {console.log(e);return res.json({ message: e.message });}});app.get('/mega', async (req, res) => {try {let { url } = req.query;
index.js+59