mirror of
https://github.com/whyour/qinglong.git
synced 2026-11-07 19:19:53 +08:00
Use MikroORM's official Node SQLite dialect with bounded database isolation, preserve legacy schema and data for rollback, and require Node 22.17 or newer. Update Debian runtimes and retain ARMv6 musl compatibility without a SQLite addon. Complete short archive writes, stop orphaned SQL workers after owner death, preserve buffered startup requests, and prestart the archived backend on every platform. Cover real package installation, migration, failure recovery, and legacy database compatibility. Keep authentication storage failures distinct from expired sessions with a pinned Keyv runtime, propagated cache errors, and retryable HTTP 503 responses. Preserve genuine 401 failures and verify legacy cache bytes, initialization safety, and session recovery.
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { Query, QuerySpec, orderBy } from '../data/queries';
|
|
import {
|
|
SystemModel,
|
|
AuthDataType,
|
|
NotifyStatus,
|
|
NotifyLogInfo,
|
|
} from '../data/system';
|
|
// Both backend sends and script reports use the same bounded, best-effort sink.
|
|
export async function persistNotificationAudit(
|
|
info: NotifyLogInfo,
|
|
): Promise<void> {
|
|
try {
|
|
await SystemModel.insert({
|
|
type: AuthDataType.notifyLog,
|
|
info: {
|
|
timestamp: Date.now(),
|
|
title: String(info.title || '').slice(0, 512),
|
|
content: String(info.content || '').slice(0, 8192),
|
|
status:
|
|
info.status === NotifyStatus.success
|
|
? NotifyStatus.success
|
|
: NotifyStatus.fail,
|
|
notifyType: String(info.notifyType || '').slice(0, 64),
|
|
source: info.source === 'script' ? 'script' : 'system',
|
|
scriptName: String(info.scriptName || '').slice(0, 512),
|
|
taskId: /^\d+$/.test(info.taskId || '') ? info.taskId : undefined,
|
|
},
|
|
});
|
|
const oldest = await SystemModel.find(
|
|
{ type: AuthDataType.notifyLog },
|
|
{
|
|
fields: ['id'],
|
|
orderBy: orderBy([['id', 'DESC']]),
|
|
offset: 200,
|
|
limit: 1,
|
|
},
|
|
);
|
|
if (oldest[0]?.id) {
|
|
await SystemModel.nativeDelete({
|
|
type: AuthDataType.notifyLog,
|
|
id: { ['$lte']: oldest[0].id },
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to persist notification audit log');
|
|
}
|
|
}
|