Spaces:
Running
Running
Update main.ts
Browse files
main.ts
CHANGED
|
@@ -374,6 +374,14 @@ const pipe = new Pipe();
|
|
| 374 |
// 验证 API 密钥
|
| 375 |
function verifyApiKey(request: Request) {
|
| 376 |
const authorization = request.headers.get('Authorization');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
if (!authorization) {
|
| 378 |
return new Response(JSON.stringify({ error: 'Missing API key' }), {
|
| 379 |
status: 401,
|
|
@@ -384,16 +392,15 @@ function verifyApiKey(request: Request) {
|
|
| 384 |
});
|
| 385 |
}
|
| 386 |
|
| 387 |
-
const apiKey = authorization.replace('Bearer ', '').trim();
|
| 388 |
if (apiKey !== VALID_API_KEY) {
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
|
| 398 |
return null;
|
| 399 |
}
|
|
|
|
| 374 |
// 验证 API 密钥
|
| 375 |
function verifyApiKey(request: Request) {
|
| 376 |
const authorization = request.headers.get('Authorization');
|
| 377 |
+
// 检查环境变量是否配置
|
| 378 |
+
if (!VALID_API_KEY) {
|
| 379 |
+
return new Response(JSON.stringify({ error: 'API key not configured' }), {
|
| 380 |
+
status: 500,
|
| 381 |
+
headers: { 'Content-Type': 'application/json' },
|
| 382 |
+
});
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
if (!authorization) {
|
| 386 |
return new Response(JSON.stringify({ error: 'Missing API key' }), {
|
| 387 |
status: 401,
|
|
|
|
| 392 |
});
|
| 393 |
}
|
| 394 |
|
|
|
|
| 395 |
if (apiKey !== VALID_API_KEY) {
|
| 396 |
+
return new Response(JSON.stringify({ error: 'Invalid API key' }), {
|
| 397 |
+
status: 401,
|
| 398 |
+
headers: {
|
| 399 |
+
'Content-Type': 'application/json',
|
| 400 |
+
'Access-Control-Allow-Origin': '*',
|
| 401 |
+
},
|
| 402 |
+
});
|
| 403 |
+
}
|
| 404 |
|
| 405 |
return null;
|
| 406 |
}
|