refactor: 集中管理配置常量并优化样式一致性

This commit is contained in:
zhang1106
2026-03-06 14:39:52 +08:00
parent 0cd0107008
commit 885ac47fd2
19 changed files with 348 additions and 64 deletions
+39
View File
@@ -0,0 +1,39 @@
/**
* 通用配置常量
* 集中管理分页、文件上传、重试等配置
*/
module.exports = {
PAGINATION: {
DEFAULT_PAGE_SIZE: parseInt(process.env.DEFAULT_PAGE_SIZE, 10) || 10,
MAX_PAGE_SIZE: parseInt(process.env.MAX_PAGE_SIZE, 10) || 1000,
PAGE_SIZE_OPTIONS: [10, 20, 30, 50, 100],
},
FILE_UPLOAD: {
MAX_FILE_SIZE: (parseInt(process.env.MAX_FILE_SIZE_MB, 10) || 50) * 1024 * 1024,
MAX_AVATAR_SIZE: (parseInt(process.env.MAX_AVATAR_SIZE_MB, 10) || 5) * 1024 * 1024,
ALLOWED_IMAGE_TYPES: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
ALLOWED_DOC_TYPES: [
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
],
},
RETRY: {
MAX_RETRIES: parseInt(process.env.MAX_RETRIES, 10) || 3,
RETRY_DELAY: parseInt(process.env.RETRY_DELAY, 10) || 1000,
},
TIMEOUT: {
API_TIMEOUT: parseInt(process.env.API_TIMEOUT, 10) || 30000,
DB_QUERY_TIMEOUT: parseInt(process.env.DB_QUERY_TIMEOUT, 10) || 30000,
},
FRONTEND: {
DEFAULT_PORT: parseInt(process.env.FRONTEND_PORT, 10) || 3000,
},
};
+13
View File
@@ -0,0 +1,13 @@
/**
* 配置统一导出
*/
const security = require('./security');
const constants = require('./constants');
module.exports = {
...security,
...constants,
security,
constants,
};
+19
View File
@@ -0,0 +1,19 @@
/**
* 安全相关配置常量
* 集中管理密码加密、登录限制等安全配置
*/
module.exports = {
SALT_ROUNDS: parseInt(process.env.SALT_ROUNDS, 10) || 10,
MAX_LOGIN_ATTEMPTS: parseInt(process.env.MAX_LOGIN_ATTEMPTS, 10) || 5,
LOCK_TIME: (parseInt(process.env.LOCK_TIME_MINUTES, 10) || 30) * 60 * 1000,
TOKEN_EXPIRY: process.env.TOKEN_EXPIRY || '24h',
PASSWORD_MIN_LENGTH: parseInt(process.env.PASSWORD_MIN_LENGTH, 10) || 6,
USERNAME_MIN_LENGTH: parseInt(process.env.USERNAME_MIN_LENGTH, 10) || 3,
USERNAME_MAX_LENGTH: parseInt(process.env.USERNAME_MAX_LENGTH, 10) || 50,
};