Spaces:
Paused
Paused
Fix mediafire
Browse files
index.js
CHANGED
|
@@ -89,10 +89,17 @@ const utils = {
|
|
| 89 |
if (browser) await browser.close()
|
| 90 |
}
|
| 91 |
},
|
| 92 |
-
getMediafireDownloadLink: async (url) =>
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
)[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
getError: (e) =>
|
| 97 |
String(e).startsWith('[object ') ? 'Internal Server Error' : String(e),
|
| 98 |
isBase64: (str) => {
|
|
@@ -244,7 +251,12 @@ app.all(/^\/mediafire(\/d(ownload|l))?$/, async (req, res) => {
|
|
| 244 |
if (_type && ['dl', 'download'].includes(_type.slice(1))) {
|
| 245 |
const url = `https://mediafire.com/file/${obj.id}`
|
| 246 |
const result = await utils.getMediafireDownloadLink(url)
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
return
|
| 249 |
}
|
| 250 |
|
|
@@ -461,4 +473,6 @@ app.all(/^\/y(outube|t)(\/(d(ownload|l)|search)?)?/, async (req, res) => {
|
|
| 461 |
// app.use((req, res, next) => {})
|
| 462 |
|
| 463 |
const PORT = process.env.PORT || 7860
|
| 464 |
-
app.listen(PORT, () =>
|
|
|
|
|
|
|
|
|
| 89 |
if (browser) await browser.close()
|
| 90 |
}
|
| 91 |
},
|
| 92 |
+
getMediafireDownloadLink: async (url) => {
|
| 93 |
+
let resp = await fetch(url)
|
| 94 |
+
let html = await resp.text()
|
| 95 |
+
let dl = html.match(/href="(.*?)".*id="downloadButton"/)?.[1]
|
| 96 |
+
return dl
|
| 97 |
+
? {
|
| 98 |
+
cookies: resp.headers.get('set-cookie'),
|
| 99 |
+
url: dl
|
| 100 |
+
}
|
| 101 |
+
: false
|
| 102 |
+
},
|
| 103 |
getError: (e) =>
|
| 104 |
String(e).startsWith('[object ') ? 'Internal Server Error' : String(e),
|
| 105 |
isBase64: (str) => {
|
|
|
|
| 251 |
if (_type && ['dl', 'download'].includes(_type.slice(1))) {
|
| 252 |
const url = `https://mediafire.com/file/${obj.id}`
|
| 253 |
const result = await utils.getMediafireDownloadLink(url)
|
| 254 |
+
if (!result)
|
| 255 |
+
return res
|
| 256 |
+
.status(400)
|
| 257 |
+
.json({ success: false, message: 'Failed to get the download link' })
|
| 258 |
+
res.setHeader('Set-Cookie', result.cookies)
|
| 259 |
+
res.redirect(result.url)
|
| 260 |
return
|
| 261 |
}
|
| 262 |
|
|
|
|
| 473 |
// app.use((req, res, next) => {})
|
| 474 |
|
| 475 |
const PORT = process.env.PORT || 7860
|
| 476 |
+
app.listen(PORT, () =>
|
| 477 |
+
console.log(`App running on port ${PORT}`)
|
| 478 |
+
)
|