|
|
@ -19,16 +19,16 @@ appConfig.use(express.static(__dirname + '/node_modules/@mdi/font'))
|
|
|
|
|
|
|
|
|
|
|
|
async function minuteCheck() {
|
|
|
|
async function minuteCheck() {
|
|
|
|
let timeRN = moment()
|
|
|
|
let timeRN = moment()
|
|
|
|
console.log('timeRN', timeRN.format("HH:mm"))
|
|
|
|
//console.log('timeRN', timeRN.format("HH:mm"))
|
|
|
|
for (let alarm of config.alarms) {
|
|
|
|
for (let alarm of config.alarms) {
|
|
|
|
let alarmTime = moment()
|
|
|
|
let alarmTime = moment()
|
|
|
|
.hours(+alarm.alarmTime.split(':') [ 0 ])
|
|
|
|
.hours(+alarm.alarmTime.split(':') [ 0 ])
|
|
|
|
.minutes(+alarm.alarmTime.split(':') [ 1 ])
|
|
|
|
.minutes(+alarm.alarmTime.split(':') [ 1 ])
|
|
|
|
let secDiff = alarmTime.diff(timeRN, 'seconds')
|
|
|
|
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")) {
|
|
|
|
if (alarmTime.format("HH:mm") == timeRN.format("HH:mm")) {
|
|
|
|
console.log("TRIGGER", alarm.alarmSchedulingMode)
|
|
|
|
//console.log("TRIGGER", alarm.alarmSchedulingMode)
|
|
|
|
let alarmTrigger = false
|
|
|
|
let alarmTrigger = false
|
|
|
|
switch (alarm.alarmSchedulingMode) {
|
|
|
|
switch (alarm.alarmSchedulingMode) {
|
|
|
|
case 'monthlyAtSpecificDate':
|
|
|
|
case 'monthlyAtSpecificDate':
|
|
|
@ -41,15 +41,15 @@ async function minuteCheck() {
|
|
|
|
while (monthFirstDay.weekday() != alarm.firstOccWeekday) monthFirstDay.add(1, 'day')
|
|
|
|
while (monthFirstDay.weekday() != alarm.firstOccWeekday) monthFirstDay.add(1, 'day')
|
|
|
|
thisMonthFirstWeekDayOccurance = monthFirstDay.date()
|
|
|
|
thisMonthFirstWeekDayOccurance = monthFirstDay.date()
|
|
|
|
|
|
|
|
|
|
|
|
console.log(monthFirstDay.date(), monthFirstDay.weekday())
|
|
|
|
//console.log(monthFirstDay.date(), monthFirstDay.weekday())
|
|
|
|
console.log('monthly first occurance for', alarm.firstOccWeekday, 'is', thisMonthFirstWeekDayOccurance)
|
|
|
|
//console.log('monthly first occurance for', alarm.firstOccWeekday, 'is', thisMonthFirstWeekDayOccurance)
|
|
|
|
alarmTrigger = (timeRN.date() == thisMonthFirstWeekDayOccurance)
|
|
|
|
alarmTrigger = (timeRN.date() == thisMonthFirstWeekDayOccurance)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'weekly':
|
|
|
|
case 'weekly':
|
|
|
|
for (let weekDayKey of Object.keys(alarm.weekDay)) {
|
|
|
|
for (let weekDayKey of Object.keys(alarm.weekDay)) {
|
|
|
|
console.log(weekDayKey, alarm.weekDay)
|
|
|
|
//console.log(weekDayKey, alarm.weekDay)
|
|
|
|
if (+weekDayKey === +timeRN.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]
|
|
|
|
alarmTrigger = alarm.weekDay[weekDayKey]
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -57,7 +57,10 @@ async function minuteCheck() {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (alarmTrigger === true) {
|
|
|
|
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) => {
|
|
|
|
appConfig.get('/config', async (req, res) => {
|
|
|
|
return res.json(JSON.parse(fs.readFileSync('config.json')))
|
|
|
|
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) => {
|
|
|
|
appConfig.post('/config', async (req, res) => {
|
|
|
|
if (!(!!req.body.alarms)) return res.status(403).json(false)
|
|
|
|
if (!(!!req.body.alarms)) return res.status(403).json(false)
|
|
|
|
if (!(!!req.body.pager)) return res.status(403).json(false)
|
|
|
|
if (!(!!req.body.pager)) return res.status(403).json(false)
|
|
|
|