Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -1,55 +1,71 @@
|
|
|
|
|
| 1 |
const os = require('os')
|
|
|
|
|
|
|
| 2 |
const bytes = require('bytes')
|
| 3 |
const sharp = require('sharp')
|
| 4 |
const morgan = require('morgan')
|
| 5 |
const express = require('express')
|
|
|
|
| 6 |
const PDFDocument = require('pdfkit')
|
| 7 |
-
const
|
| 8 |
-
const
|
| 9 |
-
|
| 10 |
-
const
|
| 11 |
-
const
|
| 12 |
-
|
| 13 |
-
//const Stress = require('./lib/ddos.js');
|
| 14 |
-
//const { BingChat } = (await import("bing-chat")).default
|
| 15 |
-
const { acytoo, chatgpt_4 } = require("./lib/chatgpt.js")
|
| 16 |
-
const { sss_instagram, gramvio } = require("./lib/instagram.js")
|
| 17 |
-
const { allToJpg } = require("./lib/convertFormat.js")
|
| 18 |
-
const apikey = "@SadTeam77"
|
| 19 |
|
| 20 |
const app = express()
|
| 21 |
app.set('json spaces', 4)
|
| 22 |
app.use(morgan('dev'))
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
app.use((req, res, next) => {
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
})
|
| 28 |
|
|
|
|
|
|
|
| 29 |
app.all('/', (req, res) => {
|
| 30 |
const status = {}
|
| 31 |
const used = process.memoryUsage()
|
| 32 |
for (let key in used) status[key] = formatSize(used[key])
|
| 33 |
|
|
|
|
|
|
|
|
|
|
| 34 |
const totalmem = os.totalmem()
|
| 35 |
const freemem = os.freemem()
|
| 36 |
status.memoryUsage = `${formatSize(totalmem - freemem)} / ${formatSize(totalmem)}`
|
| 37 |
-
|
| 38 |
-
console.log("YOUR IP: " + req.ip)
|
| 39 |
|
| 40 |
res.json({
|
| 41 |
-
creator:
|
| 42 |
-
message: 'Hello World
|
| 43 |
uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4],
|
| 44 |
status
|
| 45 |
})
|
| 46 |
})
|
| 47 |
|
| 48 |
-
app.
|
|
|
|
|
|
|
| 49 |
try {
|
| 50 |
-
console.log(req.body)
|
| 51 |
const { images } = req.body
|
| 52 |
-
if (!images) return res.json({ success: false, message: 'Required an array image url' })
|
| 53 |
|
| 54 |
const buffer = await toPDF(images)
|
| 55 |
res.setHeader('Content-Disposition', `attachment; filename=${Math.random().toString(36).slice(2)}.pdf`)
|
|
@@ -59,350 +75,236 @@ app.post('/imagetopdf', async (req, res) => {
|
|
| 59 |
} catch (e) {
|
| 60 |
console.log(e)
|
| 61 |
e = String(e)
|
| 62 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 63 |
}
|
| 64 |
})
|
| 65 |
|
| 66 |
-
app.
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
const { prompt, model, status } = req.body
|
| 70 |
-
if (!prompt) return res.json({ success: false, message: 'Required an prompt text!' })
|
| 71 |
-
if (!model) return res.json({ success: false, message: 'Required an model version!' })
|
| 72 |
-
if (!status) return res.json({ success: false, message: 'Required an prompt text!' })
|
| 73 |
-
|
| 74 |
-
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 75 |
-
if(model == "gpt-4") {
|
| 76 |
-
const response = await axios.request({
|
| 77 |
-
method: "GET",
|
| 78 |
-
url: "https://aemt.me/gpt4?text=" + prompt
|
| 79 |
-
})
|
| 80 |
-
res.json({
|
| 81 |
-
status: "ok",
|
| 82 |
-
result: response.data.result
|
| 83 |
-
})
|
| 84 |
-
} else if(model == "gpt-3.5") {
|
| 85 |
-
const response = await acytoo(prompt, "gpt-4")
|
| 86 |
-
res.json({
|
| 87 |
-
status: "ok",
|
| 88 |
-
result: response
|
| 89 |
-
})
|
| 90 |
-
} else if(model == "gpt-3") {
|
| 91 |
-
const response = await acytoo(prompt, "gpt-3.5-turbo")
|
| 92 |
-
res.json({
|
| 93 |
-
status: "ok",
|
| 94 |
-
result: response
|
| 95 |
-
})
|
| 96 |
-
}
|
| 97 |
-
} catch (e) {
|
| 98 |
-
console.log(e)
|
| 99 |
-
e = String(e)
|
| 100 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 101 |
-
}
|
| 102 |
-
})
|
| 103 |
-
app.post('/api/chatgpt2', async (req, res) => {
|
| 104 |
-
try {
|
| 105 |
-
console.log(req.body)
|
| 106 |
-
const { data, prompt, status } = req.body
|
| 107 |
-
if (!data) return res.json({ success: false, message: 'Required an data text!' })
|
| 108 |
-
if (!prompt) return res.json({ success: false, message: 'Required an prompt text!' })
|
| 109 |
-
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 110 |
-
|
| 111 |
-
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 112 |
-
const response = await axios.request({
|
| 113 |
-
method: "GET",
|
| 114 |
-
url: `https://aemt.me/prompt/gpt?prompt=${data}&text=${prompt}`
|
| 115 |
-
})
|
| 116 |
-
res.json({
|
| 117 |
-
status: "ok",
|
| 118 |
-
result: response.data.result
|
| 119 |
-
})
|
| 120 |
-
} catch (e) {
|
| 121 |
-
console.log(e)
|
| 122 |
-
e = String(e)
|
| 123 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 124 |
-
}
|
| 125 |
-
})
|
| 126 |
-
app.post('/api/toanime', async (req, res) => {
|
| 127 |
-
try {
|
| 128 |
-
console.log(req.body)
|
| 129 |
-
const { url, status } = req.body
|
| 130 |
-
if (!url) return res.json({ success: false, message: 'Required an url!' })
|
| 131 |
-
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 132 |
-
|
| 133 |
-
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 134 |
-
const response = await axios.request({
|
| 135 |
-
method: "GET",
|
| 136 |
-
url: "https://aemt.me/toanime?url=" + url
|
| 137 |
-
})
|
| 138 |
-
const image = await axios.request({
|
| 139 |
-
method: "GET",
|
| 140 |
-
url: response.data.url.img_crop_single,
|
| 141 |
-
responseType: "arraybuffer"
|
| 142 |
-
})
|
| 143 |
-
res.setHeader('Content-Type', 'image/jpeg')
|
| 144 |
-
res.send(image.data)
|
| 145 |
-
} catch (e) {
|
| 146 |
-
console.log(e)
|
| 147 |
-
e = String(e)
|
| 148 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 149 |
-
}
|
| 150 |
-
})
|
| 151 |
-
app.post('/api/upscaler', async (req, res) => {
|
| 152 |
try {
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 163 |
-
if (/^(https?|http):\/\//i.test(images)) {
|
| 164 |
-
const data_img = await axios.request({
|
| 165 |
-
method: "GET",
|
| 166 |
-
url: images,
|
| 167 |
-
responseType: "arraybuffer"
|
| 168 |
-
})
|
| 169 |
-
const response = await processImageUpscaler(data_img.data, denoise, scale, format, type)
|
| 170 |
-
const type_img = await fileType.fromBuffer(response)
|
| 171 |
-
res.setHeader('Content-Type', type_img.mime)
|
| 172 |
-
res.send(response)
|
| 173 |
-
} else if (images && typeof images == 'string' && isBase64(images)) {
|
| 174 |
-
const response = await processImage(Buffer.from(images, "base64"), denoise, scale, format, type)
|
| 175 |
-
const type_img = await fileType.fromBuffer(response)
|
| 176 |
-
res.setHeader('Content-Type', type_img.mime)
|
| 177 |
-
res.send(response)
|
| 178 |
-
} else {
|
| 179 |
-
res.json({
|
| 180 |
-
success: false, message: 'No url or base64 detected!!'
|
| 181 |
-
})
|
| 182 |
-
}
|
| 183 |
} catch (e) {
|
| 184 |
console.log(e)
|
| 185 |
e = String(e)
|
| 186 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 187 |
}
|
| 188 |
})
|
| 189 |
|
| 190 |
-
app.
|
|
|
|
|
|
|
| 191 |
try {
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
const type_img = await fileType.fromBuffer(response)
|
| 207 |
-
res.setHeader('Content-Type', type_img.mime)
|
| 208 |
-
res.send(response)
|
| 209 |
-
} else if (images && typeof images == 'string' && isBase64(images)) {
|
| 210 |
-
const response = await processImage2Img(Buffer.from(images, "base64"), prompt)
|
| 211 |
-
const type_img = await fileType.fromBuffer(response)
|
| 212 |
-
res.setHeader('Content-Type', type_img.mime)
|
| 213 |
-
res.send(response)
|
| 214 |
-
} else {
|
| 215 |
-
res.json({
|
| 216 |
-
success: false, message: 'No url or base64 detected!!'
|
| 217 |
-
})
|
| 218 |
-
}
|
| 219 |
} catch (e) {
|
| 220 |
console.log(e)
|
| 221 |
e = String(e)
|
| 222 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 223 |
}
|
| 224 |
})
|
| 225 |
-
|
|
|
|
| 226 |
try {
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 231 |
-
|
| 232 |
-
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 233 |
-
if (/^(https?|http):\/\//i.test(images)) {
|
| 234 |
-
const data_img = await axios.request({
|
| 235 |
-
method: "GET",
|
| 236 |
-
url: images,
|
| 237 |
-
responseType: "arraybuffer"
|
| 238 |
-
})
|
| 239 |
-
const imageBase64 = Buffer.from(data_img.data, 'binary').toString('base64');
|
| 240 |
-
const response = await processImageAnime(imageBase64);
|
| 241 |
-
const type_img = await fileType.fromBuffer(response)
|
| 242 |
-
res.setHeader('Content-Type', type_img.mime)
|
| 243 |
-
res.send(response)
|
| 244 |
-
} else if (images && typeof images == 'string' && isBase64(images)) {
|
| 245 |
-
const response = await processImageAnime(images)
|
| 246 |
-
const type_img = await fileType.fromBuffer(response)
|
| 247 |
-
res.setHeader('Content-Type', type_img.mime)
|
| 248 |
-
res.send(response)
|
| 249 |
-
} else {
|
| 250 |
-
res.json({
|
| 251 |
-
success: false, message: 'No url or base64 detected!!'
|
| 252 |
-
})
|
| 253 |
-
}
|
| 254 |
} catch (e) {
|
| 255 |
-
|
| 256 |
-
e = String(e)
|
| 257 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 258 |
}
|
| 259 |
})
|
| 260 |
|
| 261 |
-
app.
|
|
|
|
|
|
|
| 262 |
try {
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 269 |
-
const response = await gramvio(username)
|
| 270 |
-
res.json({
|
| 271 |
-
status: "ok",
|
| 272 |
-
result: response
|
| 273 |
-
})
|
| 274 |
} catch (e) {
|
| 275 |
console.log(e)
|
| 276 |
e = String(e)
|
| 277 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 278 |
}
|
| 279 |
})
|
| 280 |
-
app.post('/api/instagram/download', async (req, res) => {
|
| 281 |
-
try {
|
| 282 |
-
console.log(req.body)
|
| 283 |
-
const { url, status } = req.body
|
| 284 |
-
if (!url) return res.json({ success: false, message: 'Required an url!' })
|
| 285 |
-
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 286 |
|
| 287 |
-
|
| 288 |
-
|
| 289 |
res.json({
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
}
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
console.log(req.body)
|
| 302 |
-
const { url, status } = req.body
|
| 303 |
-
if (!url) return res.json({ success: false, message: 'Required an url!' })
|
| 304 |
-
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 305 |
-
|
| 306 |
-
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 307 |
-
const videoID = ytdl.getVideoID(url)
|
| 308 |
-
if (!videoID) return res.json({ success: false, message: 'Id Video Not Found!!!' })
|
| 309 |
-
const response = await ytdl.getInfo(videoID)
|
| 310 |
res.json({
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
})
|
| 320 |
-
/*app.post('/tools/ddos', async (req, res) => {
|
| 321 |
-
try {
|
| 322 |
-
console.log(req.body)
|
| 323 |
-
const { url, interval, mount, status } = req.body
|
| 324 |
-
if (!url) return res.json({ success: false, message: 'Required an url!' })
|
| 325 |
-
if (!interval) return res.json({ success: false, message: 'Required an interval number!' })
|
| 326 |
-
if (!mount) return res.json({ success: false, message: 'Required an mount number!' })
|
| 327 |
-
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 328 |
-
|
| 329 |
-
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 330 |
-
const response = await Stress.start({
|
| 331 |
-
debug: true,
|
| 332 |
-
url: url,
|
| 333 |
-
interval: interval,
|
| 334 |
-
max: mount,
|
| 335 |
-
proxy: "./proxy.txt"
|
| 336 |
-
})
|
| 337 |
-
res.json({
|
| 338 |
-
status: "ok",
|
| 339 |
-
target: url,
|
| 340 |
-
interval: interval,
|
| 341 |
-
mount: mount,
|
| 342 |
-
response
|
| 343 |
-
})
|
| 344 |
-
} catch (e) {
|
| 345 |
-
console.log(e)
|
| 346 |
-
e = String(e)
|
| 347 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 348 |
-
}
|
| 349 |
-
})*/
|
| 350 |
-
app.post('/api/bingchat', async (req, res) => {
|
| 351 |
try {
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 356 |
-
|
| 357 |
-
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 358 |
-
const response = await axios.request({
|
| 359 |
-
method: "GET",
|
| 360 |
-
url: "https://aemt.me/bingai?text=" + prompt
|
| 361 |
-
})
|
| 362 |
-
res.json({
|
| 363 |
-
status: "ok",
|
| 364 |
-
result: response.data.result
|
| 365 |
-
})
|
| 366 |
} catch (e) {
|
| 367 |
-
|
| 368 |
-
e = String(e)
|
| 369 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 370 |
}
|
| 371 |
})
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
| 373 |
try {
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
} catch (e) {
|
| 392 |
console.log(e)
|
| 393 |
e = String(e)
|
| 394 |
-
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 395 |
}
|
| 396 |
})
|
| 397 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
const PORT = process.env.PORT || 7860
|
| 399 |
-
app.listen(PORT, () =>
|
| 400 |
-
console.log('App running on port', PORT)
|
| 401 |
-
})
|
| 402 |
|
| 403 |
function formatSize(num) {
|
| 404 |
return bytes(+num || 0, { unitSeparator: ' ' })
|
| 405 |
}
|
|
|
|
| 406 |
function isBase64(str) {
|
| 407 |
try {
|
| 408 |
return btoa(atob(str)) === str
|
|
@@ -410,6 +312,7 @@ function isBase64(str) {
|
|
| 410 |
return false
|
| 411 |
}
|
| 412 |
}
|
|
|
|
| 413 |
function toPDF(urls) {
|
| 414 |
return new Promise(async (resolve, reject) => {
|
| 415 |
try {
|
|
@@ -442,121 +345,97 @@ function toPDF(urls) {
|
|
| 442 |
})
|
| 443 |
}
|
| 444 |
|
| 445 |
-
async function
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
const
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
Authority: "api.alcaamado.es",
|
| 469 |
-
Accept: "application/json",
|
| 470 |
-
Referer: "https://waifu2x.pro/",
|
| 471 |
-
Origin: "https://waifu2x.pro",
|
| 472 |
-
"User-Agent":
|
| 473 |
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
| 474 |
-
"Content-Type": `multipart/form-data; boundary=${formData._boundary}`,
|
| 475 |
-
},
|
| 476 |
-
});
|
| 477 |
-
|
| 478 |
-
const images = await axios.request({
|
| 479 |
-
method: "GET",
|
| 480 |
-
url:
|
| 481 |
-
"https://api.alcaamado.es/api/v2/waifu2x/get?hash=" +
|
| 482 |
-
response.data.hash +
|
| 483 |
-
"&type=" +
|
| 484 |
-
format,
|
| 485 |
-
headers: {
|
| 486 |
-
Accept: "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
| 487 |
-
"Content-Type": "image/jpg",
|
| 488 |
-
Referer: "https://waifu2x.pro/",
|
| 489 |
-
"User-Agent":
|
| 490 |
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
| 491 |
-
},
|
| 492 |
-
responseType: "arraybuffer",
|
| 493 |
-
});
|
| 494 |
-
|
| 495 |
-
resolve(images.data)
|
| 496 |
-
} catch (error) {
|
| 497 |
-
reject(error);
|
| 498 |
-
}
|
| 499 |
});
|
| 500 |
-
}
|
| 501 |
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
const convertingBlob = new Blob([imgBuffer], { type: type.mime });
|
| 509 |
-
|
| 510 |
-
const form = new FormData();
|
| 511 |
-
form.append('image', convertingBlob, "image" + type.ext);
|
| 512 |
-
|
| 513 |
-
const app = await Client.connect("Manjushri/SDXL-Turbo-Img2Img-CPU");
|
| 514 |
-
const result = await app.predict("/predict", [
|
| 515 |
-
form, // blob in 'Raw Image.' Image component
|
| 516 |
-
prompt, // string in 'Prompt Input Text. 77 Token (Keyword or Symbol) Maximum' Textbox component
|
| 517 |
-
1, // number (numeric value between 1 and 5) in 'Number of Iterations' Slider component
|
| 518 |
-
987654321987654321, // number (numeric value between 0 and 987654321987654321) in 'Seed' Slider component
|
| 519 |
-
0.1, // number (numeric value between 0.1 and 1) in 'Strength' Slider component
|
| 520 |
-
]);
|
| 521 |
-
resolve(result.data);
|
| 522 |
-
} catch(e) {
|
| 523 |
-
reject(e.message);
|
| 524 |
-
}
|
| 525 |
-
});
|
| 526 |
}
|
| 527 |
|
| 528 |
-
async function processImageAnime(inputBuffer) {
|
| 529 |
-
try {
|
| 530 |
-
// const base64String = Buffer.from(inputBuffer, 'binary').toString('base64');
|
| 531 |
-
const apiResponse = await axios.post('https://www.drawever.com/api/photo-to-anime', {
|
| 532 |
-
data: `data:image/png;base64,${inputBuffer}`,
|
| 533 |
-
}, {
|
| 534 |
-
headers: {
|
| 535 |
-
'Content-Type': 'application/json',
|
| 536 |
-
},
|
| 537 |
-
});
|
| 538 |
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
|
| 546 |
-
const image = await Jimp.read(imageBuffer);
|
| 547 |
-
const blackBackground = new Jimp(image.bitmap.width, 50, 0x000000FF);
|
| 548 |
-
const font = await Jimp.loadFont(Jimp.FONT_SANS_16_WHITE);
|
| 549 |
-
blackBackground.print(font, 10, 10, "SadTeams", blackBackground.bitmap.width - 20);
|
| 550 |
-
image.composite(blackBackground, 0, image.bitmap.height - blackBackground.bitmap.height, {
|
| 551 |
-
mode: Jimp.BLEND_SOURCE_OVER,
|
| 552 |
-
opacityDest: 0.5,
|
| 553 |
-
opacitySource: 1
|
| 554 |
-
});
|
| 555 |
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
}
|
|
|
|
| 1 |
+
const fs = require('fs')
|
| 2 |
const os = require('os')
|
| 3 |
+
const util = require('util')
|
| 4 |
+
const axios = require('axios')
|
| 5 |
const bytes = require('bytes')
|
| 6 |
const sharp = require('sharp')
|
| 7 |
const morgan = require('morgan')
|
| 8 |
const express = require('express')
|
| 9 |
+
const cp = require('child_process')
|
| 10 |
const PDFDocument = require('pdfkit')
|
| 11 |
+
const playwright = require('playwright-extra')
|
| 12 |
+
// const stealth = require('puppeteer-extra-plugin-stealth')
|
| 13 |
+
// playwright.chromium.use(stealth())
|
| 14 |
+
const { NinexbuddySource, NinexbuddyScraper } = require("./lib/buddy.js")
|
| 15 |
+
const kyou = new NinexbuddyScraper()
|
| 16 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
const app = express()
|
| 19 |
app.set('json spaces', 4)
|
| 20 |
app.use(morgan('dev'))
|
| 21 |
+
|
| 22 |
+
const limitSize = '500mb'
|
| 23 |
+
app.use(express.json({ limit: limitSize }))
|
| 24 |
+
app.use(express.urlencoded({ extended: true, limit: limitSize }))
|
| 25 |
+
|
| 26 |
+
const tmpFolder = os.tmpdir()
|
| 27 |
app.use((req, res, next) => {
|
| 28 |
+
fs.readdirSync(tmpFolder).map(file => {
|
| 29 |
+
file = `${tmpFolder}/${file}`
|
| 30 |
+
let stats = fs.statSync(file)
|
| 31 |
+
if (!stats.isFile()) return
|
| 32 |
+
if (Date.now() - stats.mtimeMs >= 1000 * 60 * 30) {
|
| 33 |
+
fs.unlinkSync(file)
|
| 34 |
+
console.log('Deleted file', file)
|
| 35 |
+
}
|
| 36 |
+
})
|
| 37 |
+
next()
|
| 38 |
})
|
| 39 |
|
| 40 |
+
app.use('/file', express.static(tmpFolder))
|
| 41 |
+
|
| 42 |
app.all('/', (req, res) => {
|
| 43 |
const status = {}
|
| 44 |
const used = process.memoryUsage()
|
| 45 |
for (let key in used) status[key] = formatSize(used[key])
|
| 46 |
|
| 47 |
+
const disk = cp.execSync('du -sh').toString().split('M')[0]
|
| 48 |
+
status.diskUsage = `${disk} MB`
|
| 49 |
+
|
| 50 |
const totalmem = os.totalmem()
|
| 51 |
const freemem = os.freemem()
|
| 52 |
status.memoryUsage = `${formatSize(totalmem - freemem)} / ${formatSize(totalmem)}`
|
|
|
|
|
|
|
| 53 |
|
| 54 |
res.json({
|
| 55 |
+
creator: '@rippanteq7',
|
| 56 |
+
message: 'Hello World',
|
| 57 |
uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4],
|
| 58 |
status
|
| 59 |
})
|
| 60 |
})
|
| 61 |
|
| 62 |
+
app.all('/imagetopdf', async (req, res) => {
|
| 63 |
+
if (!['POST'].includes(req.method)) return res.status(405).json({ success: false, message: 'Method Not Allowed' })
|
| 64 |
+
|
| 65 |
try {
|
| 66 |
+
console.log(new Date().toLocaleString('id', { timeZone: 'Asia/Jakarta' }), '\n', req.body)
|
| 67 |
const { images } = req.body
|
| 68 |
+
if (!(images && Array.isArray(images))) return res.json({ success: false, message: 'Required an array image url' })
|
| 69 |
|
| 70 |
const buffer = await toPDF(images)
|
| 71 |
res.setHeader('Content-Disposition', `attachment; filename=${Math.random().toString(36).slice(2)}.pdf`)
|
|
|
|
| 75 |
} catch (e) {
|
| 76 |
console.log(e)
|
| 77 |
e = String(e)
|
| 78 |
+
res.status(500).json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 79 |
}
|
| 80 |
})
|
| 81 |
|
| 82 |
+
app.all('/webp2png', async (req, res) => {
|
| 83 |
+
if (!['POST'].includes(req.method)) return res.status(405).json({ success: false, message: 'Method Not Allowed' })
|
| 84 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
try {
|
| 86 |
+
const { file } = req.body
|
| 87 |
+
if (!(file && isBase64(file))) return res.json({ success: false, message: 'Payload body file must be filled in base64 format' })
|
| 88 |
+
|
| 89 |
+
const fileBuffer = Buffer.from(file, 'base64')
|
| 90 |
+
const fileName = `${Math.random().toString(36).slice(2)}.png`
|
| 91 |
+
const convertData = await sharp(fileBuffer).png().toBuffer()
|
| 92 |
+
|
| 93 |
+
await fs.promises.writeFile(`${tmpFolder}/${fileName}`, convertData)
|
| 94 |
+
res.send(`https://${req.get('host')}/file/${fileName}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
} catch (e) {
|
| 96 |
console.log(e)
|
| 97 |
e = String(e)
|
| 98 |
+
res.status(500).json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 99 |
}
|
| 100 |
})
|
| 101 |
|
| 102 |
+
app.all(['/webp2gif', '/webp2mp4'], async (req, res) => {
|
| 103 |
+
if (!['POST'].includes(req.method)) return res.status(405).json({ success: false, message: 'Method Not Allowed' })
|
| 104 |
+
|
| 105 |
try {
|
| 106 |
+
const { file } = req.body
|
| 107 |
+
if (!(file && isBase64(file))) return res.json({ success: false, message: 'Payload body file must be filled in base64 format' })
|
| 108 |
+
|
| 109 |
+
const fileBuffer = Buffer.from(file, 'base64')
|
| 110 |
+
const fileName = `${Math.random().toString(36).slice(2)}.webp`
|
| 111 |
+
const filePath = `${tmpFolder}/${fileName}`
|
| 112 |
+
await fs.promises.writeFile(filePath, fileBuffer)
|
| 113 |
+
|
| 114 |
+
const exec = util.promisify(cp.exec).bind(cp)
|
| 115 |
+
await exec(`convert ${filePath} ${filePath.replace('.webp', '.gif')}`)
|
| 116 |
+
if (/gif/.test(req.path)) return res.send(`https://${req.get('host')}/file/${fileName.replace('.webp', '.gif')}`)
|
| 117 |
+
|
| 118 |
+
await exec(`ffmpeg -i ${filePath.replace('.webp', '.gif')} -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" ${filePath.replace(/.webp|.gif/g, '')}.mp4`)
|
| 119 |
+
res.send(`https://${req.get('host')}/file/${fileName.replace('.webp', '.mp4')}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
} catch (e) {
|
| 121 |
console.log(e)
|
| 122 |
e = String(e)
|
| 123 |
+
res.status(500).json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 124 |
}
|
| 125 |
})
|
| 126 |
+
|
| 127 |
+
app.get('/fetch', async (req, res) => {
|
| 128 |
try {
|
| 129 |
+
if (!req.query.url) return res.json({ message: 'Required an url' })
|
| 130 |
+
let json = await axios.get(req.query.url)
|
| 131 |
+
res.json(json.data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
} catch (e) {
|
| 133 |
+
res.send(e)
|
|
|
|
|
|
|
| 134 |
}
|
| 135 |
})
|
| 136 |
|
| 137 |
+
app.all(['/enhance', '/hd', '/upscale'], async (req, res) => {
|
| 138 |
+
if (!['GET', 'POST'].includes(req.method)) return res.status(405).json({ success: false, message: 'Method Not Allowed' })
|
| 139 |
+
|
| 140 |
try {
|
| 141 |
+
const { url } = req.method !== 'GET' ? req.body : req.query
|
| 142 |
+
if (!url) return res.json({ success: false, message: 'Required parameter url' })
|
| 143 |
+
|
| 144 |
+
const result = await enhanceImage(url)
|
| 145 |
+
res.json({ success: true, result })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
} catch (e) {
|
| 147 |
console.log(e)
|
| 148 |
e = String(e)
|
| 149 |
+
res.status(500).json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 150 |
}
|
| 151 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
+
app.all('/animelast', async (req, res) => {
|
| 154 |
+
const result = await scrapeAnimeInfo();
|
| 155 |
res.json({
|
| 156 |
+
creator: '@Kyouka',
|
| 157 |
+
message: 'Success',
|
| 158 |
+
uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4],
|
| 159 |
+
result
|
| 160 |
+
});
|
| 161 |
+
});
|
| 162 |
+
|
| 163 |
+
app.all('/dood', async (req, res) => {
|
| 164 |
+
const { url } = req.query
|
| 165 |
+
if (!url) return res.json({ success: false, message: 'Required parameter url' })
|
| 166 |
+
const result = await kyou.execWithArgs(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
res.json({
|
| 168 |
+
creator: '@Kyouka',
|
| 169 |
+
message: 'Success',
|
| 170 |
+
uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4],
|
| 171 |
+
result
|
| 172 |
+
});
|
| 173 |
+
});
|
| 174 |
+
|
| 175 |
+
app.get('/igstalk', async (req, res) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
try {
|
| 177 |
+
if (!req.query.user) return res.json({ message: 'Required an username' })
|
| 178 |
+
let result = await igStalk(req.query.user)
|
| 179 |
+
res.json({ result })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
} catch (e) {
|
| 181 |
+
res.send(e)
|
|
|
|
|
|
|
| 182 |
}
|
| 183 |
})
|
| 184 |
+
|
| 185 |
+
app.all('/stablediff/illusion', async (req, res) => {
|
| 186 |
+
if (!['GET', 'POST'].includes(req.method)) return res.status(405).json({ success: false, message: 'Method Not Allowed' })
|
| 187 |
+
|
| 188 |
try {
|
| 189 |
+
const {
|
| 190 |
+
prompt,
|
| 191 |
+
negative_prompt = 'low quality',
|
| 192 |
+
image_url,
|
| 193 |
+
num_inference_steps = 25,
|
| 194 |
+
controlnet_conditioning_scale = 1
|
| 195 |
+
} = req.method !== 'GET' ? req.body : req.query
|
| 196 |
+
|
| 197 |
+
if (!(prompt && image_url)) return res.json({ success: false, message: 'Required parameter prompt & image_url' })
|
| 198 |
+
|
| 199 |
+
const headers = {
|
| 200 |
+
'Content-Type': 'application/json',
|
| 201 |
+
Authorization: `Key ${process.env.falAIKey}`
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
const { detail, response_url } = await (await fetch('https://54285744-illusion-diffusion.gateway.alpha.fal.ai/fal/queue/submit', {
|
| 205 |
+
method: 'POST',
|
| 206 |
+
body: JSON.stringify({
|
| 207 |
+
prompt, negative_prompt, image_url,
|
| 208 |
+
num_inference_steps, controlnet_conditioning_scale
|
| 209 |
+
}),
|
| 210 |
+
headers
|
| 211 |
+
})).json()
|
| 212 |
+
if (detail) return res.json({ success: false, message: detail })
|
| 213 |
+
|
| 214 |
+
let retry = 0
|
| 215 |
+
while (true) {
|
| 216 |
+
await new Promise(resolve => setTimeout(resolve, 2500))
|
| 217 |
+
const prediction = await (await fetch(response_url, { headers })).json()
|
| 218 |
+
console.log(prediction)
|
| 219 |
+
if (retry > 10) return res.json({ success: false, message: prediction.detail || 'Max retry has reached' })
|
| 220 |
+
if (prediction.image) return res.json({ success: true, result: prediction })
|
| 221 |
+
retry += 1
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
} catch (e) {
|
| 225 |
console.log(e)
|
| 226 |
e = String(e)
|
| 227 |
+
res.status(500).json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 228 |
}
|
| 229 |
})
|
| 230 |
|
| 231 |
+
app.get('/dongo', async (req, res) => {
|
| 232 |
+
const { url } = req.query
|
| 233 |
+
if (!url) return res.json({ success: false, message: 'Required parameter url' })
|
| 234 |
+
const browser = await playwright.chromium.launch({
|
| 235 |
+
headless: true,
|
| 236 |
+
executablePath: '/usr/bin/chromium',
|
| 237 |
+
args: ['--no-sandbox']
|
| 238 |
+
})
|
| 239 |
+
const context = await browser.newContext({
|
| 240 |
+
extraHTTPHeaders: {
|
| 241 |
+
'accept': '*/*',
|
| 242 |
+
'accept-language': 'en-US,en;q=0.9,id;q=0.8',
|
| 243 |
+
'cache-control': 'no-cache',
|
| 244 |
+
'origin': url,
|
| 245 |
+
'pragma': 'no-cache',
|
| 246 |
+
'referer': url,
|
| 247 |
+
'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
|
| 248 |
+
'sec-ch-ua-mobile': '?0',
|
| 249 |
+
'sec-ch-ua-platform': '"Windows"',
|
| 250 |
+
'sec-fetch-dest': 'script',
|
| 251 |
+
'sec-fetch-mode': 'cors',
|
| 252 |
+
'sec-fetch-site': 'cross-site',
|
| 253 |
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36'
|
| 254 |
+
}
|
| 255 |
+
});
|
| 256 |
+
|
| 257 |
+
const page = await context.newPage();
|
| 258 |
+
await page.goto(url);
|
| 259 |
+
|
| 260 |
+
const content = await page.content(); // Get the page content as HTML
|
| 261 |
+
|
| 262 |
+
await browser.close();
|
| 263 |
+
|
| 264 |
+
res.send(content); // Send the page content as response
|
| 265 |
+
});
|
| 266 |
+
|
| 267 |
+
app.get('/fetch-page', async (req, res) => {
|
| 268 |
+
const browser = await playwright.chromium.launch({
|
| 269 |
+
headless: true,
|
| 270 |
+
executablePath: '/usr/bin/chromium',
|
| 271 |
+
args: ['--no-sandbox']
|
| 272 |
+
})
|
| 273 |
+
const context = await browser.newContext({
|
| 274 |
+
extraHTTPHeaders: {
|
| 275 |
+
'accept': '*/*',
|
| 276 |
+
'accept-language': 'en-US,en;q=0.9,id;q=0.8',
|
| 277 |
+
'cache-control': 'no-cache',
|
| 278 |
+
'origin': 'https://doujindesu.tv',
|
| 279 |
+
'pragma': 'no-cache',
|
| 280 |
+
'referer': 'https://doujindesu.tv',
|
| 281 |
+
'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
|
| 282 |
+
'sec-ch-ua-mobile': '?0',
|
| 283 |
+
'sec-ch-ua-platform': '"Windows"',
|
| 284 |
+
'sec-fetch-dest': 'script',
|
| 285 |
+
'sec-fetch-mode': 'cors',
|
| 286 |
+
'sec-fetch-site': 'cross-site',
|
| 287 |
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36'
|
| 288 |
+
}
|
| 289 |
+
});
|
| 290 |
+
|
| 291 |
+
const page = await context.newPage();
|
| 292 |
+
await page.goto('https://doujindesu.tv');
|
| 293 |
+
|
| 294 |
+
const content = await page.content(); // Get the page content as HTML
|
| 295 |
+
|
| 296 |
+
await browser.close();
|
| 297 |
+
|
| 298 |
+
res.send(content); // Send the page content as response
|
| 299 |
+
});
|
| 300 |
+
|
| 301 |
const PORT = process.env.PORT || 7860
|
| 302 |
+
app.listen(PORT, () => console.log('App running on port', PORT))
|
|
|
|
|
|
|
| 303 |
|
| 304 |
function formatSize(num) {
|
| 305 |
return bytes(+num || 0, { unitSeparator: ' ' })
|
| 306 |
}
|
| 307 |
+
|
| 308 |
function isBase64(str) {
|
| 309 |
try {
|
| 310 |
return btoa(atob(str)) === str
|
|
|
|
| 312 |
return false
|
| 313 |
}
|
| 314 |
}
|
| 315 |
+
|
| 316 |
function toPDF(urls) {
|
| 317 |
return new Promise(async (resolve, reject) => {
|
| 318 |
try {
|
|
|
|
| 345 |
})
|
| 346 |
}
|
| 347 |
|
| 348 |
+
async function scrapeAnimeInfo() {
|
| 349 |
+
try {
|
| 350 |
+
const browser = await playwright.chromium.launch({
|
| 351 |
+
headless: true,
|
| 352 |
+
executablePath: '/usr/bin/chromium',
|
| 353 |
+
args: ['--no-sandbox']
|
| 354 |
+
});
|
| 355 |
+
const page = await browser.newPage();
|
| 356 |
+
await page.goto('http://66.29.129.161/?filter=latest&cat=1');
|
| 357 |
+
const pageContent = await page.content();
|
| 358 |
+
console.log(pageContent);
|
| 359 |
+
// Wait for the list of videos to load
|
| 360 |
+
await page.waitForSelector('.videos-list');
|
| 361 |
+
|
| 362 |
+
// Extract data from all articles
|
| 363 |
+
const videoData = await page.$$eval('.videos-list article', articles => {
|
| 364 |
+
return articles.map(article => {
|
| 365 |
+
const thumbnail = article.querySelector('.post-thumbnail img').src;
|
| 366 |
+
const title = article.querySelector('header.entry-header span').textContent;
|
| 367 |
+
const url = article.querySelector('a').href;
|
| 368 |
+
const duration = article.querySelector('.duration').textContent.trim();
|
| 369 |
+
return { thumbnail, title, url, duration };
|
| 370 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
});
|
|
|
|
| 372 |
|
| 373 |
+
await browser.close();
|
| 374 |
+
return videoData;
|
| 375 |
+
} catch (error) {
|
| 376 |
+
console.error('An error occurred during scraping:', error);
|
| 377 |
+
return []; // Return an empty array in case of error
|
| 378 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
}
|
| 380 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
|
| 382 |
+
async function enhanceImage(url) {
|
| 383 |
+
const browser = await playwright.chromium.launch({
|
| 384 |
+
headless: true,
|
| 385 |
+
executablePath: '/usr/bin/chromium',
|
| 386 |
+
args: ['--no-sandbox']
|
| 387 |
+
})
|
| 388 |
+
|
| 389 |
+
const page = await browser.newPage()
|
| 390 |
+
await page.goto('https://snapedit.app/id/enhance/upload')
|
| 391 |
+
await page.waitForLoadState('domcontentloaded')
|
| 392 |
+
|
| 393 |
+
const arrayBuffer = await (await fetch(url)).arrayBuffer()
|
| 394 |
+
page.on('filechooser', (fileChooser) => {
|
| 395 |
+
const fileObject = {
|
| 396 |
+
name: 'file.jpg',
|
| 397 |
+
mimeType: 'image/jpg',
|
| 398 |
+
buffer: Buffer.from(arrayBuffer)
|
| 399 |
+
}
|
| 400 |
+
fileChooser.setFiles([fileObject])
|
| 401 |
+
})
|
| 402 |
+
|
| 403 |
+
await page.getByRole('button', { name: 'Unggah gambar', exact: true }).click()
|
| 404 |
+
const response = await page.waitForResponse(res => {
|
| 405 |
+
console.log(res.url())
|
| 406 |
+
return res.url().includes('api/enhance/v1')
|
| 407 |
+
}, { timeout: 60 * 1000 })
|
| 408 |
+
const json = await response.json()
|
| 409 |
+
|
| 410 |
+
await browser.close()
|
| 411 |
+
return json
|
| 412 |
+
}
|
| 413 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
|
| 415 |
+
async function igStalk(user) {
|
| 416 |
+
const getDetailPost = async url => {
|
| 417 |
+
let html = (await axios.get(url, { headers: { 'Referer': 'https://www.picuki.com/', 'User-Agent': fakeua.mobile() }})).data
|
| 418 |
+
let $ = cheerio.load(html), obj = {}
|
| 419 |
+
obj.caption = $('title').text().trim().split(' Instagram post ')[1].split(' - Picuki.com')[0]
|
| 420 |
+
obj.ago = $('div.single-photo-info').find('div.single-photo-time').text()
|
| 421 |
+
obj.likes = $('div.info-bottom').find('span.icon-thumbs-up-alt').text()
|
| 422 |
+
obj.comments = $('div.info-bottom').find('span.icon-chat').text()
|
| 423 |
+
obj.url = $('div.single-photo.owl-carousel.owl-theme > div.item').get().map((x) => $(x).find('img').attr('src') || $(x).find('video').attr('src'))
|
| 424 |
+
if (!obj.url.length) obj.url = [$('div.single-photo').find('img').attr('src') || $('div.single-photo').find('video').attr('src')]
|
| 425 |
+
return obj
|
| 426 |
+
}
|
| 427 |
+
let html = (await axios.get('https://www.picuki.com/profile/' + user, { headers: { 'Referer': 'https://www.picuki.com/', 'User-Agent': fakeua.mobile() }})).data
|
| 428 |
+
let $ = cheerio.load(html), obj = {}, arr = []
|
| 429 |
+
let urlPost = $('div.content > ul > li').get().map((x) => $(x).find('a').attr('href'))
|
| 430 |
+
for (let x of urlPost) {
|
| 431 |
+
if (x) arr.push(await getDetailPost(x))
|
| 432 |
+
}
|
| 433 |
+
obj.avatar = $('div.profile-avatar').find('a').attr('href')
|
| 434 |
+
obj.username = $('div.profile-name > h1').text()
|
| 435 |
+
obj.fullname = $('div.profile-name > h2').text()
|
| 436 |
+
obj.description = $('div.profile-description').text().trim()
|
| 437 |
+
obj.followers = $('div.content-title').find('span.followed_by').text()
|
| 438 |
+
obj.following = $('div.content-title').find('span.follows').text()
|
| 439 |
+
obj.post = arr
|
| 440 |
+
return obj
|
| 441 |
}
|