-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
142 lines (109 loc) · 4.42 KB
/
index.js
File metadata and controls
142 lines (109 loc) · 4.42 KB
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
const express = require("express");
const path = require("path");
const axios = require("axios");
const chalkAnimation = require('chalkercli');
const chalk = require('chalk');
const pinterestAPI = require("./API/PINTEREST/pinte");
const blackAIAPI = require("./API/AI/blackai");
const geminiAPI = require("./API/AI/gemini");
const Bardai = require('./API/BARD/bard');;
const app = express();
app.set("port", process.env.PORT || 8888);
app.use(express.static(path.join(__dirname, "public")));
// In-memory storage to keep track of the last access time for each route
const cooldowns = {};
app.use((req, res, next) => {
console.log(`[ STATUS ] -> IP: ${req.ip} - Requested path: ${req.path}${req.url}`);
// Check if the route has a cooldown period
const cooldownPeriod = 5000; // 50 seconds in milliseconds
const routeKey = req.path.toLowerCase();
if (cooldowns[routeKey] && Date.now() - cooldowns[routeKey] < cooldownPeriod) {
return res.status(429).json({ error: `Cooldown period active. Please wait ${Math.ceil((cooldowns[routeKey] + cooldownPeriod - Date.now()) / 1000)} seconds before making another request.` });
}
// Update the last access time for the route
cooldowns[routeKey] = Date.now();
next();
});
// Loading animation function
const loadingAnimation = async () => {
let str = String.raw`
LOADING API[▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒]
`;
const karaoke = chalkAnimation.karaoke(str);
karaoke.start();
await new Promise(resolve => {
setTimeout(() => {
karaoke.stop();
console.clear();
resolve();
}, 7000);
});
};
const banner = (data) => {
const rdcl = ['blue', 'yellow', 'green', 'red', 'magenta', 'yellowBright', 'blueBright', 'magentaBright'];
const color = chalk[rdcl[Math.floor(Math.random() * rdcl.length)]];
console.log(color(data));
};
// Log function
const log = (data, type) => {
var color = ["\x1b[33m", "\x1b[34m", "\x1b[35m", '\x1b[36m', '\x1b[32m'];
var more = color[Math.floor(Math.random() * color.length)];
console.log(more + `[ ${type} ] -> ` + data);
};
// Pinterest API
app.all("/pinterest", async (req, res) => {
await loadingAnimation();
pinterestAPI(req, res);
const bannerMessage = "Pinterest API request completed!";
log(bannerMessage, 'INFO');
banner(bannerMessage);
});
// Custom BlackAI API
app.get("/blackai", async (req, res) => {
await loadingAnimation();
await blackAIAPI(req, res);
const bannerMessage = "BlackAI API request completed!";
log(bannerMessage, 'INFO');
banner(bannerMessage);
});
app.all("/heroku", async (req, res) => {
try {
await loadingAnimation();
await geminiAPI(req, res);
const bannerMessage = "Heroku API request completed!";
log(bannerMessage, 'INFO');
banner(bannerMessage);
// Instead of sending a response here, you can just end the request
res.end();
} catch (error) {
console.error(error);
res.status(500).json({ error: 'An error occurred during the Heroku API request.' });
}
});
app.get("/bard", async (req, res) => {
try {
await loadingAnimation();
const bardInstance = new Bardai(/* pass required parameters here */);
await bardInstance.login(); // Call the login method or other relevant methods
// Perform chat or other actions here
const userMessage = req.query.ask; // Assuming the user's message is passed as a query parameter
if (!userMessage) {
return res.status(400).json({ error: 'Message query parameter is missing.' });
}
// Call the chat method or other relevant methods based on your Bardai class
const bardResponse = await bardInstance.chat(userMessage);
// Your logic to handle bardResponse, format the data, etc.
const bannerMessage = "Bard API request completed!";
log(bannerMessage, 'INFO');
banner(bannerMessage);
// Instead of sending a response here, you can just end the request
res.end();
} catch (error) {
console.error(error);
res.status(500).json({ error: 'An error occurred during the Bard API request.' });
}
});
// Start the server
app.listen(app.get("port"), () => {
console.log(`\x1b[35m\x1b[1mServer is running on port ${app.get("port")}\x1b[0m`);
});