mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-24 10:12:59 +01:00
Compare commits
2 Commits
e1b27f8925
...
93ada90d08
Author | SHA1 | Date | |
---|---|---|---|
|
93ada90d08 | ||
7ba85fb3ac |
@ -17,7 +17,7 @@
|
||||
"ejs": "~3.1.6",
|
||||
"express": "~4.17.1",
|
||||
"form-data": "^4.0.0",
|
||||
"got": "^11.8.2",
|
||||
"got": "^12.0.1",
|
||||
"http-errors": "~1.8.0",
|
||||
"jquery": "^3.6.0",
|
||||
"moment": "^2.29.1",
|
||||
@ -56,9 +56,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@sindresorhus/is": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.1.tgz",
|
||||
"integrity": "sha512-Qm9hBEBu18wt1PO2flE7LPb30BHMQt1eQgbV76YntdNk73XZGpn3izvGTYxbGgzXKgbCjiia0uxTd3aTNQrY/g==",
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.2.1.tgz",
|
||||
"integrity": "sha512-BrzrgtaqEre0qfvI8sMTaEvx+bayuhPmfe2rfeUGPPHYr/PLxCOqkOe4TQTDPb+qcqgNcsAtXV/Ew74mcDIE8w==",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
@ -67,14 +67,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@szmarczak/http-timer": {
|
||||
"version": "4.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz",
|
||||
"integrity": "sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==",
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-5.0.1.tgz",
|
||||
"integrity": "sha512-+PmQX0PiAYPMeVYe237LJAYvOMYW1j2rH5YROyS3b4CTVJum34HfRvKvAzozHAQG0TnHNdUfY9nCeUyRAs//cw==",
|
||||
"dependencies": {
|
||||
"defer-to-connect": "^2.0.0"
|
||||
"defer-to-connect": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": ">=14.16"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/cacheable-request": {
|
||||
@ -272,9 +272,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/cacheable-lookup": {
|
||||
"version": "5.0.4",
|
||||
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz",
|
||||
"integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA==",
|
||||
"version": "6.0.4",
|
||||
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-6.0.4.tgz",
|
||||
"integrity": "sha512-mbcDEZCkv2CZF4G01kr8eBd/5agkt9oCqz75tJMSIsquvRZ2sL6Hi5zGVKi/0OSC9oO1GHfJ2AV0ZIOY9vye0A==",
|
||||
"engines": {
|
||||
"node": ">=10.6.0"
|
||||
}
|
||||
@ -735,6 +735,11 @@
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/form-data-encoder": {
|
||||
"version": "1.7.1",
|
||||
"resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.1.tgz",
|
||||
"integrity": "sha512-EFRDrsMm/kyqbTQocNvRXMLjc7Es2Vk+IQFx/YW7hkUH1eBl4J1fqiP34l74Yt0pFLCNpc06fkbVk00008mzjg=="
|
||||
},
|
||||
"node_modules/forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||
@ -766,29 +771,53 @@
|
||||
}
|
||||
},
|
||||
"node_modules/got": {
|
||||
"version": "11.8.2",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-11.8.2.tgz",
|
||||
"integrity": "sha512-D0QywKgIe30ODs+fm8wMZiAcZjypcCodPNuMz5H9Mny7RJ+IjJ10BdmGW7OM7fHXP+O7r6ZwapQ/YQmMSvB0UQ==",
|
||||
"version": "12.0.1",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-12.0.1.tgz",
|
||||
"integrity": "sha512-1Zhoh+lDej3t7Ks1BP/Jufn+rNqdiHQgUOcTxHzg2Dao1LQfp5S4Iq0T3iBxN4Zdo7QqCJL+WJUNzDX6rCP2Ew==",
|
||||
"dependencies": {
|
||||
"@sindresorhus/is": "^4.0.0",
|
||||
"@szmarczak/http-timer": "^4.0.5",
|
||||
"@types/cacheable-request": "^6.0.1",
|
||||
"@sindresorhus/is": "^4.2.0",
|
||||
"@szmarczak/http-timer": "^5.0.1",
|
||||
"@types/cacheable-request": "^6.0.2",
|
||||
"@types/responselike": "^1.0.0",
|
||||
"cacheable-lookup": "^5.0.3",
|
||||
"cacheable-request": "^7.0.1",
|
||||
"cacheable-lookup": "^6.0.4",
|
||||
"cacheable-request": "^7.0.2",
|
||||
"decompress-response": "^6.0.0",
|
||||
"http2-wrapper": "^1.0.0-beta.5.2",
|
||||
"lowercase-keys": "^2.0.0",
|
||||
"p-cancelable": "^2.0.0",
|
||||
"form-data-encoder": "1.7.1",
|
||||
"get-stream": "^6.0.1",
|
||||
"http2-wrapper": "^2.1.9",
|
||||
"lowercase-keys": "^3.0.0",
|
||||
"p-cancelable": "^3.0.0",
|
||||
"responselike": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.19.0"
|
||||
"node": ">=14.16"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sindresorhus/got?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/got/node_modules/get-stream": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz",
|
||||
"integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/got/node_modules/lowercase-keys": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-3.0.0.tgz",
|
||||
"integrity": "sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ==",
|
||||
"engines": {
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/has-flag": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||
@ -836,12 +865,12 @@
|
||||
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
|
||||
},
|
||||
"node_modules/http2-wrapper": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz",
|
||||
"integrity": "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==",
|
||||
"version": "2.1.10",
|
||||
"resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-2.1.10.tgz",
|
||||
"integrity": "sha512-QHgsdYkieKp+6JbXP25P+tepqiHYd+FVnDwXpxi/BlUcoIB0nsmTOymTNvETuTO+pDuwcSklPE72VR3DqV+Haw==",
|
||||
"dependencies": {
|
||||
"quick-lru": "^5.1.1",
|
||||
"resolve-alpn": "^1.0.0"
|
||||
"resolve-alpn": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.19.0"
|
||||
@ -1162,11 +1191,11 @@
|
||||
}
|
||||
},
|
||||
"node_modules/p-cancelable": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz",
|
||||
"integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==",
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-3.0.0.tgz",
|
||||
"integrity": "sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw==",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
"node": ">=12.20"
|
||||
}
|
||||
},
|
||||
"node_modules/parseurl": {
|
||||
@ -1636,16 +1665,16 @@
|
||||
"peer": true
|
||||
},
|
||||
"@sindresorhus/is": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.1.tgz",
|
||||
"integrity": "sha512-Qm9hBEBu18wt1PO2flE7LPb30BHMQt1eQgbV76YntdNk73XZGpn3izvGTYxbGgzXKgbCjiia0uxTd3aTNQrY/g=="
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.2.1.tgz",
|
||||
"integrity": "sha512-BrzrgtaqEre0qfvI8sMTaEvx+bayuhPmfe2rfeUGPPHYr/PLxCOqkOe4TQTDPb+qcqgNcsAtXV/Ew74mcDIE8w=="
|
||||
},
|
||||
"@szmarczak/http-timer": {
|
||||
"version": "4.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz",
|
||||
"integrity": "sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==",
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-5.0.1.tgz",
|
||||
"integrity": "sha512-+PmQX0PiAYPMeVYe237LJAYvOMYW1j2rH5YROyS3b4CTVJum34HfRvKvAzozHAQG0TnHNdUfY9nCeUyRAs//cw==",
|
||||
"requires": {
|
||||
"defer-to-connect": "^2.0.0"
|
||||
"defer-to-connect": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"@types/cacheable-request": {
|
||||
@ -1818,9 +1847,9 @@
|
||||
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
|
||||
},
|
||||
"cacheable-lookup": {
|
||||
"version": "5.0.4",
|
||||
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz",
|
||||
"integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA=="
|
||||
"version": "6.0.4",
|
||||
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-6.0.4.tgz",
|
||||
"integrity": "sha512-mbcDEZCkv2CZF4G01kr8eBd/5agkt9oCqz75tJMSIsquvRZ2sL6Hi5zGVKi/0OSC9oO1GHfJ2AV0ZIOY9vye0A=="
|
||||
},
|
||||
"cacheable-request": {
|
||||
"version": "7.0.2",
|
||||
@ -2180,6 +2209,11 @@
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"form-data-encoder": {
|
||||
"version": "1.7.1",
|
||||
"resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.1.tgz",
|
||||
"integrity": "sha512-EFRDrsMm/kyqbTQocNvRXMLjc7Es2Vk+IQFx/YW7hkUH1eBl4J1fqiP34l74Yt0pFLCNpc06fkbVk00008mzjg=="
|
||||
},
|
||||
"forwarded": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||
@ -2199,21 +2233,35 @@
|
||||
}
|
||||
},
|
||||
"got": {
|
||||
"version": "11.8.2",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-11.8.2.tgz",
|
||||
"integrity": "sha512-D0QywKgIe30ODs+fm8wMZiAcZjypcCodPNuMz5H9Mny7RJ+IjJ10BdmGW7OM7fHXP+O7r6ZwapQ/YQmMSvB0UQ==",
|
||||
"version": "12.0.1",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-12.0.1.tgz",
|
||||
"integrity": "sha512-1Zhoh+lDej3t7Ks1BP/Jufn+rNqdiHQgUOcTxHzg2Dao1LQfp5S4Iq0T3iBxN4Zdo7QqCJL+WJUNzDX6rCP2Ew==",
|
||||
"requires": {
|
||||
"@sindresorhus/is": "^4.0.0",
|
||||
"@szmarczak/http-timer": "^4.0.5",
|
||||
"@types/cacheable-request": "^6.0.1",
|
||||
"@sindresorhus/is": "^4.2.0",
|
||||
"@szmarczak/http-timer": "^5.0.1",
|
||||
"@types/cacheable-request": "^6.0.2",
|
||||
"@types/responselike": "^1.0.0",
|
||||
"cacheable-lookup": "^5.0.3",
|
||||
"cacheable-request": "^7.0.1",
|
||||
"cacheable-lookup": "^6.0.4",
|
||||
"cacheable-request": "^7.0.2",
|
||||
"decompress-response": "^6.0.0",
|
||||
"http2-wrapper": "^1.0.0-beta.5.2",
|
||||
"lowercase-keys": "^2.0.0",
|
||||
"p-cancelable": "^2.0.0",
|
||||
"form-data-encoder": "1.7.1",
|
||||
"get-stream": "^6.0.1",
|
||||
"http2-wrapper": "^2.1.9",
|
||||
"lowercase-keys": "^3.0.0",
|
||||
"p-cancelable": "^3.0.0",
|
||||
"responselike": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"get-stream": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz",
|
||||
"integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg=="
|
||||
},
|
||||
"lowercase-keys": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-3.0.0.tgz",
|
||||
"integrity": "sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"has-flag": {
|
||||
@ -2256,12 +2304,12 @@
|
||||
}
|
||||
},
|
||||
"http2-wrapper": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz",
|
||||
"integrity": "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==",
|
||||
"version": "2.1.10",
|
||||
"resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-2.1.10.tgz",
|
||||
"integrity": "sha512-QHgsdYkieKp+6JbXP25P+tepqiHYd+FVnDwXpxi/BlUcoIB0nsmTOymTNvETuTO+pDuwcSklPE72VR3DqV+Haw==",
|
||||
"requires": {
|
||||
"quick-lru": "^5.1.1",
|
||||
"resolve-alpn": "^1.0.0"
|
||||
"resolve-alpn": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"iconv-lite": {
|
||||
@ -2509,9 +2557,9 @@
|
||||
}
|
||||
},
|
||||
"p-cancelable": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz",
|
||||
"integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg=="
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-3.0.0.tgz",
|
||||
"integrity": "sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw=="
|
||||
},
|
||||
"parseurl": {
|
||||
"version": "1.3.3",
|
||||
|
@ -15,7 +15,7 @@
|
||||
"ejs": "~3.1.6",
|
||||
"express": "~4.17.1",
|
||||
"form-data": "^4.0.0",
|
||||
"got": "^11.8.2",
|
||||
"got": "^12.0.1",
|
||||
"http-errors": "~1.8.0",
|
||||
"jquery": "^3.6.0",
|
||||
"moment": "^2.29.1",
|
||||
|
@ -21,7 +21,7 @@ function updatetNextDate() {
|
||||
|
||||
class CronContainer {
|
||||
constructor() {
|
||||
this.cronJob = null;
|
||||
this.cronJobs = [];
|
||||
this.cronClean = null;
|
||||
}
|
||||
|
||||
@ -33,52 +33,70 @@ class CronContainer {
|
||||
this.cronClean = new CronJob("0 1 * * *", this._clean, null, false, Intl.DateTimeFormat().resolvedOptions().timeZone);
|
||||
this.cronClean.start();
|
||||
}
|
||||
if (this.cronJob != null) {
|
||||
logger.info("Stopping Cron...");
|
||||
this.cronJob.stop();
|
||||
this.cronJob = null;
|
||||
}
|
||||
|
||||
if (!settingsTools.check_cron(settingsTools.getSettings())) {
|
||||
logger.warn("No Cron settings available.");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (settings.cron_base) {
|
||||
case "0":
|
||||
logger.warn("No Cron settings available.");
|
||||
return;
|
||||
case "1": {
|
||||
let splited = settings.cron_hour.split(":");
|
||||
cronStr = "" + splited[1] + " " + splited[0] + " * * *";
|
||||
break;
|
||||
}
|
||||
|
||||
case "2": {
|
||||
let splited = settings.cron_hour.split(":");
|
||||
cronStr = "" + splited[1] + " " + splited[0] + " * * " + settings.cron_weekday;
|
||||
break;
|
||||
}
|
||||
|
||||
case "3": {
|
||||
let splited = settings.cron_hour.split(":");
|
||||
cronStr = "" + splited[1] + " " + splited[0] + " " + settings.cron_month_day + " * *";
|
||||
break;
|
||||
}
|
||||
case "4": {
|
||||
cronStr = settings.cron_custom;
|
||||
break;
|
||||
if(this.cronJobs.length != 0){
|
||||
this._clean_cron_jobs();
|
||||
}
|
||||
|
||||
if (settings.cron.length == 0){
|
||||
logger.warn("No Cron settings available.");
|
||||
}
|
||||
else {
|
||||
let i = 0;
|
||||
for(let cron of settings.cron){
|
||||
logger.info(`Starting cron #${i} ...`)
|
||||
switch (cron.cron_base) {
|
||||
case "1": {
|
||||
let splited = cron.cron_hour.split(":");
|
||||
cronStr = "" + splited[1] + " " + splited[0] + " * * *";
|
||||
break;
|
||||
}
|
||||
|
||||
case "2": {
|
||||
let splited = cron.cron_hour.split(":");
|
||||
cronStr = "" + splited[1] + " " + splited[0] + " * * " + cron.cron_weekday;
|
||||
break;
|
||||
}
|
||||
|
||||
case "3": {
|
||||
let splited = cron.cron_hour.split(":");
|
||||
cronStr = "" + splited[1] + " " + splited[0] + " " + cron.cron_month_day + " * *";
|
||||
break;
|
||||
}
|
||||
case "4": {
|
||||
cronStr = cron.cron_custom;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.cronJobs.push(new CronJob(cronStr, this._createBackup, null, true, Intl.DateTimeFormat().resolvedOptions().timeZone));
|
||||
i ++ ;
|
||||
}
|
||||
}
|
||||
logger.info("Starting Cron...");
|
||||
this.cronJob = new CronJob(cronStr, this._createBackup, null, false, Intl.DateTimeFormat().resolvedOptions().timeZone);
|
||||
this.cronJob.start();
|
||||
|
||||
this.updateNextDate();
|
||||
}
|
||||
|
||||
updateNextDate() {
|
||||
let date;
|
||||
if (this.cronJob == null) date = null;
|
||||
else date = this.cronJob.nextDate().format("MMM D, YYYY HH:mm");
|
||||
if (this.cronJobs.length == 0)
|
||||
date = null;
|
||||
else {
|
||||
let last_date = null;
|
||||
for(let item of this.cronJobs){
|
||||
if(last_date == null)
|
||||
last_date = item.nextDate();
|
||||
else{
|
||||
if(last_date > item.nextDate())
|
||||
last_date = item.nextDate();
|
||||
}
|
||||
}
|
||||
date = last_date.format("MMM D, YYYY HH:mm");
|
||||
}
|
||||
let status = statusTools.getStatus();
|
||||
status.next_backup = date;
|
||||
statusTools.setStatus(status);
|
||||
@ -124,6 +142,16 @@ class CronContainer {
|
||||
webdav.clean().catch();
|
||||
}
|
||||
}
|
||||
|
||||
_clean_cron_jobs(){
|
||||
let i = 0;
|
||||
for(let elem of this.cronJobs){
|
||||
logger.info(`Stopping Crong job #${i}`)
|
||||
elem.stop();
|
||||
i++;
|
||||
}
|
||||
this.cronJobs = []
|
||||
}
|
||||
}
|
||||
|
||||
class Singleton {
|
||||
|
@ -6,48 +6,92 @@ const CronJob = require("cron").CronJob;
|
||||
const settingsPath = "/data/backup_conf.json";
|
||||
|
||||
function check_cron(conf) {
|
||||
if (conf.cron_base != null) {
|
||||
if (conf.cron_base === "1" || conf.cron_base === "2" || conf.cron_base === "3") {
|
||||
if (conf.cron_hour != null && conf.cron_hour.match(/\d\d:\d\d/)) {
|
||||
if (conf.cron_base === "1") return true;
|
||||
} else return false;
|
||||
}
|
||||
if (conf.cron != null) {
|
||||
if (!Array.isArray(conf.cron))
|
||||
return false;
|
||||
|
||||
if (conf.cron_base === "2") {
|
||||
return conf.cron_weekday != null && conf.cron_weekday >= 0 && conf.cron_weekday <= 6;
|
||||
}
|
||||
|
||||
if (conf.cron_base === "3") {
|
||||
return conf.cron_month_day != null && conf.cron_month_day >= 1 && conf.cron_month_day <= 28;
|
||||
}
|
||||
|
||||
if (conf.cron_base === "4") {
|
||||
if (conf.cron_custom != null) {
|
||||
try {
|
||||
new CronJob(conf.cron_custom, () => {});
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
for (let elem of conf.cron){
|
||||
if (elem.cron_base != null) {
|
||||
if (elem.cron_base === "1" || elem.cron_base === "2" || elem.cron_base === "3") {
|
||||
if (elem.cron_hour != null && elem.cron_hour.match(/\d\d:\d\d/)) {
|
||||
if (elem.cron_base === "1")
|
||||
continue;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}else return false;
|
||||
|
||||
if (elem.cron_base === "2") {
|
||||
if( elem.cron_weekday != null && elem.cron_weekday >= 0 && elem.cron_weekday <= 6)
|
||||
continue;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
if (elem.cron_base === "3") {
|
||||
if( elem.cron_month_day != null && elem.cron_month_day >= 1 && elem.cron_month_day <= 28)
|
||||
continue;
|
||||
else
|
||||
return false
|
||||
}
|
||||
|
||||
if (elem.cron_base === "4") {
|
||||
if (elem.cron_custom != null) {
|
||||
try {
|
||||
new CronJob(elem.cron_custom, () => { });
|
||||
continue;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
if (conf.cron_base === "0") return true;
|
||||
} else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
function migrate_cron_conf(conf) {
|
||||
let obj = {
|
||||
cron_base: conf.cron_base,
|
||||
cron_hour: conf.cron_hour,
|
||||
cron_weekday: conf.cron_weekday,
|
||||
cron_month_day: conf.cron_month_day,
|
||||
cron_custom: conf.cron_custom,
|
||||
}
|
||||
conf.cron = [obj];
|
||||
delete conf.cron_base;
|
||||
delete conf.cron_hour;
|
||||
delete conf.cron_weekday;
|
||||
delete conf.cron_month_day;
|
||||
delete conf.cron_custom;
|
||||
return conf
|
||||
}
|
||||
|
||||
function check(conf, fallback = false) {
|
||||
let needSave = false;
|
||||
|
||||
if (conf.cron == null && !Array.isArray(conf.cron) && conf.cron_base != null) {
|
||||
// Migrate to new cron conf format
|
||||
logger.warn("Migrating to new cron conf format !")
|
||||
conf = migrate_cron_conf(conf);
|
||||
needSave = true;
|
||||
}
|
||||
|
||||
|
||||
if (!check_cron(conf)) {
|
||||
if (fallback) {
|
||||
logger.warn("Bad value for cron settings, fallback to default ");
|
||||
conf.cron_base = "0";
|
||||
conf.cron_hour = "00:00";
|
||||
conf.cron_weekday = "0";
|
||||
conf.cron_month_day = "1";
|
||||
conf.cron_custom = "5 4 * * *";
|
||||
conf.cron = []
|
||||
} else {
|
||||
logger.error("Bad value for cron settings");
|
||||
return [false, "Bad cron settings"];
|
||||
@ -184,7 +228,7 @@ function getSettings() {
|
||||
}
|
||||
|
||||
function setSettings(settings) {
|
||||
fs.writeFileSync(settingsPath, JSON.stringify(settings));
|
||||
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
||||
}
|
||||
|
||||
exports.getSettings = getSettings;
|
||||
|
@ -32,8 +32,8 @@ function getStatus() {
|
||||
function setStatus(state) {
|
||||
if (fs.existsSync(statusPath)) {
|
||||
let old_state_str = fs.readFileSync(statusPath).toString();
|
||||
if(old_state_str !== JSON.stringify(state)){
|
||||
fs.writeFileSync(statusPath, JSON.stringify(state));
|
||||
if(old_state_str !== JSON.stringify(state, null, 2)){
|
||||
fs.writeFileSync(statusPath, JSON.stringify(state, null, 2));
|
||||
hassioApiTools.publish_state(state);
|
||||
}
|
||||
}else{
|
||||
|
Loading…
Reference in New Issue
Block a user