2022-09-27 23:38:40 +02:00
|
|
|
import { existsSync, mkdirSync } from "fs";
|
|
|
|
import logger from "./config/winston.js";
|
|
|
|
import * as homeAssistantService from "./services/homeAssistantService.js";
|
|
|
|
import * as statusTools from "./tools/status.js";
|
2022-09-30 19:13:39 +02:00
|
|
|
import kleur from "kleur";
|
2024-07-11 15:47:27 +02:00
|
|
|
import {
|
|
|
|
checkWebdavLogin,
|
|
|
|
createBackupFolder,
|
|
|
|
} from "./services/webdavService.js";
|
2022-09-30 19:13:39 +02:00
|
|
|
import {
|
|
|
|
getWebdavConfig,
|
|
|
|
validateWebdavConfig,
|
|
|
|
} from "./services/webdavConfigService.js";
|
2022-10-13 17:11:55 +02:00
|
|
|
import messageManager from "./tools/messageManager.js";
|
2022-09-27 23:38:40 +02:00
|
|
|
|
|
|
|
function postInit() {
|
|
|
|
logger.info(`Log level: ${process.env.LOG_LEVEL}`);
|
|
|
|
|
|
|
|
logger.info(
|
|
|
|
`Backup timeout: ${
|
|
|
|
(process.env.CREATE_BACKUP_TIMEOUT
|
|
|
|
? parseInt(process.env.CREATE_BACKUP_TIMEOUT)
|
|
|
|
: false) || 90 * 60 * 1000
|
|
|
|
}`
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!existsSync("/data")) mkdirSync("/data");
|
|
|
|
statusTools.init();
|
|
|
|
logger.info("Satus : " + kleur.green().bold("Go !"));
|
|
|
|
|
|
|
|
homeAssistantService.getBackups().then(
|
|
|
|
() => {
|
|
|
|
logger.info("Hassio API : " + kleur.green().bold("Go !"));
|
|
|
|
},
|
|
|
|
(err) => {
|
|
|
|
logger.error("Hassio API : " + kleur.red().bold("FAIL !"));
|
|
|
|
logger.error("... " + err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-09-30 19:13:39 +02:00
|
|
|
const webdavConf = getWebdavConfig();
|
|
|
|
validateWebdavConfig(webdavConf).then(
|
|
|
|
() => {
|
|
|
|
logger.info("Webdav config: " + kleur.green().bold("Go !"));
|
|
|
|
checkWebdavLogin(webdavConf).then(
|
|
|
|
() => {
|
|
|
|
logger.info("Webdav : " + kleur.green().bold("Go !"));
|
|
|
|
createBackupFolder(webdavConf).then(
|
|
|
|
() => {
|
|
|
|
logger.info("Webdav fodlers: " + kleur.green().bold("Go !"));
|
|
|
|
},
|
|
|
|
(reason) => {
|
|
|
|
logger.error("Webdav folders: " + kleur.red().bold("FAIL !"));
|
|
|
|
logger.error(reason);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
(reason) => {
|
|
|
|
logger.error("Webdav : " + kleur.red().bold("FAIL !"));
|
|
|
|
logger.error(reason);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2024-07-11 15:47:27 +02:00
|
|
|
(reason: Error) => {
|
2022-09-30 19:13:39 +02:00
|
|
|
logger.error("Webdav config: " + kleur.red().bold("FAIL !"));
|
|
|
|
logger.error(reason);
|
2022-10-13 17:11:55 +02:00
|
|
|
messageManager.error("Invalid webdav config", reason.message);
|
2022-09-30 19:13:39 +02:00
|
|
|
}
|
|
|
|
);
|
2022-09-27 23:38:40 +02:00
|
|
|
|
2024-07-11 15:47:27 +02:00
|
|
|
// settingsTools.check(settingsTools.getSettings(), true);
|
2022-09-27 23:38:40 +02:00
|
|
|
// cronTools.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
export default postInit;
|