diff --git a/internal/tts/microsoft/client.go b/internal/tts/microsoft/client.go index e3a19f2..86391cb 100644 --- a/internal/tts/microsoft/client.go +++ b/internal/tts/microsoft/client.go @@ -95,7 +95,7 @@ func (c *Client) getEndpoint(ctx context.Context) (map[string]interface{}, error // 更新缓存 c.endpointMu.Lock() c.endpoint = endpoint - c.endpointExpiry = time.Now().Add(30 * time.Minute) // 令牌有效期通常是1小时,提前刷新 + c.endpointExpiry = time.Now().Add(5 * time.Minute) c.endpointMu.Unlock() return endpoint, nil diff --git a/workers/src/index.js b/workers/src/index.js index a4ce9d7..77f5304 100644 --- a/workers/src/index.js +++ b/workers/src/index.js @@ -1,7 +1,6 @@ const encoder = new TextEncoder(); let expiredAt = null; let endpoint = null; -const API_KEY = 'your-secret-api-key'; // 添加 API 密钥常量,可以修改为你想要的值 // 定义需要保留的 SSML 标签模式 const preserveTags = [ @@ -73,7 +72,15 @@ async function handleRequest(request) { // 验证 API 密钥 if (!validateApiKey(apiKey)) { - return new Response('Unauthorized: Invalid API key', { status: 401 }); + // 改进 401 错误响应,提供更友好的错误信息 + return new Response(JSON.stringify({ + error: 'Unauthorized', + message: '无效的 API 密钥,请确保您提供了正确的密钥。', + status: 401 + }), { + status: 401, + headers: { 'Content-Type': 'application/json; charset=utf-8' } + }); } const text = requestUrl.searchParams.get('t') || ''; @@ -160,7 +167,7 @@ async function handleRequest(request) { -