1
This commit is contained in:
51
scripts/check-api-server-env.mjs
Normal file
51
scripts/check-api-server-env.mjs
Normal file
@@ -0,0 +1,51 @@
|
||||
import { mergeApiServerEnv } from './api-server-dev.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] 拼图真实生成配置检查');
|
||||
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(', ')}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (missing.length > 0) {
|
||||
console.error(`[api-server-env] 缺少:${missing.join(', ')}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('[api-server-env] 配置齐全。重启 npm run api-server 或 npm run dev 后生效。');
|
||||
Reference in New Issue
Block a user