rippanteq7 commited on
Commit
36c1eed
·
verified ·
1 Parent(s): 7054a3f

Fix mediafire

Browse files

I hv no idea, u guys must fill in the cookie headers if you want to download

Files changed (1) hide show
  1. index.js +9 -24
index.js CHANGED
@@ -96,7 +96,7 @@ const utils = {
96
  return dl
97
  ? {
98
  cookies: resp.headers.get('set-cookie'),
99
- url: dl
100
  }
101
  : false
102
  },
@@ -238,28 +238,14 @@ app.all(/^\/(brat|carbon)/, async (req, res) => {
238
  }
239
  })
240
 
241
- app.all(/^\/mediafire(\/d(ownload|l))?$/, async (req, res) => {
242
  if (!['GET', 'POST'].includes(req.method))
243
  return res
244
  .status(405)
245
  .json({ success: false, message: 'Method Not Allowed' })
246
 
247
  try {
248
- const _type = req.params[0]
249
  const obj = req.allParams
250
-
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
-
263
  if (!obj.url)
264
  return res
265
  .status(400)
@@ -277,19 +263,20 @@ app.all(/^\/mediafire(\/d(ownload|l))?$/, async (req, res) => {
277
  .status(400)
278
  .json({ success: false, message: 'Cannot find file id' })
279
 
280
- const result = {}
281
- const data = await utils.fetchMediafireAPI(id)
 
 
282
  if (data.error)
283
  return res.status(400).json({ success: false, message: data.message })
284
 
285
  for (let [key, val] of Object.entries(data.file_info)) {
286
  if (key === 'links') continue
287
- key = key.split('_')[0]
288
  if (key === 'size') val = utils.formatSize(val)
 
289
  result[key] = val
290
  }
291
- result['download'] =
292
- `https://${req.hostname + req.originalUrl.split('?')[0]}/dl?id=${id}`
293
  res.json({ success: true, result })
294
  } catch (e) {
295
  console.log(e)
@@ -473,6 +460,4 @@ app.all(/^\/y(outube|t)(\/(d(ownload|l)|search)?)?/, async (req, res) => {
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
- )
 
96
  return dl
97
  ? {
98
  cookies: resp.headers.get('set-cookie'),
99
+ download: dl
100
  }
101
  : false
102
  },
 
238
  }
239
  })
240
 
241
+ app.all('/mediafire', async (req, res) => {
242
  if (!['GET', 'POST'].includes(req.method))
243
  return res
244
  .status(405)
245
  .json({ success: false, message: 'Method Not Allowed' })
246
 
247
  try {
 
248
  const obj = req.allParams
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  if (!obj.url)
250
  return res
251
  .status(400)
 
263
  .status(400)
264
  .json({ success: false, message: 'Cannot find file id' })
265
 
266
+ const [data, result] = await Promise.all([
267
+ utils.fetchMediafireAPI(id),
268
+ utils.getMediafireDownloadLink(obj.url)
269
+ ])
270
  if (data.error)
271
  return res.status(400).json({ success: false, message: data.message })
272
 
273
  for (let [key, val] of Object.entries(data.file_info)) {
274
  if (key === 'links') continue
 
275
  if (key === 'size') val = utils.formatSize(val)
276
+ key = key.split('_')[0]
277
  result[key] = val
278
  }
279
+
 
280
  res.json({ success: true, result })
281
  } catch (e) {
282
  console.log(e)
 
460
  // app.use((req, res, next) => {})
461
 
462
  const PORT = process.env.PORT || 7860
463
+ app.listen(PORT, () => console.log(`App running on port ${PORT}`))