mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-24 07:14:04 +00:00
Validate cron before submit
This commit is contained in:
parent
511038b45a
commit
dbfaddafca
1 changed files with 12 additions and 1 deletions
|
@ -164,6 +164,7 @@ class Maintenance extends BeanModel {
|
||||||
if (bean.strategy === "cron") {
|
if (bean.strategy === "cron") {
|
||||||
bean.duration = obj.durationMinutes * 60;
|
bean.duration = obj.durationMinutes * 60;
|
||||||
bean.cron = obj.cron;
|
bean.cron = obj.cron;
|
||||||
|
this.validateCron(bean.cron);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bean.strategy.startsWith("recurring-")) {
|
if (bean.strategy.startsWith("recurring-")) {
|
||||||
|
@ -172,9 +173,19 @@ class Maintenance extends BeanModel {
|
||||||
bean.weekdays = JSON.stringify(obj.weekdays);
|
bean.weekdays = JSON.stringify(obj.weekdays);
|
||||||
bean.days_of_month = JSON.stringify(obj.daysOfMonth);
|
bean.days_of_month = JSON.stringify(obj.daysOfMonth);
|
||||||
await bean.generateCron();
|
await bean.generateCron();
|
||||||
|
this.validateCron(bean.cron);
|
||||||
|
}
|
||||||
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bean;
|
/**
|
||||||
|
* Throw error if cron is invalid
|
||||||
|
* @param cron
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
static async validateCron(cron) {
|
||||||
|
let job = new Cron(cron, () => {});
|
||||||
|
job.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue