Update index.js
Browse files
index.js
CHANGED
|
@@ -120,15 +120,25 @@ app.post('/api/toanime', async (req, res) => {
|
|
| 120 |
app.post('/api/waifu2x', async (req, res) => {
|
| 121 |
try {
|
| 122 |
console.log(req.body)
|
| 123 |
-
const {
|
| 124 |
-
if (!
|
| 125 |
if (!format) return res.json({ success: false, message: 'Required an format size!' })
|
| 126 |
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 127 |
|
| 128 |
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
res.setHeader('Content-Type', 'image/jpg')
|
| 131 |
res.send(response)
|
|
|
|
| 132 |
} catch (e) {
|
| 133 |
console.log(e)
|
| 134 |
e = String(e)
|
|
@@ -218,9 +228,9 @@ async function acytoo(text, model) {
|
|
| 218 |
})
|
| 219 |
return res.data
|
| 220 |
}
|
| 221 |
-
async function waifu2x(
|
| 222 |
// data
|
| 223 |
-
let img = await axios.get(urls, { responseType: "arraybuffer"})
|
| 224 |
let random_numbers = Math.floor(Math.random() * 1000)
|
| 225 |
let format
|
| 226 |
if(formats == "Medium") {
|
|
@@ -234,7 +244,7 @@ async function waifu2x(urls, formats) {
|
|
| 234 |
const formData = new FormData()
|
| 235 |
formData.append("denoise", format)
|
| 236 |
formData.append("scale", "true")
|
| 237 |
-
formData.append("file",
|
| 238 |
filename: "images_" + random_numbers.toString().padStart(3, '0') + ".jpg",
|
| 239 |
contentType: "image/jpeg"
|
| 240 |
})
|
|
|
|
| 120 |
app.post('/api/waifu2x', async (req, res) => {
|
| 121 |
try {
|
| 122 |
console.log(req.body)
|
| 123 |
+
const { images, format, status } = req.body
|
| 124 |
+
if (!images) return res.json({ success: false, message: 'Required an images!' })
|
| 125 |
if (!format) return res.json({ success: false, message: 'Required an format size!' })
|
| 126 |
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 127 |
|
| 128 |
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 129 |
+
if (!images && typeof images !== 'string' && !isBase64(images)) {
|
| 130 |
+
const data_img = await axios.request({
|
| 131 |
+
method: "GET",
|
| 132 |
+
url: images
|
| 133 |
+
})
|
| 134 |
+
const response = await waifu2x(data_img, format)
|
| 135 |
+
res.setHeader('Content-Type', 'image/jpg')
|
| 136 |
+
res.send(response)
|
| 137 |
+
} else {
|
| 138 |
+
const response = await waifu2x(Buffer.from(images, "base64", format)
|
| 139 |
res.setHeader('Content-Type', 'image/jpg')
|
| 140 |
res.send(response)
|
| 141 |
+
}
|
| 142 |
} catch (e) {
|
| 143 |
console.log(e)
|
| 144 |
e = String(e)
|
|
|
|
| 228 |
})
|
| 229 |
return res.data
|
| 230 |
}
|
| 231 |
+
async function waifu2x(image, formats) {
|
| 232 |
// data
|
| 233 |
+
//let img = await axios.get(urls, { responseType: "arraybuffer"})
|
| 234 |
let random_numbers = Math.floor(Math.random() * 1000)
|
| 235 |
let format
|
| 236 |
if(formats == "Medium") {
|
|
|
|
| 244 |
const formData = new FormData()
|
| 245 |
formData.append("denoise", format)
|
| 246 |
formData.append("scale", "true")
|
| 247 |
+
formData.append("file", image, {
|
| 248 |
filename: "images_" + random_numbers.toString().padStart(3, '0') + ".jpg",
|
| 249 |
contentType: "image/jpeg"
|
| 250 |
})
|