Khrisna commited on
Commit
239892a
·
1 Parent(s): 5a347b8

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +17 -16
index.js CHANGED
@@ -125,9 +125,20 @@ app.post('/api/waifu2x', async (req, res) => {
125
  if (!status) return res.json({ success: false, message: 'Required an status text!' })
126
 
127
  if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
128
- const response = waifu2x(url, format)
 
 
 
 
 
 
 
 
 
 
 
129
  res.setHeader('Content-Type', 'image/jpg')
130
- res.send(response)
131
  } catch (e) {
132
  console.log(e)
133
  e = String(e)
@@ -198,6 +209,7 @@ async function acytoo(text, model) {
198
  async function waifu2x(urls, formats) {
199
  // data
200
  let img = await axios.get(urls, { responseType: "arraybuffer"})
 
201
  let format
202
  if(formats == "Medium") {
203
  format = "1"
@@ -211,7 +223,7 @@ async function waifu2x(urls, formats) {
211
  formData.append("denoise", format)
212
  formData.append("scale", "true")
213
  formData.append("file", img.data, {
214
- filename: "images_.jpg",
215
  contentType: "image/jpeg"
216
  })
217
 
@@ -238,17 +250,6 @@ async function waifu2x(urls, formats) {
238
  })
239
 
240
  if(!ress.data.finished) return "Images Not Supported!!"
241
- // setelah mendapatkan mengecek hash, hash akan di convert ke sebuah image
242
- const results = await axios.request({
243
- method: "GET",
244
- url: "https://api.alcaamado.es/api/v2/waifu2x/get?hash=" + response.data.hash + "&type=jpg",
245
- headers: {
246
- "Accept": "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
247
- "Content-Type": "image/jpg",
248
- "Referer": "https://waifu2x.pro/",
249
- "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"
250
- },
251
- responseType: "arraybuffer"
252
- })
253
- return results.data
254
  }
 
125
  if (!status) return res.json({ success: false, message: 'Required an status text!' })
126
 
127
  if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
128
+ const response = await waifu2x(url, format)
129
+ const images = await axios.request({
130
+ method: "GET",
131
+ url: "https://api.alcaamado.es/api/v2/waifu2x/get?hash=" + response + "&type=jpg",
132
+ headers: {
133
+ "Accept": "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
134
+ "Content-Type": "image/jpg",
135
+ "Referer": "https://waifu2x.pro/",
136
+ "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"
137
+ },
138
+ responseType: "arraybuffer"
139
+ })
140
  res.setHeader('Content-Type', 'image/jpg')
141
+ res.send(images.data)
142
  } catch (e) {
143
  console.log(e)
144
  e = String(e)
 
209
  async function waifu2x(urls, formats) {
210
  // data
211
  let img = await axios.get(urls, { responseType: "arraybuffer"})
212
+ let random_numbers = Math.floor(Math.random() * 1000)
213
  let format
214
  if(formats == "Medium") {
215
  format = "1"
 
223
  formData.append("denoise", format)
224
  formData.append("scale", "true")
225
  formData.append("file", img.data, {
226
+ filename: "images_" + random_numbers.toString().padStart(3, '0') + ".jpg",
227
  contentType: "image/jpeg"
228
  })
229
 
 
250
  })
251
 
252
  if(!ress.data.finished) return "Images Not Supported!!"
253
+
254
+ return response.data.hash
 
 
 
 
 
 
 
 
 
 
 
255
  }