Update index.js
Browse files
index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
const yts = require('yt-search')
|
| 2 |
const morgan = require('morgan')
|
| 3 |
const express = require('express')
|
|
|
|
| 4 |
|
| 5 |
const ytIdRegex = /(?:http(?:s|):\/\/|)(?:(?:www\.|)?youtube(?:\-nocookie|)\.com\/(?:shorts\/)?(?:watch\?.*(?:|\&)v=|embed\/|v\/)?|youtu\.be\/)([-_0-9A-Za-z]{11})/
|
| 6 |
-
|
| 7 |
const post = (url, form, headers = {}) => fetch(url, {
|
| 8 |
method: 'post',
|
| 9 |
body: new URLSearchParams(form),
|
|
@@ -112,5 +113,24 @@ const app = express()
|
|
| 112 |
console.log(e)
|
| 113 |
res.json({ message: e })
|
| 114 |
}
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
.listen(7860, () => console.log('App running on port 7860'))
|
|
|
|
| 1 |
const yts = require('yt-search')
|
| 2 |
const morgan = require('morgan')
|
| 3 |
const express = require('express')
|
| 4 |
+
const { File } = require('megajs')
|
| 5 |
|
| 6 |
const ytIdRegex = /(?:http(?:s|):\/\/|)(?:(?:www\.|)?youtube(?:\-nocookie|)\.com\/(?:shorts\/)?(?:watch\?.*(?:|\&)v=|embed\/|v\/)?|youtu\.be\/)([-_0-9A-Za-z]{11})/
|
| 7 |
+
const megaRegex = /https:\/\/mega\.nz\/file\/[A-Za-z0-9]+#[A-Za-z0-9-_]+/;
|
| 8 |
const post = (url, form, headers = {}) => fetch(url, {
|
| 9 |
method: 'post',
|
| 10 |
body: new URLSearchParams(form),
|
|
|
|
| 113 |
console.log(e)
|
| 114 |
res.json({ message: e })
|
| 115 |
}
|
| 116 |
+
})
|
| 117 |
+
.get('/megajs', async (req, res) => {
|
| 118 |
+
try {
|
| 119 |
+
const { url } = req.query;
|
| 120 |
+
if (!megaRegex.test(url)) return res.json({ message: 'Invalid URL' });
|
| 121 |
+
|
| 122 |
+
const file = File.fromURL(url);
|
| 123 |
+
await file.loadAttributes();
|
| 124 |
+
|
| 125 |
+
const data = await file.downloadBuffer();
|
| 126 |
+
res.json({
|
| 127 |
+
name: file.name, // file name
|
| 128 |
+
size: file.size, // file size in bytes
|
| 129 |
+
contents: data.toString() // file contents
|
| 130 |
+
});
|
| 131 |
+
} catch (error) {
|
| 132 |
+
console.error(error);
|
| 133 |
+
res.json({ message: error.message });
|
| 134 |
+
}
|
| 135 |
+
})
|
| 136 |
.listen(7860, () => console.log('App running on port 7860'))
|