通知系统-1

This commit is contained in:
yml2213
2026-05-14 17:29:12 +08:00
parent 91d74b3e59
commit b6c493d5e7
22 changed files with 1314 additions and 11 deletions
@@ -0,0 +1,62 @@
// @ts-check
import {
getNotificationConfig,
getNotificationConfigFilePath,
saveNotificationConfig,
} from '../../notification/config-service.js'
import { sendInternalNotification } from '../../notification/notification-service.js'
import { maskSecret } from './mappers.js'
/** @typedef {import('../../../types/admin-write-inputs.js').AdminNotificationConfigInput} AdminNotificationConfigInput */
/** @typedef {import('../../../types/admin-write-inputs.js').AdminNotificationTestInput} AdminNotificationTestInput */
export function getAdminNotificationConfig() {
const config = getNotificationConfig()
return {
filePath: getNotificationConfigFilePath(),
source: mapAdminNotificationConfig(config),
}
}
/** @param {AdminNotificationConfigInput} [payload] */
export function updateAdminNotificationConfig(payload = /** @type {AdminNotificationConfigInput} */ ({})) {
const saved = saveNotificationConfig(payload)
return {
filePath: getNotificationConfigFilePath(),
source: mapAdminNotificationConfig(saved),
}
}
/** @param {AdminNotificationTestInput} [payload] */
export async function testAdminNotification(payload = /** @type {AdminNotificationTestInput} */ ({})) {
return sendInternalNotification({
title: String(payload.title || '订单系统测试通知').trim() || '订单系统测试通知',
body: String(payload.body || '这是一条 Bark 内部通知测试。').trim() || '这是一条 Bark 内部通知测试。',
category: 'test',
url: String(payload.url || '').trim(),
})
}
function mapAdminNotificationConfig(config = {}) {
const bark = config.channels?.bark || {}
return {
enabled: config.enabled !== false,
channels: {
bark: {
enabled: bark.enabled !== false,
serverUrl: String(bark.serverUrl || 'https://api.day.app').trim(),
recipients: (Array.isArray(bark.recipients) ? bark.recipients : []).map((item) => ({
id: String(item.id || '').trim(),
name: String(item.name || '').trim(),
deviceKey: String(item.deviceKey || '').trim(),
deviceKeyMasked: maskSecret(item.deviceKey),
enabled: item.enabled !== false,
})),
},
},
}
}
@@ -49,3 +49,9 @@ export {
getAdminKuaishouCloudFulfillmentConfig,
updateAdminKuaishouCloudFulfillmentConfig,
} from './kuaishou-cloud-fulfillment-service.js'
export {
getAdminNotificationConfig,
updateAdminNotificationConfig,
testAdminNotification,
} from './notification-service.js'