feat: add ntfy and telegram notification workflows
This commit is contained in:
@@ -16,7 +16,20 @@ const DEFAULT_SETTINGS = {
|
||||
storeId: '51450',
|
||||
description: 'TVS'
|
||||
}
|
||||
]
|
||||
],
|
||||
notifications: {
|
||||
ntfy: {
|
||||
enabled: false,
|
||||
serverUrl: 'https://ntfy.sh',
|
||||
topicPrefix: '',
|
||||
username: '',
|
||||
password: ''
|
||||
},
|
||||
telegram: {
|
||||
enabled: false,
|
||||
botToken: ''
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function ensureDir() {
|
||||
@@ -45,6 +58,33 @@ function sanitizeIgnoredSlots(slots = []) {
|
||||
.filter((slot) => slot.storeId);
|
||||
}
|
||||
|
||||
function sanitizeString(value) {
|
||||
if (typeof value === 'string') {
|
||||
return value.trim();
|
||||
}
|
||||
if (value === null || value === undefined) {
|
||||
return '';
|
||||
}
|
||||
return String(value).trim();
|
||||
}
|
||||
|
||||
function sanitizeNotifications(input = {}) {
|
||||
const defaults = DEFAULT_SETTINGS.notifications;
|
||||
return {
|
||||
ntfy: {
|
||||
enabled: !!(input?.ntfy?.enabled),
|
||||
serverUrl: sanitizeString(input?.ntfy?.serverUrl || defaults.ntfy.serverUrl),
|
||||
topicPrefix: sanitizeString(input?.ntfy?.topicPrefix || defaults.ntfy.topicPrefix),
|
||||
username: sanitizeString(input?.ntfy?.username || defaults.ntfy.username),
|
||||
password: sanitizeString(input?.ntfy?.password || defaults.ntfy.password)
|
||||
},
|
||||
telegram: {
|
||||
enabled: !!(input?.telegram?.enabled),
|
||||
botToken: sanitizeString(input?.telegram?.botToken || defaults.telegram.botToken)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function readSettings() {
|
||||
ensureDir();
|
||||
if (!fs.existsSync(SETTINGS_FILE)) {
|
||||
@@ -65,7 +105,8 @@ function readSettings() {
|
||||
parsed.storePickupCheckDelayMs,
|
||||
DEFAULT_SETTINGS.storePickupCheckDelayMs
|
||||
),
|
||||
ignoredSlots: sanitizeIgnoredSlots(parsed.ignoredSlots)
|
||||
ignoredSlots: sanitizeIgnoredSlots(parsed.ignoredSlots),
|
||||
notifications: sanitizeNotifications(parsed.notifications)
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Konnte Admin-Einstellungen nicht lesen:', error.message);
|
||||
@@ -88,7 +129,11 @@ function writeSettings(patch = {}) {
|
||||
ignoredSlots:
|
||||
patch.ignoredSlots !== undefined
|
||||
? sanitizeIgnoredSlots(patch.ignoredSlots)
|
||||
: current.ignoredSlots
|
||||
: current.ignoredSlots,
|
||||
notifications:
|
||||
patch.notifications !== undefined
|
||||
? sanitizeNotifications(patch.notifications)
|
||||
: current.notifications
|
||||
};
|
||||
|
||||
ensureDir();
|
||||
|
||||
Reference in New Issue
Block a user