feat: 完善后台导入日志权限与备份恢复
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { Cron, CronExpression } from '@nestjs/schedule';
|
||||
import { SettingsService } from '../settings/settings.service';
|
||||
import { OperationLogService } from './operation-log.service';
|
||||
|
||||
@Injectable()
|
||||
export class OperationLogRetentionService {
|
||||
private readonly logger = new Logger(OperationLogRetentionService.name);
|
||||
|
||||
constructor(
|
||||
private readonly settings: SettingsService,
|
||||
private readonly logs: OperationLogService,
|
||||
) {}
|
||||
|
||||
@Cron(CronExpression.EVERY_DAY_AT_4AM)
|
||||
async cleanup(): Promise<void> {
|
||||
const raw = await this.settings.get('operationLogRetentionDays');
|
||||
const days = Number(raw ?? 365);
|
||||
if (!days || days <= 0) return;
|
||||
const count = await this.logs.cleanup(days);
|
||||
this.logger.log(`操作日志清理完成:${count} 条,保留 ${days} 天`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user