feat(settings): 集中刷新策略与账号授权并独立设置审计
build / build (push) Successful in 1m11s

This commit is contained in:
姚章浩
2026-10-27 09:28:16 +08:00
parent a55d7f454e
commit 8930ef29cd
8 changed files with 520 additions and 214 deletions
+35
View File
@@ -0,0 +1,35 @@
import {
activateSourceSettingsRevision,
createSourceSettingsRevision,
fetchSourceSettingsRevisions,
} from './sourceConnections'
import type { SourceConnectionListItem, SourceSettingsRevision } from './sourceConnections'
export function configuredInterval(connection: SourceConnectionListItem, revisions: SourceSettingsRevision[]): number {
const active = revisions.find((item) => item.state === 'active')
if (active) {
const seconds = Number(active.refresh_interval_seconds ?? 0)
if (!Number.isInteger(seconds) || seconds < 0) throw new Error('刷新周期无效,未修改设置')
return seconds
}
if (connection.schedule_configured) throw new Error(`${connection.name}:无法读取活动刷新策略,未修改设置`)
return 0
}
export async function saveSourceRefresh(
connection: SourceConnectionListItem,
enabled: boolean,
interval?: number
): Promise<void> {
const seconds = interval ?? configuredInterval(connection, await fetchSourceSettingsRevisions(connection.id))
if (!enabled && connection.source_type === 'manual') throw new Error('手工来源不支持自动刷新')
const created = await createSourceSettingsRevision(connection.id, {
source_type: connection.source_type,
name: connection.name,
endpoint: '',
credential_ref: '',
enabled,
schedule: { refresh_interval_seconds: seconds > 0 ? seconds : null },
})
await activateSourceSettingsRevision(connection.id, created.id)
}