脱敏环科Gemini日志中的API密钥
This commit is contained in:
parent
a8445627dd
commit
ee890bc304
@ -7,6 +7,17 @@ interface HuankeGeminiConfig {
|
||||
baseURL: string;
|
||||
}
|
||||
|
||||
function redactSecrets(text: string, secrets: string[] = []) {
|
||||
let output = text;
|
||||
for (const secret of secrets) {
|
||||
if (!secret) continue;
|
||||
output = output.split(secret).join("***");
|
||||
}
|
||||
output = output.replace(/([?&]key=)[^&\s"']+/gi, "$1***");
|
||||
output = output.replace(/("apiKey"\s*:\s*")[^"]+(")/gi, "$1***$2");
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* 压缩图片生成缩略图(使用 sharp)
|
||||
*/
|
||||
@ -379,7 +390,7 @@ async function sendHuankeGeminiRequest(
|
||||
// 例如: https://api.example.com/v1beta/models/gemini-3-pro-image-preview-4k:generateContent
|
||||
const url = `${baseURL}/v1beta/models/${modelId}:generateContent?key=${apiKey}`;
|
||||
|
||||
console.log("[Huanke Gemini] Sending request to:", url.replace(apiKey, "***"));
|
||||
console.log("[Huanke Gemini] Sending request to:", redactSecrets(url, [apiKey]));
|
||||
console.log("[Huanke Gemini] Using model:", modelId);
|
||||
console.log("[Huanke Gemini] Image params:", imageParams);
|
||||
|
||||
@ -525,7 +536,7 @@ async function sendHuankeGeminiRequest(
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
const errorText = redactSecrets(await response.text(), [apiKey]);
|
||||
console.error("[Huanke Gemini] Request failed:", response.status, errorText);
|
||||
throw new Error(
|
||||
`Huanke Gemini API error: ${response.status} ${response.statusText} - ${errorText}`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user