/* Credits @xpushz on telegram Copyright 2017-2025 (c) Randy W @xtdevs, @xtsea on telegram from : https://github.com/TeamKillerX Channel : @RendyProjects This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ import express from 'express'; const app = express(); import * as swaggerUi from 'swagger-ui-express'; import * as cheerio from 'cheerio'; import * as lifestyle from './startup/lifestyle.js'; import * as uuid from 'uuid'; import { Database } from './database/database.js' import { ApiKey } from './models.js'; import { Readable } from "stream"; import { randomBytes } from "crypto"; import { AkenoaiJs } from "akenoaijs"; import { CheckMilWare, authenticateApiKey, apiLimiter } from './middleware/midware.js'; import { setup, serve } from './swagger.js'; import { swaggerOptions } from './settingOptions.js'; import path from "path"; import sharp from "sharp"; import bodyParser from 'body-parser'; import swaggerJsDoc from 'swagger-jsdoc'; // routes import { GempaRoutes } from './plugins/gempa.js'; import { FluxRoutes } from './plugins/fluxai.js'; import { GptRoutes } from './plugins/gptold.js'; import { HentaiRoutes } from './plugins/hentai.js'; import { TebakRoutes } from './plugins/tebak.js'; import { CopilotRoutes } from './plugins/copilot.js'; import { CarbonRoutes } from './plugins/carbon.js'; import { UnblockIpRoutes } from './plugins/unblockip.js'; import { AntibanRoutes } from './plugins/antiban.js'; import { AllDlRoutes } from './plugins/alldownloader.js'; import { GeminiRoutes } from './routes/googleGemini.js'; const __dirname = path.resolve(); const CheckMilWares = new CheckMilWare(); const myUUID = uuid.v4(); function _0x8e5f(){const _0x47a684=['21328MwnItu','akeno_','2HGYaRq','7539MDsoUT','239924nJVgmv','67736vpCrKx','7007630HuiUXg','620826tHyNgs','978pHDPNY','153GWQrSV','1344810LrohVJ'];_0x8e5f=function(){return _0x47a684;};return _0x8e5f();}(function(_0x2cc85e,_0x5b8aeb){const _0x30a48=_0x2eb9,_0x508eac=_0x2cc85e();while(!![]){try{const _0x401ae4=parseInt(_0x30a48(0x1b1))/0x1*(parseInt(_0x30a48(0x1b3))/0x2)+-parseInt(_0x30a48(0x1b6))/0x3+parseInt(_0x30a48(0x1af))/0x4+-parseInt(_0x30a48(0x1b9))/0x5+-parseInt(_0x30a48(0x1b7))/0x6*(parseInt(_0x30a48(0x1b2))/0x7)+-parseInt(_0x30a48(0x1b4))/0x8*(parseInt(_0x30a48(0x1b8))/0x9)+parseInt(_0x30a48(0x1b5))/0xa;if(_0x401ae4===_0x5b8aeb)break;else _0x508eac['push'](_0x508eac['shift']());}catch(_0x43caee){_0x508eac['push'](_0x508eac['shift']());}}}(_0x8e5f,0x24c61));function _0x2eb9(_0x71c9ef,_0x40f517){const _0x8e5f80=_0x8e5f();return _0x2eb9=function(_0x2eb9aa,_0xe433fa){_0x2eb9aa=_0x2eb9aa-0x1af;let _0x4300be=_0x8e5f80[_0x2eb9aa];return _0x4300be;},_0x2eb9(_0x71c9ef,_0x40f517);}function generateAkenoKey(){const _0x5cad5d=_0x2eb9,_0x399302=randomBytes(0x18)['toString']('base64')['replace'](/[^a-zA-Z0-9]/g,'');return _0x5cad5d(0x1b0)+_0x399302;} app.use(async (req, res, next) => { await CheckMilWares.handle(req, res, next); }); app.use("/api/v1/", apiLimiter); app.disable("x-powered-by"); app.disable("link") app.use(bodyParser.json()); app.use( bodyParser.urlencoded({ extended: true, }) ); app.use(express.static('public')); // routes app.use(GeminiRoutes); app.use(FluxRoutes); app.use(GptRoutes); app.use(HentaiRoutes); app.use(TebakRoutes); app.use(GempaRoutes); app.use(CopilotRoutes); app.use(UnblockIpRoutes); app.use(CarbonRoutes); app.use(AntibanRoutes); app.use(AllDlRoutes); const specs = swaggerJsDoc(swaggerOptions); const AllJsonReques = { "AkenoXAPI": { "akenox_date": new Date(), "developer": "@xpushz", "language": "JS && Python", "cybersecurity": true, "source_link": "https://github.com/TeamKillerX/akenoai-lib", "ai": { "endpoint": "ai/google-gemini", "params": "query", "method": "GET", "headers": "x-api-key", "part2": { "endpoint": "ai/copilot2-trip", "params": "q", "method": "GET", "headers": "x-api-key", }, "part3": { "endpoint": "ai/gpt-old", "params": "query", "method": "GET", "headers": "x-api-key", }, }, "flux": { "endpoint": "flux/flux-ai", "body": "query", "method": "POST", "headers": "x-api-key", }, }, } app.get("/api/v1/json/all", async (req, res) => { res.json(AllJsonReques); }); app.get('/broadcast-user', async (req, res) => { const dbClient = new Database("AkenoXJs"); const collection = dbClient.collection("api_keys"); try { const result = await collection.find({}).toArray(); let userIds = []; let storage_dict = {}; for (const data of result) { if (data.owner !== undefined) { storage_dict[data.owner] = data.key; userIds.push(data.owner); } } res.json({ user_id: userIds, count: userIds.length }); // console.log(storage_dict); } catch (error) { console.error("Failed to get data from DB: " + error); res.status(500).send("Error fetching data from database."); } }); app.post('/webhook', (req, res) => { console.log('Received webhook:', req.body); res.status(200).send('Webhook received'); }); app.delete("/api/v2/delete-key", async (req, res) => { const apiKey = req.query.api_key; if (!apiKey) { return res.status(400).json({ error: "Missing 'api_key' parameter" }); } try { const DocsKey = await ApiKey.deleteOne({ key: apiKey }); if (DocsKey.deletedCount > 0) { res.json({ message: "API key has been successfully deleted" }); } else { res.status(404).json({ message: "API key not found" }); } } catch (err) { res.status(500).json({ error: `Key deletion failed: ${err.message}` }); } }); app.delete("/api/v1/delete-key", async (req, res) => { const dbClient = new Database("AkenoXJs"); const collection = dbClient.collection("api_keys"); const apiKey = req.query.api_key; if (!apiKey) { return res.status(400).json({ error: "Missing 'api_key' parameter" }); } try { const DocsKey = await collection.deleteOne({ key: apiKey }); if (DocsKey.deletedCount > 0) { res.json({ message: "API key has been successfully deleted" }); } else { res.status(404).json({ message: "API key not found" }); } } catch (err) { res.status(500).json({ error: `Key deletion failed: ${err.message}` }); } }); app.get("/api/v1/test", authenticateApiKey, apiLimiter, async (req, res) => { res.json({ message: "access key" }); }) app.get("/runtime", async (req, res) => { res.send("Running lifetime"); }) app.post('/api/v2/generate-key', async (req, res) => { try { const newKey = generateAkenoKey(); const userIdNumber = Number(req.query.user_id); const email = req.query.email; if (isNaN(userIdNumber)) { return res.status(400).json({ error: "Invalid or missing user_id" }); } const existingUser = await ApiKey.findOne({ owner: userIdNumber }); if (existingUser) { return res.status(200).json({ apiKey: existingUser.key, createdAt: existingUser.createdAt, expiresAt: existingUser.expiresAt, owner: existingUser.owner, type: existingUser.type }); } const expirationDate = new Date(); expirationDate.setDate(expirationDate.getDate() + 30); const userDocument = new ApiKey({ key: newKey, createdAt: new Date(), expiresAt: expirationDate, owner: userIdNumber, type: "premium", email: email || null }); await userDocument.save(); res.json({ apiKey: newKey, createdAt: new Date(), expiresAt: expirationDate, owner: userIdNumber, type: "premium" }); } catch (err) { res.status(500).json({ error: `Key generation failed: ${err.message}` }); } }); app.post("/api/v1/revoked-key", async (req, res) => { const dbClient = new Database("AkenoXJs"); const collection = dbClient.collection("api_keys"); try { const userIdString = req.query.user_id; const userIdNumber = Number(userIdString); if (isNaN(userIdNumber)) { return res.status(400).json({ error: "Invalid or missing user_id" }); } const existingUser = await collection.findOne({ owner: userIdNumber }); if (!existingUser) { return res.status(404).json({ error: "API key not found" }); } const newKey = generateAkenoKey(); const result = await collection.updateOne( { owner: userIdNumber }, { $set: { key: newKey, createdAt: new Date() } }, { upsert: false } ); if (result.modifiedCount > 0) { res.json({ message: "API key successfully revoked and regenerated", apiKey: newKey, createdAt: new Date(), owner: userIdNumber }); } else { res.status(500).json({ error: "Failed to update API key" }); } } catch (err) { res.status(500).json({ error: `Key generation failed: ${err.message}` }); } }); app.post('/api/v1/generate-key', async (req, res) => { const dbClient = new Database("AkenoXJs"); const collection = dbClient.collection('api_keys'); try { const newKey = generateAkenoKey(); const userIdString = req.query.user_id; const userIdNumber = Number(userIdString); const email = req.query.email; if (isNaN(userIdNumber)) { return res.status(400).json({ error: "Invalid or missing user_id" }); } const existingUser = await collection.findOne({ owner: userIdNumber }); if (existingUser) { return res.status(200).json({ apiKey: existingUser.key, createdAt: existingUser.createdAt, owner: existingUser.owner }); } const userDocument = { key: newKey, createdAt: new Date(), owner: userIdNumber, type: "free" }; if (email) { userDocument.email = email; } await collection.insertOne(userDocument); res.json({ apiKey: newKey, createdAt: new Date(), owner: userIdNumber }); } catch (err) { res.status(500).json({ error: `Key generation failed: ${err.message}` }); } }); app.get("/policy", ( req, res ) => { res.sendFile(path.join(__dirname + "/public/policy.html")); }); app.get("/scraper/read", ( req, res ) => { res.sendFile(path.join(__dirname + "/public/docs.html")); }); app.use( '/docs', serve, setup(specs, { customCss: ` .swagger-ui .topbar { display: none; } .swagger-ui .opblock .opblock-summary-path { display: inline-block; word-break: break-word; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; } `, customCssUrl: "https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.3.0/swagger-ui.min.css", customSiteTitle: 'AkenoXJs' }) ); app.get('/', (req, res) => { res.redirect('https://t.me/RendyProjects'); }); lifestyle.startServer(app);