Update middleware/midware.js
Browse files- middleware/midware.js +8 -0
middleware/midware.js
CHANGED
@@ -12,6 +12,7 @@ const EXTRA_ALLOWED_UA = [
|
|
12 |
|
13 |
const authenticateApiKeyPremium = async (req, res, next) => {
|
14 |
const apiKey = req.headers['x-api-key'];
|
|
|
15 |
const ua = req.headers['user-agent'];
|
16 |
|
17 |
const isAllowed = ALLOWED_UA_REGEX.test(ua || "") ||
|
@@ -28,6 +29,13 @@ const authenticateApiKeyPremium = async (req, res, next) => {
|
|
28 |
return res.status(401).json({ error: 'Premium API Key required' });
|
29 |
}
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
try {
|
32 |
const keyData = await ApiKey.findOne({ key: apiKey });
|
33 |
if (!keyData) {
|
|
|
12 |
|
13 |
const authenticateApiKeyPremium = async (req, res, next) => {
|
14 |
const apiKey = req.headers['x-api-key'];
|
15 |
+
const validRyzenthKey = /^sk-ryzenth-[a-zA-Z]{10}$/;
|
16 |
const ua = req.headers['user-agent'];
|
17 |
|
18 |
const isAllowed = ALLOWED_UA_REGEX.test(ua || "") ||
|
|
|
29 |
return res.status(401).json({ error: 'Premium API Key required' });
|
30 |
}
|
31 |
|
32 |
+
if (!validRyzenthKey.test(apiKey)) {
|
33 |
+
return res.status(402).json({
|
34 |
+
status: "error",
|
35 |
+
message: "API Key disabled or invalid. Please upgrade to sk-ryzenth-* format."
|
36 |
+
});
|
37 |
+
}
|
38 |
+
|
39 |
try {
|
40 |
const keyData = await ApiKey.findOne({ key: apiKey });
|
41 |
if (!keyData) {
|