配置改为数据库存储
将运行时 JSON 配置迁入 app_config_entries,启动时从文件导入并删除源文件。
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import path from 'node:path'
|
||||
|
||||
import { APP_CONFIG_KEYS } from '../../config/app-config-keys.js'
|
||||
import { PROJECT_ROOT } from '../../config/runtime.js'
|
||||
import { readJsonFile, writeJsonFile } from '../../utils/json-file-store.js'
|
||||
import {
|
||||
readAppConfigEntry,
|
||||
saveAppConfigEntry,
|
||||
} from '../config/app-config-store.js'
|
||||
|
||||
const NOTIFICATION_CONFIG_FILE_PATH = path.join(PROJECT_ROOT, 'data', 'notification-config.json')
|
||||
const DEFAULT_BARK_SERVER_URL = 'https://api.day.app'
|
||||
@@ -20,11 +24,21 @@ export function getNotificationConfigFilePath() {
|
||||
}
|
||||
|
||||
export function getNotificationConfig() {
|
||||
return loadNotificationConfigFromFile()
|
||||
return readAppConfigEntry({
|
||||
configKey: APP_CONFIG_KEYS.notification,
|
||||
legacyFilePath: NOTIFICATION_CONFIG_FILE_PATH,
|
||||
fallback: createDefaultNotificationConfig,
|
||||
normalize: normalizeNotificationConfig,
|
||||
})
|
||||
}
|
||||
|
||||
export function saveNotificationConfig(rawValue: unknown) {
|
||||
return writeJsonFile(NOTIFICATION_CONFIG_FILE_PATH, rawValue, normalizeNotificationConfig)
|
||||
return saveAppConfigEntry({
|
||||
configKey: APP_CONFIG_KEYS.notification,
|
||||
legacyFilePath: NOTIFICATION_CONFIG_FILE_PATH,
|
||||
value: rawValue,
|
||||
normalize: normalizeNotificationConfig,
|
||||
})
|
||||
}
|
||||
|
||||
export function listEnabledBarkRecipients(config: JsonObject = getNotificationConfig()) {
|
||||
@@ -45,14 +59,6 @@ export function listEnabledWpushRecipients(config: JsonObject = getNotificationC
|
||||
.filter((item: JsonObject) => item.enabled !== false && String(item.apiKey || item.apikey || '').trim())
|
||||
}
|
||||
|
||||
function loadNotificationConfigFromFile() {
|
||||
return readJsonFile(
|
||||
NOTIFICATION_CONFIG_FILE_PATH,
|
||||
createDefaultNotificationConfig,
|
||||
normalizeNotificationConfig,
|
||||
)
|
||||
}
|
||||
|
||||
export function normalizeNotificationConfig(rawValue: unknown) {
|
||||
const source = isPlainObject(rawValue) ? rawValue : {}
|
||||
const bark = isPlainObject(source.channels?.bark) ? source.channels.bark : {}
|
||||
|
||||
Reference in New Issue
Block a user