feat: add notification audit log feature

Agent-Logs-Url: https://github.com/whyour/qinglong/sessions/4c9f0ab1-8b0e-4b94-b295-39c90ed942c2

Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-25 06:49:18 +00:00
committed by GitHub
co-authored by whyour
parent bcb2471768
commit 79964f149c
5 changed files with 179 additions and 0 deletions
+36
View File
@@ -30,6 +30,8 @@ import {
SystemInstance,
SystemModel,
SystemModelInfo,
NotifyStatus,
NotifyLogInfo,
} from '../data/system';
import taskLimit from '../shared/pLimit';
import NotificationService from './notify';
@@ -389,11 +391,33 @@ export default class SystemService {
if (notificationInfo && typeString) {
notificationInfo.type = typeString;
}
let notifyType: string | undefined;
try {
const notifConfig = await this.getDb({ type: AuthDataType.notification });
notifyType = notifConfig.info?.type as string | undefined;
} catch (e) {}
if (notificationInfo?.type) {
notifyType = typeString || (notificationInfo.type as string);
}
const isSuccess = await this.notificationService.notify(
title,
content,
notificationInfo,
);
await SystemModel.create({
type: AuthDataType.notifyLog,
info: {
timestamp: Date.now(),
title,
content,
status: isSuccess ? NotifyStatus.success : NotifyStatus.fail,
notifyType,
},
});
if (isSuccess) {
return { code: 200, message: '通知发送成功' };
} else {
@@ -401,6 +425,18 @@ export default class SystemService {
}
}
public async getNotifyLog(): Promise<Array<NotifyLogInfo>> {
const docs = await SystemModel.findAll({
where: { type: AuthDataType.notifyLog },
order: [['id', 'DESC']],
});
if (docs.length > 200) {
const ids = docs.slice(200).map((x) => x.id!);
await SystemModel.destroy({ where: { id: ids } });
}
return docs.slice(0, 200).map((x) => ({ ...x.info, id: x.id }));
}
public async run({ command, logPath }: { command: string; logPath?: string }, callback: TaskCallbacks) {
if (!command.startsWith(TASK_COMMAND)) {
command = `${TASK_COMMAND} ${command}`;