Khrisna commited on
Commit
2af4d6d
·
1 Parent(s): 7c7d7cf

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +74 -0
index.js CHANGED
@@ -115,6 +115,24 @@ app.post('/api/toanime', async (req, res) => {
115
  res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
116
  }
117
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  const PORT = process.env.PORT || 7860
120
  app.listen(PORT, () => console.log('App running on port', PORT))
@@ -175,4 +193,60 @@ async function acytoo(text, model) {
175
  }
176
  })
177
  return res.data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  }
 
115
  res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
116
  }
117
  })
118
+ app.post('/api/waifu2x', async (req, res) => {
119
+ try {
120
+ console.log(req.body)
121
+ const { url, format, status } = req.body
122
+ if (!url) return res.json({ success: false, message: 'Required an url!' })
123
+ if (!format) return res.json({ success: false, message: 'Required an format size!' })
124
+ if (!status) return res.json({ success: false, message: 'Required an status text!' })
125
+
126
+ if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
127
+ const response = waifu2x(url, format)
128
+ res.setHeader('Content-Type', 'image/jpg')
129
+ res.send(response)
130
+ } catch (e) {
131
+ console.log(e)
132
+ e = String(e)
133
+ res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
134
+ }
135
+ })
136
 
137
  const PORT = process.env.PORT || 7860
138
  app.listen(PORT, () => console.log('App running on port', PORT))
 
193
  }
194
  })
195
  return res.data
196
+ }
197
+ async function waifu2x(urls, formats) {
198
+ // data
199
+ let img = await axios.get(urls, { responseType: "arraybuffer"})
200
+ let format
201
+ if(formats == "Medium") {
202
+ format = "1"
203
+ } else if(formats == "High") {
204
+ format = "2"
205
+ } else if(!formats) {
206
+ format = "0"
207
+ }
208
+ // memasukan data api
209
+ const formData = new FormData()
210
+ formData.append("denoise", format)
211
+ formData.append("scale", "true")
212
+ formData.append("file", img.data, {
213
+ filename: "images_.jpg",
214
+ contentType: "image/jpeg"
215
+ })
216
+
217
+ // request ke api untuk mendapatkan hash nya
218
+ const response = await axios.request({
219
+ method: "POST",
220
+ url: "https://api.alcaamado.es/api/v1/waifu2x/convert",
221
+ data: formData,
222
+ headers: {
223
+ "Accept": "application/json",
224
+ "Referer": "https://waifu2x.pro/",
225
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"
226
+ }
227
+ })
228
+
229
+ const ress = await axios.request({
230
+ method: "GET",
231
+ url: "https://api.alcaamado.es/api/v2/waifu2x/check?hash=" + response.data.hash,
232
+ headers: {
233
+ "Accept": "application/json",
234
+ "Referer": "https://waifu2x.pro/",
235
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"
236
+ }
237
+ })
238
+
239
+ if(!ress.data.finished) return "Images Not Supported!!"
240
+ // setelah mendapatkan mengecek hash, hash akan di convert ke sebuah image
241
+ const results = await axios.request({
242
+ method: "GET",
243
+ url: "https://api.alcaamado.es/api/v2/waifu2x/get?hash=" + response.data.hash + "&type=jpg",
244
+ headers: {
245
+ "Accept": "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
246
+ "Content-Type": "image/jpg",
247
+ "Referer": "https://waifu2x.pro/",
248
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"
249
+ }
250
+ })
251
+ return results.data
252
  }