Update index.js
Browse files4 unmodified lines5678891011122 unmodified lines1341351361371381371381391401401411421431441451461471451461471481491501511521534 unmodified lines
// Regex untuk mengidentifikasi URL YouTube dan Megaconst ytIdRegex = /(?:http(?:s|):\/\/|)(?:(?:www\.|)?youtube(?:\-nocookie|)\.com\/(?:shorts\/)?(?:watch\?.*(?:|\&)v=|embed\/|v\/)?|youtu\.be\/)([-_0-9A-Za-z]{11})/;const megaRegex = /https:\/\/mega\.nz\/file\/[A-Za-z0-9]+#[A-Za-z0-9-_]+/;const megaRegex = /https:\/\/mega\.nz\/file\/([A-Za-z0-9]+)(?:#([A-Za-z0-9-_]+))?/;
// Fungsi untuk melakukan HTTP POST requestconst post = async (url, form, headers = {}) => {122 unmodified lines .get('/megajs', async (req, res) => { try { let { url } = req.query; url = url.replace('#', '%23'); if (!megaRegex.test(url)) return res.json({ message: 'Invalid URL' }); const match = url.match(megaRegex); if (!match) return res.json({ message: 'Invalid URL' });
const file = File.fromURL(url); const id = match[1]; const query = match[2] || ''; // Jika tidak ada query, gunakan string kosong
const file = File.fromURL(`https://mega.nz/file/${id}#${query}`); await file.loadAttributes();
const data = await file.downloadBuffer(); res.json({ name: file.name, // file name size: file.size, // file size in bytes contents: data.toString() // file contents name: file.name, // Nama file size: file.size, // Ukuran file dalam byte contents: data.toString() // Konten file dalam format string }); } catch (error) { console.error(error);index.js+10-7