refactor: 重构项目结构并优化类型定义
- 移除extension模块,将功能迁移至node-agent - 修复类型导出问题,使用export type明确类型导出 - 统一数据库连接方式,从直接导入改为使用config/database - 更新文档中的项目结构描述 - 添加多个服务的实用方法,如getForecast、getBalances等 - 修复类型错误和TS1205警告 - 优化RedisService调用方式 - 添加新的实体类型定义 - 更新审计日志格式,统一字段命名
This commit is contained in:
45
server/fix-safe-final.js
Normal file
45
server/fix-safe-final.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const filePath = path.join(__dirname, 'src/core/security/SecurityHardeningService.ts');
|
||||
|
||||
// 使用 Buffer 读取文件,确保不改变编码
|
||||
const buffer = fs.readFileSync(filePath);
|
||||
let content = buffer.toString('utf8');
|
||||
|
||||
console.log('Original lines:', content.split('\n').length);
|
||||
console.log('Original bytes:', buffer.length);
|
||||
|
||||
// 1. 替换导入语句
|
||||
content = content.replace(
|
||||
"import { RedisService } from '../cache/RedisService';",
|
||||
"import RedisService from '../../services/RedisService';"
|
||||
);
|
||||
|
||||
// 2. 替换 securityCheckInterval 属性
|
||||
content = content.replace(
|
||||
'private securityCheckInterval: NodeJS.Timeout;',
|
||||
'private securityCheckInterval!: NodeJS.Timeout;'
|
||||
);
|
||||
|
||||
// 3. 移除构造函数中的 redisService 参数
|
||||
content = content.replace(
|
||||
/constructor\(\s*private readonly configService: ConfigService,\s*private readonly redisService: RedisService,\s*\) \{\}/,
|
||||
'constructor(\n private readonly configService: ConfigService,\n ) {}'
|
||||
);
|
||||
|
||||
// 4. 替换所有 this.redisService. 为 RedisService.
|
||||
content = content.replace(/this\.redisService\./g, 'RedisService.');
|
||||
|
||||
// 5. 修复 RedisService.set 调用 - 移除 'EX' 参数
|
||||
// 只替换 , 'EX', 数字 的模式(包括换行)
|
||||
content = content.replace(/,\s*'EX',\s*(\d+)/g, ', $1');
|
||||
|
||||
console.log('After replacement lines:', content.split('\n').length);
|
||||
console.log('After replacement bytes:', Buffer.byteLength(content, 'utf8'));
|
||||
|
||||
// 使用 Buffer 写入文件,确保不添加 BOM
|
||||
const newBuffer = Buffer.from(content, 'utf8');
|
||||
fs.writeFileSync(filePath, newBuffer);
|
||||
|
||||
console.log('File updated successfully');
|
||||
Reference in New Issue
Block a user