Update index.js
Browse files
index.js
CHANGED
@@ -10,6 +10,7 @@ const ytdl = require('ytdl-core')
|
|
10 |
const tfjs = require('@tensorflow/tfjs-node')
|
11 |
const nsfwjs = require('nsfwjs')
|
12 |
const jpegjs = require('jpeg-js')
|
|
|
13 |
const fileType = require("file-type")
|
14 |
//const Stress = require('./lib/ddos.js');
|
15 |
//const { BingChat } = (await import("bing-chat")).default
|
@@ -188,6 +189,41 @@ app.post('/api/upscaler', async (req, res) => {
|
|
188 |
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
189 |
}
|
190 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
app.post('/api/nsfw-check', async (req, res) => {
|
192 |
try {
|
193 |
console.log(req.body)
|
@@ -477,6 +513,42 @@ async function processImage(image, denoise, scale, format, type) {
|
|
477 |
});
|
478 |
}
|
479 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
480 |
async function check_nsfw(buffer) {
|
481 |
let _model = await load_model()
|
482 |
const convert = async (img) => {
|
|
|
10 |
const tfjs = require('@tensorflow/tfjs-node')
|
11 |
const nsfwjs = require('nsfwjs')
|
12 |
const jpegjs = require('jpeg-js')
|
13 |
+
const jimp = require('jimp')
|
14 |
const fileType = require("file-type")
|
15 |
//const Stress = require('./lib/ddos.js');
|
16 |
//const { BingChat } = (await import("bing-chat")).default
|
|
|
189 |
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
190 |
}
|
191 |
})
|
192 |
+
app.post('/api/upscaler', async (req, res) => {
|
193 |
+
try {
|
194 |
+
console.log(req.body)
|
195 |
+
const { status images } = req.body
|
196 |
+
if (!images) return res.json({ success: false, message: 'Required an images!' })
|
197 |
+
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
198 |
+
|
199 |
+
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
200 |
+
if (/^(https?|http):\/\//i.test(images)) {
|
201 |
+
const data_img = await axios.request({
|
202 |
+
method: "GET",
|
203 |
+
url: images,
|
204 |
+
responseType: "arraybuffer"
|
205 |
+
})
|
206 |
+
const imageBase64 = Buffer.from(data_img.data, 'binary').toString('base64');
|
207 |
+
const response = await processImageAnime(imageBase64);
|
208 |
+
const type_img = await fileType.fromBuffer(response)
|
209 |
+
res.setHeader('Content-Type', type_img.mime)
|
210 |
+
res.send(response)
|
211 |
+
} else if (images && typeof images == 'string' && isBase64(images)) {
|
212 |
+
const response = await processImageAnime(images)
|
213 |
+
const type_img = await fileType.fromBuffer(response)
|
214 |
+
res.setHeader('Content-Type', type_img.mime)
|
215 |
+
res.send(response)
|
216 |
+
} else {
|
217 |
+
res.json({
|
218 |
+
success: false, message: 'No url or base64 detected!!'
|
219 |
+
})
|
220 |
+
}
|
221 |
+
} catch (e) {
|
222 |
+
console.log(e)
|
223 |
+
e = String(e)
|
224 |
+
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
225 |
+
}
|
226 |
+
})
|
227 |
app.post('/api/nsfw-check', async (req, res) => {
|
228 |
try {
|
229 |
console.log(req.body)
|
|
|
513 |
});
|
514 |
}
|
515 |
|
516 |
+
async function processImageAnime(inputBuffer) {
|
517 |
+
try {
|
518 |
+
// const base64String = Buffer.from(inputBuffer, 'binary').toString('base64');
|
519 |
+
const apiResponse = await axios.post('https://www.drawever.com/api/photo-to-anime', {
|
520 |
+
data: `data:image/png;base64,${inputBuffer}`,
|
521 |
+
}, {
|
522 |
+
headers: {
|
523 |
+
'Content-Type': 'application/json',
|
524 |
+
},
|
525 |
+
});
|
526 |
+
|
527 |
+
const link = 'https://www.drawever.com' + (apiResponse.data.urls[1] || apiResponse.data.urls[0]);
|
528 |
+
const {
|
529 |
+
data: imageBuffer
|
530 |
+
} = await axios.get(link, {
|
531 |
+
responseType: 'arraybuffer'
|
532 |
+
});
|
533 |
+
|
534 |
+
const image = await Jimp.read(imageBuffer);
|
535 |
+
const blackBackground = new Jimp(image.bitmap.width, 50, 0x000000FF);
|
536 |
+
const font = await Jimp.loadFont(Jimp.FONT_SANS_16_WHITE);
|
537 |
+
blackBackground.print(font, 10, 10, "SadTeams", blackBackground.bitmap.width - 20);
|
538 |
+
image.composite(blackBackground, 0, image.bitmap.height - blackBackground.bitmap.height, {
|
539 |
+
mode: Jimp.BLEND_SOURCE_OVER,
|
540 |
+
opacityDest: 0.5,
|
541 |
+
opacitySource: 1
|
542 |
+
});
|
543 |
+
|
544 |
+
const outputBuffer = await image.getBufferAsync(Jimp.MIME_JPEG);
|
545 |
+
return outputBuffer;
|
546 |
+
} catch (err) {
|
547 |
+
console.error(err);
|
548 |
+
throw err;
|
549 |
+
}
|
550 |
+
}
|
551 |
+
|
552 |
async function check_nsfw(buffer) {
|
553 |
let _model = await load_model()
|
554 |
const convert = async (img) => {
|