File size: 7,312 Bytes
70335fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6f115e7
70335fc
cc43160
1c2f245
83075c1
f836f2f
ff5dd77
 
7864014
2a1da11
0073410
ff5dd77
9d7429f
 
 
7864014
9d7429f
 
ea9ab95
8e9d6ef
4acf951
ea9ab95
 
 
 
aaeefe8
03eff68
dd7e9fe
03eff68
1736687
b749907
e9a4054
f38b6df
4ae50c2
43320de
ded0ba9
e67e90e
ad71933
1122fa5
7864014
1122fa5
ff5dd77
 
 
 
 
ba1757e
 
 
1c8c6b7
 
6d18814
 
 
 
 
594fd9f
e28d3f7
091ea21
 
 
 
 
43cc2ca
9565290
1aa6951
ad61b3a
 
 
 
 
 
 
 
 
 
 
 
 
be1f5f7
73b11fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be1f5f7
 
 
c388a7a
73b11fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c388a7a
 
 
dc73788
258ce6a
 
dc73788
258ce6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
763fd09
258ce6a
 
 
 
 
 
dc73788
 
 
c388a7a
73b11fb
0114ae9
9d7429f
ff5dd77
0cb9b79
 
 
 
 
 
 
0f816c4
 
 
8587052
0f816c4
0cb9b79
9d7429f
 
0cb9b79
 
 
 
 
 
9d7429f
 
7d62f05
9d7429f
 
4067ca0
ba1757e
 
 
 
 
 
 
 
ea9ab95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e67e90e
dc7aadc
90e4651
 
dc7aadc
1c2f245
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
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 <https://www.gnu.org/licenses/>.
*/

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 { Readable } from "stream";
import { randomBytes } from "crypto";

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 cors from 'cors';
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 { GeminiRoutes } from './routes/googleGemini.js';

const __dirname = path.resolve();
const CheckMilWares = new CheckMilWare();
const myUUID = uuid.v4();

function generateAkenoKey() {
    const randomString = randomBytes(24).toString("base64").replace(/[^a-zA-Z0-9]/g, "");
    return `akeno_${randomString}`;
}

app.use(async (req, res, next) => {
    await CheckMilWares.handle(req, res, next);
});
app.disable("x-powered-by");
app.disable("link")
app.use(cors({
    origin: '*',
    methods: ['GET', 'POST'],
    allowedHeaders: ['Content-Type', 'Authorization']
}));

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);

const specs = swaggerJsDoc(swaggerOptions);

app.delete("/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("/v1/show-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.findOne({ key: apiKey });

        if (DocsKey) {
            res.json({
                owner: DocsKey.owner,
                createdAt: DocsKey.createdAt
            });
        } else {
            res.status(404).json({ message: "API key not found" });
        }
    } catch (err) {
        res.status(500).json({ error: `Key retrieval failed: ${err.message}` });
    }
});

app.post("/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() });
        } 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('/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 });
    }
    const userDocument = {
      key: newKey,
      createdAt: new Date(),
      owner: userIdNumber
    };
    if (email) {
      userDocument.email = email;
    }
    await collection.insertOne(userDocument);
    res.json({ apiKey: newKey });
  } 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);