38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
|
|
const fs = require('fs');
|
||
|
|
const path = require('path');
|
||
|
|
|
||
|
|
const filePath = path.join(__dirname, 'src/core/security/SecurityHardeningService.ts');
|
||
|
|
let content = fs.readFileSync(filePath, 'utf8');
|
||
|
|
|
||
|
|
console.log('Original lines:', content.split('\n').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*/g, ', ');
|
||
|
|
|
||
|
|
console.log('After replacement lines:', content.split('\n').length);
|
||
|
|
|
||
|
|
fs.writeFileSync(filePath, content, 'utf8');
|
||
|
|
console.log('File updated successfully');
|