akkun3704 commited on
Commit
3a98f24
·
1 Parent(s): 5314d44

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +10 -8
index.js CHANGED
@@ -5,6 +5,11 @@ const morgan = require('morgan')
5
  const express = require('express')
6
  const PDFDocument = require('pdfkit')
7
 
 
 
 
 
 
8
  const app = express()
9
  app.set('json spaces', 4)
10
  app.use(morgan('dev'))
@@ -96,15 +101,14 @@ app.get('/yt/convert', async (req, res) => {
96
  if (!hash) return res.json({ success: false, message: 'Invalid hash' })
97
 
98
  const fetchPost = (url, body) => (fetch(url, {
99
- method: 'POST',
100
- body: JSON.stringify(body),
101
  headers: {
102
- 'Content-Type': 'application/*',
103
  'Referer': 'https://y2mate.is/'
104
  }
105
  }))
106
 
107
- const reqTaskId = await fetchPost('https://srvcdn3.2convert.me/api/json', { hash: encodeURIComponent(hash) })
108
  if (!reqTaskId.ok) return res.json({ success: false, message: 'Hash not found' })
109
 
110
  const reqTaskJson = await reqTaskId.json()
@@ -112,8 +116,7 @@ app.get('/yt/convert', async (req, res) => {
112
 
113
  let downloadUrl
114
  while (!downloadUrl) {
115
- const { taskId } = reqTaskJson
116
- const fetchTaskId = await fetchPost('https://srvcdn3.2convert.me/api/json/task', { taskId })
117
  const fetchTaskJson = await fetchTaskId.json()
118
  console.log(fetchTaskJson)
119
  if (fetchTaskJson.status === 'finished') {
@@ -124,7 +127,7 @@ app.get('/yt/convert', async (req, res) => {
124
  await new Promise(resolve => setTimeout(resolve, 1000))
125
  }
126
 
127
- // res.setHeader('Referer', 'https://y2mate.is/')
128
  res.redirect(downloadUrl)
129
  } catch (e) {
130
  console.log(e)
@@ -171,4 +174,3 @@ function toPDF(urls) {
171
  }
172
  })
173
  }
174
-
 
5
  const express = require('express')
6
  const PDFDocument = require('pdfkit')
7
 
8
+ let myIP;
9
+ (async () => {
10
+ myIP = (await (await fetch('https://icanhazip.com/')).text()).trim()
11
+ })()
12
+
13
  const app = express()
14
  app.set('json spaces', 4)
15
  app.use(morgan('dev'))
 
101
  if (!hash) return res.json({ success: false, message: 'Invalid hash' })
102
 
103
  const fetchPost = (url, body) => (fetch(url, {
104
+ method: 'POST', body,
 
105
  headers: {
106
+ 'Content-Type': 'application/x-www-form-urlencoded',
107
  'Referer': 'https://y2mate.is/'
108
  }
109
  }))
110
 
111
+ const reqTaskId = await fetchPost('https://srvcdn3.2convert.me/api/json', `hash=${encodeURIComponent(hash)}`)
112
  if (!reqTaskId.ok) return res.json({ success: false, message: 'Hash not found' })
113
 
114
  const reqTaskJson = await reqTaskId.json()
 
116
 
117
  let downloadUrl
118
  while (!downloadUrl) {
119
+ const fetchTaskId = await fetchPost('https://srvcdn3.2convert.me/api/json/task', `taskId=${reqTaskJson.taskId}`)
 
120
  const fetchTaskJson = await fetchTaskId.json()
121
  console.log(fetchTaskJson)
122
  if (fetchTaskJson.status === 'finished') {
 
127
  await new Promise(resolve => setTimeout(resolve, 1000))
128
  }
129
 
130
+ res.setHeader('X-Forwarded-For', myIP)
131
  res.redirect(downloadUrl)
132
  } catch (e) {
133
  console.log(e)
 
174
  }
175
  })
176
  }