Spaces:
Paused
Paused
| const os = require('os') | |
| const bytes = require('bytes') | |
| const sharp = require('sharp') | |
| const morgan = require('morgan') | |
| const express = require('express') | |
| const PDFDocument = require('pdfkit') | |
| const axios = require("axios") | |
| const FormData = require("form-data") | |
| //const { BingChat } = (await import("bing-chat")).default | |
| const apikey = "@SadTeam77" | |
| const app = express() | |
| app.set('json spaces', 4) | |
| app.use(morgan('dev')) | |
| app.use(express.json()) | |
| app.all('/', (req, res) => { | |
| const status = {} | |
| const used = process.memoryUsage() | |
| for (let key in used) status[key] = formatSize(used[key]) | |
| const totalmem = os.totalmem() | |
| const freemem = os.freemem() | |
| status.memoryUsage = `${formatSize(totalmem - freemem)} / ${formatSize(totalmem)}` | |
| res.json({ | |
| creator: "@SadTeams", | |
| message: 'Hello World!!', | |
| uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4], | |
| status | |
| }) | |
| }) | |
| app.post('/imagetopdf', async (req, res) => { | |
| try { | |
| console.log(req.body) | |
| const { images } = req.body | |
| if (!images) return res.json({ success: false, message: 'Required an array image url' }) | |
| const buffer = await toPDF(images) | |
| res.setHeader('Content-Disposition', `attachment; filename=${Math.random().toString(36).slice(2)}.pdf`) | |
| res.setHeader('Content-Type', 'application/pdf') | |
| res.setHeader('Content-Length', buffer.byteLength) | |
| res.send(buffer) | |
| } catch (e) { | |
| console.log(e) | |
| e = String(e) | |
| res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e }) | |
| } | |
| }) | |
| app.post('/api/chatgpt', async (req, res) => { | |
| try { | |
| console.log(req.body) | |
| const { prompt, model, status } = req.body | |
| if (!prompt) return res.json({ success: false, message: 'Required an prompt text!' }) | |
| if (!model) return res.json({ success: false, message: 'Required an model version!' }) | |
| if (!status) return res.json({ success: false, message: 'Required an prompt text!' }) | |
| if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' }) | |
| const response = await acytoo(prompt, model) | |
| res.json({ | |
| status: "ok", | |
| result: response | |
| }) | |
| } catch (e) { | |
| console.log(e) | |
| e = String(e) | |
| res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e }) | |
| } | |
| }) | |
| app.post('/api/chatgpt2', async (req, res) => { | |
| try { | |
| console.log(req.body) | |
| const { data, prompt, status } = req.body | |
| if (!data) return res.json({ success: false, message: 'Required an data text!' }) | |
| if (!prompt) return res.json({ success: false, message: 'Required an prompt text!' }) | |
| if (!status) return res.json({ success: false, message: 'Required an status text!' }) | |
| if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' }) | |
| const response = await axios.request({ | |
| method: "GET", | |
| url: `https://aemt.me/prompt/gpt?prompt=${data}&text=${prompt}` | |
| }) | |
| res.json({ | |
| status: "ok", | |
| result: response.data.result | |
| }) | |
| } catch (e) { | |
| console.log(e) | |
| e = String(e) | |
| res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e }) | |
| } | |
| }) | |
| app.post('/api/toanime', async (req, res) => { | |
| try { | |
| console.log(req.body) | |
| const { url, status } = req.body | |
| if (!url) return res.json({ success: false, message: 'Required an url!' }) | |
| if (!status) return res.json({ success: false, message: 'Required an status text!' }) | |
| if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' }) | |
| const response = await axios.request({ | |
| method: "GET", | |
| url: `https://aemt.me/toanime?url=${url}` | |
| }) | |
| const image = await axios.request({ | |
| method: "GET", | |
| url: response.data.url.img_crop_single, | |
| responseType: "arraybuffer" | |
| }) | |
| res.setHeader('Content-Type', 'image/jpeg') | |
| res.send(image.data) | |
| } catch (e) { | |
| console.log(e) | |
| e = String(e) | |
| res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e }) | |
| } | |
| }) | |
| app.post('/api/waifu2x', async (req, res) => { | |
| try { | |
| console.log(req.body) | |
| const { url, format, status } = req.body | |
| if (!url) return res.json({ success: false, message: 'Required an url!' }) | |
| if (!format) return res.json({ success: false, message: 'Required an format size!' }) | |
| if (!status) return res.json({ success: false, message: 'Required an status text!' }) | |
| if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' }) | |
| const response = await waifu2x(url, format) | |
| res.setHeader('Content-Type', 'image/jpg') | |
| res.send(response) | |
| } catch (e) { | |
| console.log(e) | |
| e = String(e) | |
| res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e }) | |
| } | |
| }) | |
| /*app.post('/api/bingchat', async (req, res) => { | |
| try { | |
| console.log(req.body) | |
| const { prompt, status } = req.body | |
| if (!prompt) return res.json({ success: false, message: 'Required an prompt text!' }) | |
| if (!status) return res.json({ success: false, message: 'Required an status text!' }) | |
| if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' }) | |
| const api = new BingChat({ | |
| cookie: process.env.BING_COOKIE | |
| }) | |
| const resonse = await api.sendMessage(prompt) | |
| res.json({ | |
| status: "ok", | |
| result: response.text | |
| }) | |
| } catch (e) { | |
| console.log(e) | |
| e = String(e) | |
| res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e }) | |
| } | |
| })*/ | |
| const PORT = process.env.PORT || 7860 | |
| app.listen(PORT, () => console.log('App running on port', PORT)) | |
| function formatSize(num) { | |
| return bytes(+num || 0, { unitSeparator: ' ' }) | |
| } | |
| function toPDF(urls) { | |
| return new Promise(async (resolve, reject) => { | |
| try { | |
| if (!Array.isArray(urls)) urls = [urls] | |
| const doc = new PDFDocument({ margin: 0, size: 'A4' }) | |
| const buffers = [] | |
| for (let i = 0; i < urls.length; i++) { | |
| const response = await fetch(urls[i], { headers: { referer: urls[i] }}) | |
| if (!response.ok) continue | |
| const type = response.headers.get('content-type') | |
| if (!/image/.test(type)) continue | |
| let buffer = Buffer.from(await response.arrayBuffer()) | |
| if (/gif|webp/.test(type)) buffer = await sharp(buffer).png().toBuffer() | |
| doc.image(buffer, 0, 0, { fit: [595.28, 841.89], align: 'center', valign: 'center' }) | |
| if (urls.length !== i + 1) doc.addPage() | |
| } | |
| doc.on('data', (chunk) => buffers.push(chunk)) | |
| doc.on('end', () => resolve(Buffer.concat(buffers))) | |
| doc.on('error', reject) | |
| doc.end() | |
| } catch (e) { | |
| console.log(e) | |
| reject(e) | |
| } | |
| }) | |
| } | |
| async function acytoo(text, model) { | |
| let res = await axios.request({ | |
| method: "POST", | |
| url: "https://chat.acytoo.com/api/completions", | |
| data: JSON.stringify({ | |
| key: "", | |
| messages: [{ | |
| role: "user", | |
| content: text, | |
| createAt: "", | |
| }], | |
| model: model, | |
| password: "", | |
| temprature: 1 | |
| }), | |
| headres: { | |
| "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36", | |
| "Origin": "https://chat.acytoo.com" | |
| } | |
| }) | |
| return res.data | |
| } | |
| async function waifu2x(urls, formats) { | |
| // data | |
| let img = await axios.get(urls, { responseType: "arraybuffer"}) | |
| let random_numbers = Math.floor(Math.random() * 1000) | |
| let format | |
| if(formats == "Medium") { | |
| format = "1" | |
| } else if(formats == "High") { | |
| format = "2" | |
| } else if(!formats) { | |
| format = "0" | |
| } | |
| // memasukan data api | |
| const formData = new FormData() | |
| formData.append("denoise", format) | |
| formData.append("scale", "true") | |
| formData.append("file", img.data, { | |
| filename: "images_" + random_numbers.toString().padStart(3, '0') + ".jpg", | |
| contentType: "image/jpeg" | |
| }) | |
| // request ke api untuk mendapatkan hash nya | |
| const response = await axios.request({ | |
| method: "POST", | |
| url: "https://api.alcaamado.es/api/v1/waifu2x/convert", | |
| data: formData, | |
| headers: { | |
| "Accept": "application/json", | |
| "Referer": "https://waifu2x.pro/", | |
| "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" | |
| } | |
| }) | |
| const ress = await axios.request({ | |
| method: "GET", | |
| url: "https://api.alcaamado.es/api/v2/waifu2x/check?hash=" + response.data.hash, | |
| headers: { | |
| "Accept": "application/json", | |
| "Referer": "https://waifu2x.pro/", | |
| "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" | |
| } | |
| }) | |
| if(!ress.data.finished) return "Images Not Supported!!" | |
| const images = await axios.request({ | |
| method: "GET", | |
| url: "https://api.alcaamado.es/api/v2/waifu2x/get?hash=" + response.data.hash + "&type=jpg", | |
| headers: { | |
| "Accept": "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8", | |
| "Content-Type": "image/jpg", | |
| "Referer": "https://waifu2x.pro/", | |
| "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" | |
| }, | |
| responseType: "arraybuffer" | |
| }) | |
| return images.data | |
| } |