Files
Genarrative/scripts/check-api-server-env.mjs
T
lhk229 f14702362f 部署侧接线阿里云抠图凭证,避免抠图兜底静默塌成两级
aliyun_matting_enabled 默认 true,但 env 模板/校验器从未提供
GENARRATIVE_ALIYUN_MATTING_ACCESS_KEY_*,标准部署里 build_matting_client 因缺 key
返回 None,BgFilter 失败直接本地去背,与三级兜底设计口径不符。
- 两份 api-server.env.example 补 matting 段(enabled/endpoint/AccessKey 占位/timeout)
- check-api-server-env.mjs 增可选告警:enabled 但缺 AccessKey 时提示兜底层被跳过
- 开发运维文档补记该层需配 AccessKey 才生效

密钥与 OSS/SMS/token 一致,只留空占位由运维填,不写进 provision/deploy 脚本。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 08:54:28 +00:00

81 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {mergeApiServerEnv} from './dev-utils.mjs';
const REQUIRED_FOR_PUZZLE_GENERATION = [
'VECTOR_ENGINE_BASE_URL',
'VECTOR_ENGINE_API_KEY',
'ALIYUN_OSS_BUCKET',
'ALIYUN_OSS_ENDPOINT',
'ALIYUN_OSS_ACCESS_KEY_ID',
'ALIYUN_OSS_ACCESS_KEY_SECRET',
];
const COMMON_MISTYPED_KEYS = [
'ALIYUN_0SS_BUCKET',
'ALIYUN_0SS_ENDPOINT',
'ALIYUN_0SS_ACCESS_KEY_ID',
'ALIYUN_0SS_ACCESS_KEY_SECRET',
];
function hasValue(value) {
return typeof value === 'string' && value.trim().length > 0;
}
function printStatus(key, present) {
console.log(`${key}: ${present ? 'present' : 'missing'}`);
}
const env = mergeApiServerEnv(process.cwd(), process.env);
const missing = [];
console.log('[api-server-env] 认证短信配置检查');
printStatus('SMS_AUTH_ENABLED', env.SMS_AUTH_ENABLED === 'true');
printStatus('SMS_AUTH_PROVIDER', hasValue(env.SMS_AUTH_PROVIDER));
console.log('[api-server-env] 拼图真实生成配置检查');
for (const key of REQUIRED_FOR_PUZZLE_GENERATION) {
const present = hasValue(env[key]);
printStatus(key, present);
if (!present) {
missing.push(key);
}
}
const typoKeys = COMMON_MISTYPED_KEYS.filter((key) => hasValue(env[key]));
if (typoKeys.length > 0) {
console.log(
`[api-server-env] 检测到疑似拼错的 OSS 键名:${typoKeys.join(', ')}`,
);
}
// 阿里云通用抠图兜底层:默认 enabled=true,但 AccessKey 缺失时会被静默跳过,
// BgFilter 失败直接本地去背(质量下降)。属可选降级项,只告警不阻断部署。
console.log('[api-server-env] 抠图兜底(阿里云通用抠图)配置检查');
const mattingEnabled = env.GENARRATIVE_ALIYUN_MATTING_ENABLED !== 'false';
const mattingKeyPresent =
hasValue(env.GENARRATIVE_ALIYUN_MATTING_ACCESS_KEY_ID) ||
hasValue(env.ALIBABA_CLOUD_ACCESS_KEY_ID);
const mattingSecretPresent =
hasValue(env.GENARRATIVE_ALIYUN_MATTING_ACCESS_KEY_SECRET) ||
hasValue(env.ALIBABA_CLOUD_ACCESS_KEY_SECRET);
printStatus(
'GENARRATIVE_ALIYUN_MATTING_ACCESS_KEY_ID / ALIBABA_CLOUD_ACCESS_KEY_ID',
mattingKeyPresent,
);
printStatus(
'GENARRATIVE_ALIYUN_MATTING_ACCESS_KEY_SECRET / ALIBABA_CLOUD_ACCESS_KEY_SECRET',
mattingSecretPresent,
);
if (mattingEnabled && !(mattingKeyPresent && mattingSecretPresent)) {
console.warn(
'[api-server-env] 警告:GENARRATIVE_ALIYUN_MATTING_ENABLED 未关闭但缺少 AccessKey' +
'阿里云抠图兜底层将被跳过,BgFilter 失败后直接本地去背(质量下降)。',
);
}
if (missing.length > 0) {
console.error(`[api-server-env] 缺少:${missing.join(', ')}`);
process.exit(1);
}
console.log('[api-server-env] 配置齐全。重启 npm run dev:api-server 或 npm run dev 后生效。');