Update middleware/midware.js
Browse files- middleware/midware.js +17 -1
middleware/midware.js
CHANGED
@@ -7,6 +7,13 @@ import * as config from '../config.js';
|
|
7 |
|
8 |
const authenticateApiKeyPremium = async (req, res, next) => {
|
9 |
const apiKey = req.headers['x-api-key'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
if (!apiKey) {
|
12 |
return res.status(401).json({ error: 'Premium API Key required' });
|
@@ -29,7 +36,7 @@ const authenticateApiKeyPremium = async (req, res, next) => {
|
|
29 |
if (keyData.expiresAt && new Date() > keyData.expiresAt) {
|
30 |
keyData.is_expired = true;
|
31 |
await keyData.save();
|
32 |
-
await TelegramUseLogNotif(keyData.owner, keyData.key);
|
33 |
return res.status(403).json({ error: 'Premium API Key has expired' });
|
34 |
}
|
35 |
|
@@ -72,6 +79,15 @@ const authenticateApiKey = async (req, res, next) => {
|
|
72 |
const apiKey = req.headers['x-api-key'];
|
73 |
const dbClient = new Database("AkenoXJs");
|
74 |
const db = dbClient.collection("api_keys");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
if (!apiKey) {
|
76 |
return res.status(401).json({ error: 'API Key required' });
|
77 |
}
|
|
|
7 |
|
8 |
const authenticateApiKeyPremium = async (req, res, next) => {
|
9 |
const apiKey = req.headers['x-api-key'];
|
10 |
+
const ua = req.headers['user-agent'];
|
11 |
+
if (!ua || !/^Ryzenth\/(Python|TS|Rust)-\d+\.\d+/.test(ua)) {
|
12 |
+
return res.status(403).json({
|
13 |
+
status: "error",
|
14 |
+
message: "Access blocked: Invalid or missing Ryzenth/Python User-Agent",
|
15 |
+
});
|
16 |
+
}
|
17 |
|
18 |
if (!apiKey) {
|
19 |
return res.status(401).json({ error: 'Premium API Key required' });
|
|
|
36 |
if (keyData.expiresAt && new Date() > keyData.expiresAt) {
|
37 |
keyData.is_expired = true;
|
38 |
await keyData.save();
|
39 |
+
// await TelegramUseLogNotif(keyData.owner, keyData.key);
|
40 |
return res.status(403).json({ error: 'Premium API Key has expired' });
|
41 |
}
|
42 |
|
|
|
79 |
const apiKey = req.headers['x-api-key'];
|
80 |
const dbClient = new Database("AkenoXJs");
|
81 |
const db = dbClient.collection("api_keys");
|
82 |
+
const ua = req.headers['user-agent'];
|
83 |
+
|
84 |
+
if (!ua || !/^Ryzenth\/(Python|TS|Rust)-\d+\.\d+/.test(ua)) {
|
85 |
+
return res.status(403).json({
|
86 |
+
status: "error",
|
87 |
+
message: "Access blocked: Invalid or missing Ryzenth/Python User-Agent",
|
88 |
+
});
|
89 |
+
}
|
90 |
+
|
91 |
if (!apiKey) {
|
92 |
return res.status(401).json({ error: 'API Key required' });
|
93 |
}
|