randydev commited on
Commit
ff5dd77
·
verified ·
1 Parent(s): e6acbde

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +10 -2
index.js CHANGED
@@ -24,9 +24,12 @@ const app = express();
24
  import * as swaggerUi from 'swagger-ui-express';
25
  import * as cheerio from 'cheerio';
26
  import * as lifestyle from './startup/lifestyle.js';
 
 
27
  import { Database } from './database/database.js'
28
  import { Readable } from "stream";
29
- import * as uuid from 'uuid';
 
30
  import {
31
  CheckMilWare,
32
  authenticateApiKey,
@@ -56,6 +59,11 @@ const __dirname = path.resolve();
56
  const CheckMilWares = new CheckMilWare();
57
  const myUUID = uuid.v4();
58
 
 
 
 
 
 
59
  app.disable("x-powered-by");
60
  app.disable("link")
61
  app.use(cors({
@@ -77,7 +85,7 @@ app.post('/generate-key', async (req, res) => {
77
  const dbClient = new Database("AkenoXJs", "FastJsAPI");
78
  const collection = dbClient.collection('api_keys');
79
  try {
80
- const newKey = myUUID;
81
  await collection.insertOne({
82
  key: newKey,
83
  createdAt: new Date(),
 
24
  import * as swaggerUi from 'swagger-ui-express';
25
  import * as cheerio from 'cheerio';
26
  import * as lifestyle from './startup/lifestyle.js';
27
+ import * as uuid from 'uuid';
28
+
29
  import { Database } from './database/database.js'
30
  import { Readable } from "stream";
31
+ import randomBytes } from "crypto";
32
+
33
  import {
34
  CheckMilWare,
35
  authenticateApiKey,
 
59
  const CheckMilWares = new CheckMilWare();
60
  const myUUID = uuid.v4();
61
 
62
+ function generateAkenoKey() {
63
+ const randomString = randomBytes(24).toString("base64").replace(/[^a-zA-Z0-9]/g, "");
64
+ return `akeno_${randomString}`;
65
+ }
66
+
67
  app.disable("x-powered-by");
68
  app.disable("link")
69
  app.use(cors({
 
85
  const dbClient = new Database("AkenoXJs", "FastJsAPI");
86
  const collection = dbClient.collection('api_keys');
87
  try {
88
+ const newKey = generateAkenoKey();
89
  await collection.insertOne({
90
  key: newKey,
91
  createdAt: new Date(),