|
|
|
@ -19,16 +19,16 @@ appConfig.use(express.static(__dirname + '/node_modules/@mdi/font'))
|
|
|
|
|
|
|
|
|
|
async function minuteCheck() {
|
|
|
|
|
let timeRN = moment()
|
|
|
|
|
console.log('timeRN', timeRN.format("HH:mm"))
|
|
|
|
|
//console.log('timeRN', timeRN.format("HH:mm"))
|
|
|
|
|
for (let alarm of config.alarms) {
|
|
|
|
|
let alarmTime = moment()
|
|
|
|
|
.hours(+alarm.alarmTime.split(':') [ 0 ])
|
|
|
|
|
.minutes(+alarm.alarmTime.split(':') [ 1 ])
|
|
|
|
|
let secDiff = alarmTime.diff(timeRN, 'seconds')
|
|
|
|
|
//
|
|
|
|
|
console.log(alarmTime.format("HH:mm"), secDiff)
|
|
|
|
|
//console.log(alarmTime.format("HH:mm"), secDiff)
|
|
|
|
|
if (alarmTime.format("HH:mm") == timeRN.format("HH:mm")) {
|
|
|
|
|
console.log("TRIGGER", alarm.alarmSchedulingMode)
|
|
|
|
|
//console.log("TRIGGER", alarm.alarmSchedulingMode)
|
|
|
|
|
let alarmTrigger = false
|
|
|
|
|
switch (alarm.alarmSchedulingMode) {
|
|
|
|
|
case 'monthlyAtSpecificDate':
|
|
|
|
@ -41,15 +41,15 @@ async function minuteCheck() {
|
|
|
|
|
while (monthFirstDay.weekday() != alarm.firstOccWeekday) monthFirstDay.add(1, 'day')
|
|
|
|
|
thisMonthFirstWeekDayOccurance = monthFirstDay.date()
|
|
|
|
|
|
|
|
|
|
console.log(monthFirstDay.date(), monthFirstDay.weekday())
|
|
|
|
|
console.log('monthly first occurance for', alarm.firstOccWeekday, 'is', thisMonthFirstWeekDayOccurance)
|
|
|
|
|
//console.log(monthFirstDay.date(), monthFirstDay.weekday())
|
|
|
|
|
//console.log('monthly first occurance for', alarm.firstOccWeekday, 'is', thisMonthFirstWeekDayOccurance)
|
|
|
|
|
alarmTrigger = (timeRN.date() == thisMonthFirstWeekDayOccurance)
|
|
|
|
|
break;
|
|
|
|
|
case 'weekly':
|
|
|
|
|
for (let weekDayKey of Object.keys(alarm.weekDay)) {
|
|
|
|
|
console.log(weekDayKey, alarm.weekDay)
|
|
|
|
|
//console.log(weekDayKey, alarm.weekDay)
|
|
|
|
|
if (+weekDayKey === +timeRN.weekday()) {
|
|
|
|
|
console.log('weekday match', 'result is', alarm.weekDay[weekDayKey] )
|
|
|
|
|
//console.log('weekday match', 'result is', alarm.weekDay[weekDayKey] )
|
|
|
|
|
alarmTrigger = alarm.weekDay[weekDayKey]
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -57,7 +57,10 @@ async function minuteCheck() {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (alarmTrigger === true) {
|
|
|
|
|
await axios.post(config.pager.url, Object.assign({ ...alarm.params }, { payload: alarm.payload }))
|
|
|
|
|
await axios.post(config.pager.url, Object.assign( !!alarm.preset
|
|
|
|
|
? { ...alarm.params } // backward compatibility
|
|
|
|
|
: { preset: alarm.preset }
|
|
|
|
|
, { payload: alarm.payload }))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -75,6 +78,10 @@ main()
|
|
|
|
|
appConfig.get('/config', async (req, res) => {
|
|
|
|
|
return res.json(JSON.parse(fs.readFileSync('config.json')))
|
|
|
|
|
})
|
|
|
|
|
appConfig.get('/api/deliveryPresets', async (req, res) => {
|
|
|
|
|
const presets = await axios.get(new URL(config.pager.url).origin + '/api/deliveryPresets')
|
|
|
|
|
return res.json(presets.data)
|
|
|
|
|
})
|
|
|
|
|
appConfig.post('/config', async (req, res) => {
|
|
|
|
|
if (!(!!req.body.alarms)) return res.status(403).json(false)
|
|
|
|
|
if (!(!!req.body.pager)) return res.status(403).json(false)
|
|
|
|
|