- 移除extension模块,将功能迁移至node-agent - 修复类型导出问题,使用export type明确类型导出 - 统一数据库连接方式,从直接导入改为使用config/database - 更新文档中的项目结构描述 - 添加多个服务的实用方法,如getForecast、getBalances等 - 修复类型错误和TS1205警告 - 优化RedisService调用方式 - 添加新的实体类型定义 - 更新审计日志格式,统一字段命名
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
const fs = require('fs');
|
||
const file = 'd:\\trae_projects\\makemd\\makemd\\server\\src\\core\\security\\SecurityHardeningService.ts';
|
||
|
||
// 读取文件(使用 utf8 编码,不带 BOM)
|
||
let content = fs.readFileSync(file, 'utf8');
|
||
|
||
// 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' 参数
|
||
// 处理多行格式
|
||
content = content.replace(
|
||
/RedisService\.set\(\s*\n\s*`([^`]+)`,\s*\n\s*([^,]+),\s*\n\s*'EX',\s*\n\s*(\d+)(?:\s*\/\/[^\n]*)?\s*\n\s*\)/g,
|
||
"RedisService.set(\n `$1`,\n $2,\n $3\n )"
|
||
);
|
||
|
||
content = content.replace(
|
||
/RedisService\.set\(\s*\n\s*'([^']+)',\s*\n\s*([^,]+),\s*\n\s*'EX',\s*\n\s*(\d+)(?:\s*\/\/[^\n]*)?\s*\n\s*\)/g,
|
||
"RedisService.set(\n '$1',\n $2,\n $3\n )"
|
||
);
|
||
|
||
// 处理单行格式
|
||
content = content.replace(
|
||
/RedisService\.set\('([^']+)', ([^,]+), 'EX', (\d+)\)/g,
|
||
"RedisService.set('$1', $2, $3)"
|
||
);
|
||
|
||
content = content.replace(
|
||
/RedisService\.set\(`([^`]+)`, ([^,]+), 'EX', (\d+)\)/g,
|
||
"RedisService.set(`$1`, $2, $3)"
|
||
);
|
||
|
||
// 写入文件(使用 utf8 编码,不带 BOM)
|
||
fs.writeFileSync(file, content, 'utf8');
|
||
console.log('File updated successfully');
|