Update index.js
Browse files
index.js
CHANGED
|
@@ -318,6 +318,47 @@ const youtubedl = async (url) => {
|
|
| 318 |
};
|
| 319 |
};
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
const app = express();
|
| 322 |
app.set('json spaces', 4);
|
| 323 |
app.use(morgan('dev'));
|
|
@@ -366,6 +407,11 @@ app.all('/', (req, res) => {
|
|
| 366 |
"title": "Mega Downloader",
|
| 367 |
"method": "GET",
|
| 368 |
"example": `${host}/mega?url=`+ '${encodeURIComponent(${url})}',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
}
|
| 370 |
]
|
| 371 |
});
|
|
@@ -494,6 +540,19 @@ app.all('/', (req, res) => {
|
|
| 494 |
return res.json({ message: e.message });
|
| 495 |
}
|
| 496 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 497 |
app.get('/mega', async (req, res) => {
|
| 498 |
try {
|
| 499 |
let { url } = req.query;
|
|
|
|
| 318 |
};
|
| 319 |
};
|
| 320 |
|
| 321 |
+
//TWITTER API
|
| 322 |
+
async twitterAPI(url, options = {text:true}) {
|
| 323 |
+
let input = {};
|
| 324 |
+
if (typeof url === 'object')
|
| 325 |
+
if (url.url)
|
| 326 |
+
input = url;
|
| 327 |
+
else
|
| 328 |
+
return { found: false, error: 'No URL provided' };
|
| 329 |
+
else if (typeof url === 'string')
|
| 330 |
+
input.url = url;
|
| 331 |
+
else
|
| 332 |
+
return { found: false, error: 'Invalid first argument' };
|
| 333 |
+
if (options)
|
| 334 |
+
Object.keys(options).forEach((key) => input[key] = options[key]);
|
| 335 |
+
if (/\/\/twitter.com/.test(input.url)) {
|
| 336 |
+
let apiURL = input.url.replace('//twitter.com', '//api.vxtwitter.com');
|
| 337 |
+
let result = await axios.get(apiURL, {}).then((res) => res.data).catch((err) => {
|
| 338 |
+
return { found: false, error: 'An issue occured. Make sure the twitter link is valid.' };
|
| 339 |
+
});
|
| 340 |
+
if (!result.media_extended)
|
| 341 |
+
return { found: false, error: 'No media found' };
|
| 342 |
+
let output = {
|
| 343 |
+
found: true,
|
| 344 |
+
type: result.media_extended[0].type,
|
| 345 |
+
url: result.media_extended[0].url
|
| 346 |
+
};
|
| 347 |
+
if (input.text)
|
| 348 |
+
output.text = result.text;
|
| 349 |
+
if (input.buffer)
|
| 350 |
+
output.buffer = await axios.get(output.url, { responseType: 'arraybuffer', headers: headers }).then((res) => {
|
| 351 |
+
return Buffer.from(res.data, 'binary');
|
| 352 |
+
}).catch((err) => {
|
| 353 |
+
console.log('Error getting buffer: ', err);
|
| 354 |
+
return undefined;
|
| 355 |
+
});
|
| 356 |
+
return output;
|
| 357 |
+
}
|
| 358 |
+
else
|
| 359 |
+
return { found: false, error: `Invalid URL: ${input.url}` };
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
const app = express();
|
| 363 |
app.set('json spaces', 4);
|
| 364 |
app.use(morgan('dev'));
|
|
|
|
| 407 |
"title": "Mega Downloader",
|
| 408 |
"method": "GET",
|
| 409 |
"example": `${host}/mega?url=`+ '${encodeURIComponent(${url})}',
|
| 410 |
+
},
|
| 411 |
+
{
|
| 412 |
+
"title": "Twitter/X Downloader",
|
| 413 |
+
"method": "GET",
|
| 414 |
+
"example": `${host}/twitter?url=`,
|
| 415 |
}
|
| 416 |
]
|
| 417 |
});
|
|
|
|
| 540 |
return res.json({ message: e.message });
|
| 541 |
}
|
| 542 |
});
|
| 543 |
+
app.get('/twitter', async (req,res) => {
|
| 544 |
+
try {
|
| 545 |
+
let {url} = req.query
|
| 546 |
+
if (!/https?:\/\/(www\.)?(twitter|X)\.com\/.*\/status/.test(url)) {
|
| 547 |
+
return res.json({ message: 'Invalid URL' });
|
| 548 |
+
}
|
| 549 |
+
let data = await twitterAPI(url)
|
| 550 |
+
return res.json(data)
|
| 551 |
+
} catch (e) {
|
| 552 |
+
console.log(e);
|
| 553 |
+
return res.json({ message: e.message });
|
| 554 |
+
}
|
| 555 |
+
});
|
| 556 |
app.get('/mega', async (req, res) => {
|
| 557 |
try {
|
| 558 |
let { url } = req.query;
|