forked from datawhale/whale-town-end
refactor:重构安全模块架构,将security模块迁移至core层
- 将src/business/security模块迁移至src/core/security_core - 更新模块导入路径和依赖关系 - 统一安全相关组件的命名规范(content_type.middleware.ts) - 清理过时的配置文件和文档 - 更新架构文档以反映新的模块结构 此次重构符合业务功能模块化架构设计原则,将技术基础设施 服务统一放置在core层,提高代码组织的清晰度和可维护性。
This commit is contained in:
@@ -12,9 +12,9 @@ import { ZulipModule } from './business/zulip/zulip.module';
|
||||
import { RedisModule } from './core/redis/redis.module';
|
||||
import { AdminModule } from './business/admin/admin.module';
|
||||
import { UserMgmtModule } from './business/user-mgmt/user-mgmt.module';
|
||||
import { SecurityModule } from './business/security/security.module';
|
||||
import { MaintenanceMiddleware } from './business/security/middleware/maintenance.middleware';
|
||||
import { ContentTypeMiddleware } from './business/security/middleware/content-type.middleware';
|
||||
import { SecurityCoreModule } from './core/security_core/security_core.module';
|
||||
import { MaintenanceMiddleware } from './core/security_core/middleware/maintenance.middleware';
|
||||
import { ContentTypeMiddleware } from './core/security_core/middleware/content_type.middleware';
|
||||
|
||||
/**
|
||||
* 检查数据库配置是否完整 by angjustinl 2025-12-17
|
||||
@@ -71,7 +71,7 @@ function isDatabaseConfigured(): boolean {
|
||||
ZulipModule,
|
||||
UserMgmtModule,
|
||||
AdminModule,
|
||||
SecurityModule,
|
||||
SecurityCoreModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
AdminUserResponseDto,
|
||||
AdminRuntimeLogsResponseDto
|
||||
} from './dto/admin-response.dto';
|
||||
import { Throttle, ThrottlePresets } from '../security/decorators/throttle.decorator';
|
||||
import { Throttle, ThrottlePresets } from '../../core/security_core/decorators/throttle.decorator';
|
||||
import type { Response } from 'express';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
@@ -33,8 +33,8 @@ import {
|
||||
TestModeEmailVerificationResponseDto,
|
||||
SuccessEmailVerificationResponseDto
|
||||
} from '../dto/login_response.dto';
|
||||
import { Throttle, ThrottlePresets } from '../../security/decorators/throttle.decorator';
|
||||
import { Timeout, TimeoutPresets } from '../../security/decorators/timeout.decorator';
|
||||
import { Throttle, ThrottlePresets } from '../../../core/security_core/decorators/throttle.decorator';
|
||||
import { Timeout, TimeoutPresets } from '../../../core/security_core/decorators/timeout.decorator';
|
||||
|
||||
@ApiTags('auth')
|
||||
@Controller('auth')
|
||||
|
||||
@@ -20,8 +20,8 @@ import { Body, Controller, Get, HttpCode, HttpStatus, Param, Put, Post, UseGuard
|
||||
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { AdminGuard } from '../../admin/guards/admin.guard';
|
||||
import { UserManagementService } from '../services/user-management.service';
|
||||
import { Throttle, ThrottlePresets } from '../../security/decorators/throttle.decorator';
|
||||
import { Timeout, TimeoutPresets } from '../../security/decorators/timeout.decorator';
|
||||
import { Throttle, ThrottlePresets } from '../../../core/security_core/decorators/throttle.decorator';
|
||||
import { Timeout, TimeoutPresets } from '../../../core/security_core/decorators/timeout.decorator';
|
||||
import { UserStatusDto, BatchUserStatusDto } from '../dto/user-status.dto';
|
||||
import { UserStatusResponseDto, BatchUserStatusResponseDto, UserStatusStatsResponseDto } from '../dto/user-status-response.dto';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* 安全功能模块导出
|
||||
* 核心安全模块导出
|
||||
*
|
||||
* 功能概述:
|
||||
* - 频率限制和防护机制
|
||||
@@ -10,14 +10,14 @@
|
||||
*/
|
||||
|
||||
// 模块
|
||||
export * from './security.module';
|
||||
export * from './security_core.module';
|
||||
|
||||
// 守卫
|
||||
export * from './guards/throttle.guard';
|
||||
|
||||
// 中间件
|
||||
export * from './middleware/maintenance.middleware';
|
||||
export * from './middleware/content-type.middleware';
|
||||
export * from './middleware/content_type.middleware';
|
||||
|
||||
// 拦截器
|
||||
export * from './interceptors/timeout.interceptor';
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* 安全功能模块
|
||||
* 核心安全模块
|
||||
*
|
||||
* 功能描述:
|
||||
* - 整合所有安全相关功能
|
||||
* - 提供系统级安全防护功能
|
||||
* - 频率限制和请求超时控制
|
||||
* - 维护模式和内容类型验证
|
||||
* - 系统安全防护机制
|
||||
* - 全局安全中间件和守卫
|
||||
*
|
||||
* @author kiro-ai
|
||||
* @version 1.0.0
|
||||
@@ -34,4 +34,4 @@ import { TimeoutInterceptor } from './interceptors/timeout.interceptor';
|
||||
],
|
||||
exports: [ThrottleGuard, TimeoutInterceptor],
|
||||
})
|
||||
export class SecurityModule {}
|
||||
export class SecurityCoreModule {}
|
||||
@@ -139,10 +139,39 @@ export class ConfigManagerService implements OnModuleDestroy {
|
||||
private configLoadTime: Date;
|
||||
private configWatcher: fs.FSWatcher | null = null;
|
||||
private isWatcherEnabled: boolean = false;
|
||||
private readonly CONFIG_DIR = path.join(process.cwd(), 'config', 'zulip');
|
||||
private readonly CONFIG_DIR = this.getConfigDir();
|
||||
private readonly MAP_CONFIG_FILE = 'map-config.json';
|
||||
private readonly logger = new Logger(ConfigManagerService.name);
|
||||
|
||||
/**
|
||||
* 获取配置目录路径
|
||||
*
|
||||
* 在开发环境中使用 config/zulip
|
||||
* 在生产环境中使用 dist/zulip (编译后的位置)
|
||||
*/
|
||||
private getConfigDir(): string {
|
||||
const isDevelopment = process.env.NODE_ENV !== 'production';
|
||||
|
||||
if (isDevelopment) {
|
||||
// 开发环境:使用源码目录
|
||||
return path.join(process.cwd(), 'config', 'zulip');
|
||||
} else {
|
||||
// 生产环境:使用编译后的目录
|
||||
const distConfigPath = path.join(process.cwd(), 'dist', 'zulip');
|
||||
const rootConfigPath = path.join(process.cwd(), 'config', 'zulip');
|
||||
|
||||
// 优先使用 dist/zulip,如果不存在则回退到 config/zulip
|
||||
if (fs.existsSync(distConfigPath)) {
|
||||
return distConfigPath;
|
||||
} else if (fs.existsSync(rootConfigPath)) {
|
||||
return rootConfigPath;
|
||||
} else {
|
||||
// 都不存在,使用默认路径
|
||||
return distConfigPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.logger.log('ConfigManagerService初始化完成');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user