Update index.js
Browse files
index.js
CHANGED
|
@@ -5,7 +5,7 @@ const { File } = require('megajs');
|
|
| 5 |
|
| 6 |
// Regex untuk mengidentifikasi URL YouTube dan Mega
|
| 7 |
const ytIdRegex = /(?:http(?:s|):\/\/|)(?:(?:www\.|)?youtube(?:\-nocookie|)\.com\/(?:shorts\/)?(?:watch\?.*(?:|\&)v=|embed\/|v\/)?|youtu\.be\/)([-_0-9A-Za-z]{11})/;
|
| 8 |
-
const megaRegex = /https:\/\/mega\.nz\/file\/[A-Za-z0-9]
|
| 9 |
|
| 10 |
// Fungsi untuk melakukan HTTP POST request
|
| 11 |
const post = async (url, form, headers = {}) => {
|
|
@@ -134,17 +134,20 @@ const app = express()
|
|
| 134 |
.get('/megajs', async (req, res) => {
|
| 135 |
try {
|
| 136 |
let { url } = req.query;
|
| 137 |
-
|
| 138 |
-
if (!
|
| 139 |
|
| 140 |
-
const
|
|
|
|
|
|
|
|
|
|
| 141 |
await file.loadAttributes();
|
| 142 |
|
| 143 |
const data = await file.downloadBuffer();
|
| 144 |
res.json({
|
| 145 |
-
name: file.name, // file
|
| 146 |
-
size: file.size, // file
|
| 147 |
-
contents: data.toString() // file
|
| 148 |
});
|
| 149 |
} catch (error) {
|
| 150 |
console.error(error);
|
|
|
|
| 5 |
|
| 6 |
// Regex untuk mengidentifikasi URL YouTube dan Mega
|
| 7 |
const ytIdRegex = /(?:http(?:s|):\/\/|)(?:(?:www\.|)?youtube(?:\-nocookie|)\.com\/(?:shorts\/)?(?:watch\?.*(?:|\&)v=|embed\/|v\/)?|youtu\.be\/)([-_0-9A-Za-z]{11})/;
|
| 8 |
+
const megaRegex = /https:\/\/mega\.nz\/file\/([A-Za-z0-9]+)(?:#([A-Za-z0-9-_]+))?/;
|
| 9 |
|
| 10 |
// Fungsi untuk melakukan HTTP POST request
|
| 11 |
const post = async (url, form, headers = {}) => {
|
|
|
|
| 134 |
.get('/megajs', async (req, res) => {
|
| 135 |
try {
|
| 136 |
let { url } = req.query;
|
| 137 |
+
const match = url.match(megaRegex);
|
| 138 |
+
if (!match) return res.json({ message: 'Invalid URL' });
|
| 139 |
|
| 140 |
+
const id = match[1];
|
| 141 |
+
const query = match[2] || ''; // Jika tidak ada query, gunakan string kosong
|
| 142 |
+
|
| 143 |
+
const file = File.fromURL(`https://mega.nz/file/${id}#${query}`);
|
| 144 |
await file.loadAttributes();
|
| 145 |
|
| 146 |
const data = await file.downloadBuffer();
|
| 147 |
res.json({
|
| 148 |
+
name: file.name, // Nama file
|
| 149 |
+
size: file.size, // Ukuran file dalam byte
|
| 150 |
+
contents: data.toString() // Konten file dalam format string
|
| 151 |
});
|
| 152 |
} catch (error) {
|
| 153 |
console.error(error);
|