ilhamdev commited on
Commit
b34c222
·
verified ·
1 Parent(s): 8c38b3e

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +10 -7
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]+#[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
- url = url.replace('#', '%23');
138
- if (!megaRegex.test(url)) return res.json({ message: 'Invalid URL' });
139
 
140
- const file = File.fromURL(url);
 
 
 
141
  await file.loadAttributes();
142
 
143
  const data = await file.downloadBuffer();
144
  res.json({
145
- name: file.name, // file name
146
- size: file.size, // file size in bytes
147
- contents: data.toString() // file contents
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);