refactor: 统一代码风格并迁移至 ESLint 新配置

style(backend): 格式化模型文件代码
style(frontend): 调整组件代码格式
chore: 删除旧 ESLint 配置并添加新配置
refactor(backend): 重构模型定义语法
style: 统一箭头函数和对象属性简写
This commit is contained in:
zhang1106
2026-03-27 19:12:16 +08:00
parent 6a8d4144ff
commit 63f0cb570e
166 changed files with 15483 additions and 11170 deletions
+18 -16
View File
@@ -11,11 +11,13 @@ function generateSecret(length = 64) {
function parseEnvContent(content) {
const lines = content.split('\n');
const result = {};
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
if (!trimmed || trimmed.startsWith('#')) {
continue;
}
const equalIndex = trimmed.indexOf('=');
if (equalIndex > 0) {
const key = trimmed.substring(0, equalIndex).trim();
@@ -23,26 +25,26 @@ function parseEnvContent(content) {
result[key] = value;
}
}
return result;
}
function stringifyEnvContent(envObj, originalContent) {
const lines = originalContent.split('\n');
const updatedLines = [];
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) {
updatedLines.push(line);
continue;
}
const equalIndex = trimmed.indexOf('=');
if (equalIndex > 0) {
const key = trimmed.substring(0, equalIndex).trim();
if (key === 'JWT_SECRET' && envObj.hasOwnProperty('JWT_SECRET')) {
updatedLines.push(`JWT_SECRET=${envObj.JWT_SECRET}`);
} else {
@@ -52,29 +54,29 @@ function stringifyEnvContent(envObj, originalContent) {
updatedLines.push(line);
}
}
return updatedLines.join('\n');
}
function ensureJwtSecret() {
const currentSecret = process.env.JWT_SECRET;
if (currentSecret && currentSecret.length >= 32) {
console.log('✓ JWT_SECRET 已配置');
return currentSecret;
}
if (process.env.NODE_ENV === 'production') {
throw new Error(
'[致命错误] 生产环境未设置 JWT_SECRET 环境变量!\n' +
'请在服务器环境变量中设置强密钥(至少32位随机字符)。\n' +
'生成命令(PowerShell):-join ((48..57) + (65..90) + (97..122) | Get-Random -Count 64 | ForEach-Object { [char]$_ })'
'请在服务器环境变量中设置强密钥(至少32位随机字符)。\n' +
'生成命令(PowerShell):-join ((48..57) + (65..90) + (97..122) | Get-Random -Count 64 | ForEach-Object { [char]$_ })'
);
}
const newSecret = generateSecret(64);
console.log('⚠️ JWT_SECRET 未配置或长度不足,正在自动生成...');
try {
if (fs.existsSync(ENV_FILE_PATH)) {
const originalContent = fs.readFileSync(ENV_FILE_PATH, 'utf-8');
@@ -90,7 +92,7 @@ JWT_SECRET=${newSecret}
fs.writeFileSync(ENV_FILE_PATH, defaultContent, 'utf-8');
console.log('✓ JWT_SECRET 已自动生成并创建 .env 文件');
}
process.env.JWT_SECRET = newSecret;
return newSecret;
} catch (err) {