增加xpush

This commit is contained in:
yml
2026-05-25 17:20:18 +08:00
parent 28c8575a11
commit 30728c40be
22 changed files with 794 additions and 81 deletions
@@ -29,6 +29,15 @@ export function listEnabledBarkRecipients(config: JsonObject = getNotificationCo
.filter((item) => item.enabled !== false && String(item.deviceKey || '').trim())
}
export function listEnabledWpushRecipients(config: JsonObject = getNotificationConfig()) {
if (config.enabled === false || config.channels?.wpush?.enabled === false) {
return []
}
return (Array.isArray(config.channels?.wpush?.recipients) ? config.channels.wpush.recipients : [])
.filter((item) => item.enabled !== false && String(item.apiKey || item.apikey || '').trim())
}
function loadNotificationConfigFromFile() {
return readJsonFile(
NOTIFICATION_CONFIG_FILE_PATH,
@@ -37,9 +46,10 @@ function loadNotificationConfigFromFile() {
)
}
function normalizeNotificationConfig(rawValue: unknown) {
export function normalizeNotificationConfig(rawValue: unknown) {
const source = isPlainObject(rawValue) ? rawValue : {}
const bark = isPlainObject(source.channels?.bark) ? source.channels.bark : {}
const wpush = isPlainObject(source.channels?.wpush) ? source.channels.wpush : {}
return {
enabled: typeof source.enabled === 'boolean' ? source.enabled : true,
@@ -51,6 +61,12 @@ function normalizeNotificationConfig(rawValue: unknown) {
.map((item) => normalizeBarkRecipient(item))
.filter(Boolean),
},
wpush: {
enabled: typeof wpush.enabled === 'boolean' ? wpush.enabled : true,
recipients: (Array.isArray(wpush.recipients) ? wpush.recipients : [])
.map((item) => normalizeWpushRecipient(item))
.filter(Boolean),
},
},
}
}
@@ -81,7 +97,28 @@ function normalizeBarkServerUrl(value: unknown) {
return normalized.replace(/\/+$/, '')
}
function createDefaultNotificationConfig() {
function normalizeWpushRecipient(rawValue: unknown) {
if (!isPlainObject(rawValue)) {
return null
}
const name = String(rawValue.name || '').trim()
const apiKey = String(rawValue.apiKey || rawValue.apikey || '').trim()
const id = String(rawValue.id || apiKey || name || '').trim()
if (!name && !apiKey) {
return null
}
return {
id,
name,
apiKey,
enabled: typeof rawValue.enabled === 'boolean' ? rawValue.enabled : true,
}
}
export function createDefaultNotificationConfig() {
return {
enabled: true,
channels: {
@@ -90,6 +127,10 @@ function createDefaultNotificationConfig() {
serverUrl: DEFAULT_BARK_SERVER_URL,
recipients: [],
},
wpush: {
enabled: true,
recipients: [],
},
},
}
}