mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-12-23 22:46:44 +01:00
🔨 Add logger
This commit is contained in:
parent
911d18675b
commit
24f6a8c552
4
.gitignore
vendored
4
.gitignore
vendored
@ -105,4 +105,6 @@ dist
|
||||
.vscode
|
||||
status.json
|
||||
conf.json
|
||||
webdav_conf.json
|
||||
webdav_conf.json
|
||||
|
||||
.idea
|
@ -13,9 +13,13 @@ const app = express();
|
||||
app.set('views', path.join(__dirname, 'views'));
|
||||
app.set('view engine', 'ejs');
|
||||
|
||||
app.use(logger('dev', { skip: function(req, res) { return res.statusCode = 304 } }));
|
||||
app.use(logger('dev', {
|
||||
skip: function (req, res) {
|
||||
return res.statusCode = 304
|
||||
}
|
||||
}));
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(express.urlencoded({extended: false}));
|
||||
app.use(cookieParser());
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
@ -23,53 +27,51 @@ app.use('/', indexRouter);
|
||||
app.use('/api', apiRouter);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function(req, res, next) {
|
||||
next(createError(404));
|
||||
app.use(function (req, res, next) {
|
||||
next(createError(404));
|
||||
});
|
||||
|
||||
// error handler
|
||||
app.use(function(err, req, res, next) {
|
||||
// set locals, only providing error in development
|
||||
res.locals.message = err.message;
|
||||
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
||||
app.use(function (err, req, res, next) {
|
||||
// set locals, only providing error in development
|
||||
res.locals.message = err.message;
|
||||
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
||||
|
||||
// render the error page
|
||||
res.status(err.status || 500);
|
||||
res.render('error');
|
||||
// render the error page
|
||||
res.status(err.status || 500);
|
||||
res.render('error');
|
||||
});
|
||||
|
||||
const fs = require('fs');
|
||||
const newlog = require('./config/winston');
|
||||
if (!fs.existsSync('/data'))
|
||||
fs.mkdirSync('/data');
|
||||
fs.mkdirSync('/data');
|
||||
const statusTools = require('./tools/status');
|
||||
statusTools.init();
|
||||
console.log("Satus : \x1b[32mGo !\x1b[0m")
|
||||
|
||||
newlog.info("Satus : \x1b[32mGo !\x1b[0m");
|
||||
const hassioApiTools = require('./tools/hassioApiTools');
|
||||
hassioApiTools.getSnapshots().then(
|
||||
() => {
|
||||
console.log("Hassio API : \x1b[32mGo !\x1b[0m")
|
||||
() => {
|
||||
newlog.info("Hassio API : \x1b[32mGo !\x1b[0m")
|
||||
|
||||
}, (err) => {
|
||||
console.log("Hassio API : \x1b[31;1mFAIL !\x1b[0m")
|
||||
console.log("... " + err);
|
||||
});
|
||||
}, (err) => {
|
||||
newlog.error("Hassio API : \x1b[31;1mFAIL !\x1b[0m")
|
||||
newlog.error("... " + err);
|
||||
});
|
||||
|
||||
const WebdavTools = require('./tools/webdavTools');
|
||||
const webdav = new WebdavTools().getInstance();
|
||||
webdav.confIsValid().then(
|
||||
() => {
|
||||
console.log("Nextcloud connection : \x1b[32mGo !\x1b[0m")
|
||||
}, (err) => {
|
||||
console.log("Nextcloud connection : \x1b[31;1mFAIL !\x1b[0m")
|
||||
console.log("... " + err);
|
||||
}
|
||||
() => {
|
||||
newlog.info("Nextcloud connection : \x1b[32mGo !\x1b[0m")
|
||||
}, (err) => {
|
||||
newlog.error("Nextcloud connection : \x1b[31;1mFAIL !\x1b[0m")
|
||||
newlog.error("... " + err);
|
||||
}
|
||||
)
|
||||
|
||||
const cronTools = require('./tools/cronTools');
|
||||
cronTools.startCron();
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = app;
|
||||
|
@ -0,0 +1,30 @@
|
||||
const appRoot = require('app-root-path');
|
||||
const winston = require('winston');
|
||||
|
||||
|
||||
const logger = winston.createLogger({
|
||||
level: 'info',
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp({
|
||||
format: 'YYYY-MM-DD HH:mm:ss'
|
||||
}),
|
||||
// winston.format.errors({ stack: true }),
|
||||
// winston.format.splat(),
|
||||
|
||||
winston.format.colorize(),
|
||||
winston.format.printf(({level, message, timestamp}) => {
|
||||
return `[${timestamp}] [${level}]: ${message}`;
|
||||
})
|
||||
),
|
||||
transports: [
|
||||
//
|
||||
// - Write to all logs with level `info` and below to `quick-start-combined.log`.
|
||||
// - Write all logs error (and below) to `quick-start-error.log`.
|
||||
//
|
||||
new winston.transports.Console({handleExceptions: true}),
|
||||
new winston.transports.File({filename: '/data/NCB.log', handleExceptions: true})
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
module.exports = logger;
|
@ -80,6 +80,11 @@
|
||||
"color-convert": "^1.9.0"
|
||||
}
|
||||
},
|
||||
"app-root-path": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-3.0.0.tgz",
|
||||
"integrity": "sha512-qMcx+Gy2UZynHjOHOIXPNvpf+9cjvk3cWrBBK7zg4gH9+clobJRb9NGzcT7mQTcV/6Gm/1WelUtqxVXnNlrwcw=="
|
||||
},
|
||||
"argparse": {
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
|
||||
@ -113,6 +118,14 @@
|
||||
"integrity": "sha1-bIw/uCfdQ+45GPJ7gngqt2WKb9k=",
|
||||
"dev": true
|
||||
},
|
||||
"async": {
|
||||
"version": "2.6.3",
|
||||
"resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz",
|
||||
"integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==",
|
||||
"requires": {
|
||||
"lodash": "^4.17.14"
|
||||
}
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
@ -237,11 +250,19 @@
|
||||
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=",
|
||||
"dev": true
|
||||
},
|
||||
"color": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/color/-/color-3.0.0.tgz",
|
||||
"integrity": "sha512-jCpd5+s0s0t7p3pHQKpnJ0TpQKKdleP71LWcA0aqiljpiuAkOSUFN/dyH8ZwF0hRmFlrIuRhufds1QyEP9EB+w==",
|
||||
"requires": {
|
||||
"color-convert": "^1.9.1",
|
||||
"color-string": "^1.5.2"
|
||||
}
|
||||
},
|
||||
"color-convert": {
|
||||
"version": "1.9.3",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
|
||||
"integrity": "sha1-u3GFBpDh8TZWfeYp0tVHHe2kweg=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"color-name": "1.1.3"
|
||||
}
|
||||
@ -249,8 +270,35 @@
|
||||
"color-name": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
|
||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
|
||||
"dev": true
|
||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
|
||||
},
|
||||
"color-string": {
|
||||
"version": "1.5.3",
|
||||
"resolved": "https://registry.npmjs.org/color-string/-/color-string-1.5.3.tgz",
|
||||
"integrity": "sha512-dC2C5qeWoYkxki5UAXapdjqO672AM4vZuPGRQfO8b5HKuKGBbKWpITyDYN7TOFKvRW7kOgAn3746clDBMDJyQw==",
|
||||
"requires": {
|
||||
"color-name": "^1.0.0",
|
||||
"simple-swizzle": "^0.2.2"
|
||||
}
|
||||
},
|
||||
"colornames": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/colornames/-/colornames-1.1.1.tgz",
|
||||
"integrity": "sha1-+IiQMGhcfE/54qVZ9Qd+t2qBb5Y="
|
||||
},
|
||||
"colors": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
|
||||
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
|
||||
},
|
||||
"colorspace": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/colorspace/-/colorspace-1.1.2.tgz",
|
||||
"integrity": "sha512-vt+OoIP2d76xLhjwbBaucYlNSpPsrJWPlBTtwCpQKIu6/CSMutyzX93O/Do0qzpH3YoHEes8YEFXyZ797rEhzQ==",
|
||||
"requires": {
|
||||
"color": "3.0.x",
|
||||
"text-hex": "1.0.x"
|
||||
}
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
@ -373,6 +421,16 @@
|
||||
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
||||
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
|
||||
},
|
||||
"diagnostics": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/diagnostics/-/diagnostics-1.1.1.tgz",
|
||||
"integrity": "sha512-8wn1PmdunLJ9Tqbx+Fx/ZEuHfJf4NKSN2ZBj7SJC/OWRWha843+WsTjqMe1B5E3p28jqBlp+mJ2fPVxPyNgYKQ==",
|
||||
"requires": {
|
||||
"colorspace": "1.1.x",
|
||||
"enabled": "1.0.x",
|
||||
"kuler": "1.0.x"
|
||||
}
|
||||
},
|
||||
"doctrine": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz",
|
||||
@ -407,11 +465,24 @@
|
||||
"integrity": "sha1-6Bj9ac5cz8tARZT4QpY79TFkzDc=",
|
||||
"dev": true
|
||||
},
|
||||
"enabled": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/enabled/-/enabled-1.0.2.tgz",
|
||||
"integrity": "sha1-ll9lE9LC0cX0ZStkouM5ZGf8L5M=",
|
||||
"requires": {
|
||||
"env-variable": "0.0.x"
|
||||
}
|
||||
},
|
||||
"encodeurl": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
|
||||
"integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k="
|
||||
},
|
||||
"env-variable": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/env-variable/-/env-variable-0.0.6.tgz",
|
||||
"integrity": "sha512-bHz59NlBbtS0NhftmR8+ExBEekE7br0e01jw+kk0NDro7TtZzBYZ5ScGPs3OmwnpyfHTHOtr1Y6uedCdrIldtg=="
|
||||
},
|
||||
"es-abstract": {
|
||||
"version": "1.17.0-next.1",
|
||||
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.0-next.1.tgz",
|
||||
@ -681,6 +752,16 @@
|
||||
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=",
|
||||
"dev": true
|
||||
},
|
||||
"fast-safe-stringify": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz",
|
||||
"integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA=="
|
||||
},
|
||||
"fecha": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/fecha/-/fecha-2.3.3.tgz",
|
||||
"integrity": "sha512-lUGBnIamTAwk4znq5BcqsDaxSmZ9nDVJaij6NvRt/Tg4R69gERA+otPKbS86ROw9nxVMw2/mp1fnaiWqbs6Sdg=="
|
||||
},
|
||||
"figures": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/figures/-/figures-3.1.0.tgz",
|
||||
@ -960,6 +1041,11 @@
|
||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz",
|
||||
"integrity": "sha1-N9905DCg5HVQ/lSi3v4w2KzZX2U="
|
||||
},
|
||||
"is-arrayish": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz",
|
||||
"integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ=="
|
||||
},
|
||||
"is-buffer": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
|
||||
@ -1010,6 +1096,11 @@
|
||||
"has": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"is-stream": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
|
||||
},
|
||||
"is-symbol": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz",
|
||||
@ -1023,6 +1114,11 @@
|
||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
|
||||
},
|
||||
"isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
@ -1087,6 +1183,14 @@
|
||||
"verror": "1.10.0"
|
||||
}
|
||||
},
|
||||
"kuler": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/kuler/-/kuler-1.0.1.tgz",
|
||||
"integrity": "sha512-J9nVUucG1p/skKul6DU3PUZrhs0LPulNaeUOox0IyXDi8S4CztTHs1gQphhuZmzXG7VOQSf6NJfKuzteQLv9gQ==",
|
||||
"requires": {
|
||||
"colornames": "^1.1.1"
|
||||
}
|
||||
},
|
||||
"levn": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",
|
||||
@ -1100,8 +1204,26 @@
|
||||
"lodash": {
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||
"integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg=",
|
||||
"dev": true
|
||||
"integrity": "sha1-tEf2ZwoEVbv+7dETku/zMOoJdUg="
|
||||
},
|
||||
"logform": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/logform/-/logform-2.1.2.tgz",
|
||||
"integrity": "sha512-+lZh4OpERDBLqjiwDLpAWNQu6KMjnlXH2ByZwCuSqVPJletw0kTWJf5CgSNAUKn1KUkv3m2cUz/LK8zyEy7wzQ==",
|
||||
"requires": {
|
||||
"colors": "^1.2.1",
|
||||
"fast-safe-stringify": "^2.0.4",
|
||||
"fecha": "^2.3.3",
|
||||
"ms": "^2.1.1",
|
||||
"triple-beam": "^1.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"media-typer": {
|
||||
"version": "0.3.0",
|
||||
@ -1280,6 +1402,11 @@
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"one-time": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/one-time/-/one-time-0.0.4.tgz",
|
||||
"integrity": "sha1-+M33eISCb+Tf+T46nMN7HkSAdC4="
|
||||
},
|
||||
"onetime": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz",
|
||||
@ -1356,6 +1483,11 @@
|
||||
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=",
|
||||
"dev": true
|
||||
},
|
||||
"process-nextick-args": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
|
||||
},
|
||||
"progress": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
|
||||
@ -1407,6 +1539,16 @@
|
||||
"unpipe": "1.0.0"
|
||||
}
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
|
||||
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
|
||||
"requires": {
|
||||
"inherits": "^2.0.3",
|
||||
"string_decoder": "^1.1.1",
|
||||
"util-deprecate": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"regexpp": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz",
|
||||
@ -1574,6 +1716,14 @@
|
||||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
|
||||
"dev": true
|
||||
},
|
||||
"simple-swizzle": {
|
||||
"version": "0.2.2",
|
||||
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",
|
||||
"integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=",
|
||||
"requires": {
|
||||
"is-arrayish": "^0.3.1"
|
||||
}
|
||||
},
|
||||
"slice-ansi": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz",
|
||||
@ -1615,6 +1765,11 @@
|
||||
"tweetnacl": "~0.14.0"
|
||||
}
|
||||
},
|
||||
"stack-trace": {
|
||||
"version": "0.0.10",
|
||||
"resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
|
||||
"integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA="
|
||||
},
|
||||
"statuses": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
|
||||
@ -1660,6 +1815,21 @@
|
||||
"function-bind": "^1.1.1"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
||||
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
|
||||
"requires": {
|
||||
"safe-buffer": "~5.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"safe-buffer": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",
|
||||
"integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz",
|
||||
@ -1729,6 +1899,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"text-hex": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz",
|
||||
"integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg=="
|
||||
},
|
||||
"text-table": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
|
||||
@ -1771,6 +1946,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"triple-beam": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz",
|
||||
"integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw=="
|
||||
},
|
||||
"tslib": {
|
||||
"version": "1.10.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz",
|
||||
@ -1841,6 +2021,11 @@
|
||||
"requires-port": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
|
||||
},
|
||||
"util.promisify": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/util.promisify/-/util.promisify-1.0.0.tgz",
|
||||
@ -1906,6 +2091,55 @@
|
||||
"isexe": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"winston": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/winston/-/winston-3.2.1.tgz",
|
||||
"integrity": "sha512-zU6vgnS9dAWCEKg/QYigd6cgMVVNwyTzKs81XZtTFuRwJOcDdBg7AU0mXVyNbs7O5RH2zdv+BdNZUlx7mXPuOw==",
|
||||
"requires": {
|
||||
"async": "^2.6.1",
|
||||
"diagnostics": "^1.1.1",
|
||||
"is-stream": "^1.1.0",
|
||||
"logform": "^2.1.1",
|
||||
"one-time": "0.0.4",
|
||||
"readable-stream": "^3.1.1",
|
||||
"stack-trace": "0.0.x",
|
||||
"triple-beam": "^1.3.0",
|
||||
"winston-transport": "^4.3.0"
|
||||
}
|
||||
},
|
||||
"winston-transport": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.3.0.tgz",
|
||||
"integrity": "sha512-B2wPuwUi3vhzn/51Uukcao4dIduEiPOcOt9HJ3QeaXgkJ5Z7UwpBzxS4ZGNHtrxrUvTwemsQiSys0ihOf8Mp1A==",
|
||||
"requires": {
|
||||
"readable-stream": "^2.3.6",
|
||||
"triple-beam": "^1.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"readable-stream": {
|
||||
"version": "2.3.7",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",
|
||||
"integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==",
|
||||
"requires": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.3",
|
||||
"isarray": "~1.0.0",
|
||||
"process-nextick-args": "~2.0.0",
|
||||
"safe-buffer": "~5.1.1",
|
||||
"string_decoder": "~1.1.1",
|
||||
"util-deprecate": "~1.0.1"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||
"requires": {
|
||||
"safe-buffer": "~5.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"word-wrap": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
|
||||
|
@ -6,6 +6,7 @@
|
||||
"start": "node --inspect=0.0.0.0:9226 ./bin/www "
|
||||
},
|
||||
"dependencies": {
|
||||
"app-root-path": "^3.0.0",
|
||||
"cookie-parser": "~1.4.4",
|
||||
"cron": "^1.7.2",
|
||||
"debug": "~2.6.9",
|
||||
@ -16,7 +17,8 @@
|
||||
"morgan": "~1.9.1",
|
||||
"request": "^2.88.0",
|
||||
"request-progress": "^3.0.0",
|
||||
"webdav": "^2.10.0"
|
||||
"webdav": "^2.10.0",
|
||||
"winston": "^3.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^6.7.2",
|
||||
|
@ -10,6 +10,8 @@ const hassioApiTools = require('../tools/hassioApiTools');
|
||||
|
||||
const cronTools = require('../tools/cronTools');
|
||||
|
||||
const logger = require('../config/winston');
|
||||
|
||||
|
||||
|
||||
|
||||
@ -36,7 +38,7 @@ router.get('/formated-local-snap', function(req, res, next) {
|
||||
res.render('localSnaps', { snaps: snaps, moment: moment });
|
||||
},
|
||||
(err) => {
|
||||
console.log(err);
|
||||
logger.error(err);
|
||||
res.status(500);
|
||||
res.send('');
|
||||
})
|
||||
@ -134,7 +136,7 @@ router.post('/manual-backup', function(req, res, next) {
|
||||
router.post('/new-backup', function(req, res, next) {
|
||||
|
||||
let status = statusTools.getStatus();
|
||||
if (status.status == "creating" && status.status == "upload" && status.status == "download") {
|
||||
if (status.status === "creating" && status.status === "upload" && status.status === "download") {
|
||||
res.status(503);
|
||||
res.send();
|
||||
return;
|
||||
|
@ -1,6 +1,6 @@
|
||||
const settingsTools = require('./settingsTools');
|
||||
|
||||
const WebdavTools = require('./webdavTools')
|
||||
const WebdavTools = require('./webdavTools');
|
||||
const webdav = new WebdavTools().getInstance();
|
||||
|
||||
const hassioApiTools = require('./hassioApiTools');
|
||||
@ -9,35 +9,31 @@ const statusTools = require('./status');
|
||||
|
||||
const pathTools = require('./pathTools');
|
||||
|
||||
var CronJob = require('cron').CronJob;
|
||||
const CronJob = require('cron').CronJob;
|
||||
const moment = require('moment');
|
||||
const logger = require('../config/winston');
|
||||
|
||||
|
||||
function checkConfig(conf) {
|
||||
if (conf.cron_base != null) {
|
||||
if (conf.cron_base == '1' || conf.cron_base == '2' || conf.cron_base == '3') {
|
||||
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')
|
||||
if (conf.cron_base === '1')
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
if (conf.cron_base == '2') {
|
||||
if (conf.cron_weekday != null && conf.cron_weekday >= 0 && conf.cron_weekday <= 6)
|
||||
return true;
|
||||
else
|
||||
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') {
|
||||
if (conf.cron_month_day != null && conf.cron_month_day >= 1 && conf.cron_month_day <= 28)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
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 == '0')
|
||||
if (conf.cron_base === '0')
|
||||
return true
|
||||
}
|
||||
else
|
||||
@ -67,23 +63,23 @@ class CronContainer {
|
||||
let settings = settingsTools.getSettings();
|
||||
let cronStr = "";
|
||||
if (this.cronClean == null) {
|
||||
console.log("Starting auto clean cron...")
|
||||
logger.info("Starting auto clean cron...");
|
||||
this.cronClean = new CronJob('0 1 * * *', this._clean, null, false, Intl.DateTimeFormat().resolvedOptions().timeZone);
|
||||
this.cronClean.start();
|
||||
}
|
||||
if (this.cronJob != null) {
|
||||
console.log("Stoping Cron...")
|
||||
logger.info("Stoping Cron...");
|
||||
this.cronJob.stop();
|
||||
this.cronJob = null;
|
||||
}
|
||||
if (!checkConfig(settingsTools.getSettings())) {
|
||||
console.log("No Cron settings available.")
|
||||
logger.warn("No Cron settings available.");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (settings.cron_base) {
|
||||
case '0':
|
||||
console.log("No Cron settings available.")
|
||||
logger.warn("No Cron settings available.");
|
||||
return;
|
||||
case '1': {
|
||||
let splited = settings.cron_hour.split(':');
|
||||
@ -105,7 +101,7 @@ class CronContainer {
|
||||
|
||||
|
||||
}
|
||||
console.log("Starting Cron...")
|
||||
logger.info("Starting Cron...");
|
||||
this.cronJob = new CronJob(cronStr, this._createBackup, null, false, Intl.DateTimeFormat().resolvedOptions().timeZone);
|
||||
this.cronJob.start();
|
||||
this.updatetNextDate();
|
||||
@ -123,8 +119,9 @@ class CronContainer {
|
||||
}
|
||||
|
||||
_createBackup() {
|
||||
logger.debug('Cron triggered !');
|
||||
let status = statusTools.getStatus();
|
||||
if (status.status == "creating" && status.status == "upload" && status.status == "download")
|
||||
if (status.status === "creating" && status.status === "upload" && status.status === "download")
|
||||
return;
|
||||
|
||||
let name = 'Auto-' + moment().format('YYYY-MM-DD_HH:mm');
|
||||
@ -142,11 +139,11 @@ class CronContainer {
|
||||
|
||||
_clean() {
|
||||
let autoCleanCloud = settingsTools.getSettings().auto_clean_backup;
|
||||
if (autoCleanCloud != null && autoCleanCloud == "true") {
|
||||
if (autoCleanCloud != null && autoCleanCloud === "true") {
|
||||
this.clean().catch();
|
||||
}
|
||||
let autoCleanlocal = settingsTools.getSettings().auto_clean_local;
|
||||
if (autoCleanlocal != null && autoCleanlocal == "true") {
|
||||
if (autoCleanlocal != null && autoCleanlocal === "true") {
|
||||
hassioApiTools.clean();
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ const statusTools = require('./status');
|
||||
const fs = require('fs');
|
||||
const settingsTools = require('./settingsTools');
|
||||
const moment = require('moment');
|
||||
|
||||
const logger = require('../config/winston');
|
||||
|
||||
// !!! FOR DEV PURPOSE ONLY !!!
|
||||
//put token here for dev (ssh port tunelling 'sudo ssh -L 80:hassio:80 root@`hassoi_ip`' + put 127.0.0.1 hassio into host)
|
||||
@ -22,10 +22,10 @@ function getSnapshots() {
|
||||
url: "http://hassio/snapshots",
|
||||
headers: { 'X-HASSIO-KEY': token },
|
||||
json: true
|
||||
}
|
||||
};
|
||||
request(option, (error, response, body) => {
|
||||
if (!error && response.statusCode == 200) {
|
||||
if (status.error_code == 1) {
|
||||
if (!error && response.statusCode === 200) {
|
||||
if (status.error_code === 1) {
|
||||
status.status = "idle";
|
||||
status.message = null;
|
||||
status.error_code = null;
|
||||
@ -40,7 +40,7 @@ function getSnapshots() {
|
||||
status.message = "Fail to fetch Hassio snapshot (" + error + ")";
|
||||
status.error_code = 1;
|
||||
statusTools.setStatus(status);
|
||||
console.error(status.message);
|
||||
logger.error(status.message);
|
||||
reject(error);
|
||||
}
|
||||
})
|
||||
@ -50,7 +50,7 @@ function getSnapshots() {
|
||||
|
||||
function downloadSnapshot(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('Downloading snapshot ' + id + '...')
|
||||
logger.info('Downloading snapshot ' + id + '...');
|
||||
if (!fs.existsSync('./temp/'))
|
||||
fs.mkdirSync('./temp/');
|
||||
let stream = fs.createWriteStream('./temp/' + id + '.tar');
|
||||
@ -66,7 +66,7 @@ function downloadSnapshot(id) {
|
||||
let option = {
|
||||
url: 'http://hassio/snapshots/' + id + '/download',
|
||||
headers: { 'X-HASSIO-KEY': token },
|
||||
}
|
||||
};
|
||||
progress(request(option))
|
||||
.on('progress', (state) => {
|
||||
// TODO Don't write progress to disk, preseve disk IO time
|
||||
@ -78,11 +78,11 @@ function downloadSnapshot(id) {
|
||||
status.message = "Fail to download Hassio snapshot (" + error + ")";
|
||||
status.error_code = 1;
|
||||
statusTools.setStatus(status);
|
||||
console.error(status.message);
|
||||
logger.error(status.message);
|
||||
reject(error);
|
||||
})
|
||||
.on('end', () => {
|
||||
console.log('Download success !')
|
||||
logger.info('Download success !')
|
||||
status.progress = 1;
|
||||
statusTools.setStatus(status);
|
||||
resolve();
|
||||
@ -93,7 +93,7 @@ function downloadSnapshot(id) {
|
||||
status.message = "Fail to download Hassio snapshot. Not found ?";
|
||||
status.error_code = 1;
|
||||
statusTools.setStatus(status);
|
||||
console.error(status.message);
|
||||
logger.error(status.message);
|
||||
reject();
|
||||
});
|
||||
|
||||
@ -113,7 +113,7 @@ function dellSnap(id) {
|
||||
json: true
|
||||
}
|
||||
request.post(option, (error, response, body) => {
|
||||
if (error || (response.statusCode != 200 && response.statusCode != 204))
|
||||
if (error || (response.statusCode !== 200 && response.statusCode !== 204))
|
||||
reject();
|
||||
else
|
||||
resolve();
|
||||
|
@ -1,4 +1,4 @@
|
||||
let root = '/Hassio Backup/'
|
||||
let root = '/Hassio Backup/';
|
||||
exports.root = root;
|
||||
exports.manual = root + 'Manual/'
|
||||
exports.auto = root + 'Auto/'
|
||||
exports.manual = root + 'Manual/';
|
||||
exports.auto = root + 'Auto/';
|
@ -1,6 +1,6 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const settingsPath = "/data/backup_conf.json"
|
||||
const settingsPath = "/data/backup_conf.json";
|
||||
|
||||
|
||||
function getSettings(){
|
||||
|
@ -1,12 +1,12 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const statusPath = '/data/status.json'
|
||||
const statusPath = '/data/status.json';
|
||||
|
||||
let baseStatus = {
|
||||
status: "idle",
|
||||
last_backup: null,
|
||||
next_backup: null
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
@ -3,12 +3,13 @@ const fs = require("fs");
|
||||
const moment = require('moment');
|
||||
|
||||
const statusTools = require('./status');
|
||||
const endpoint = "/remote.php/webdav"
|
||||
const configPath = "/data/webdav_conf.json"
|
||||
const endpoint = "/remote.php/webdav";
|
||||
const configPath = "/data/webdav_conf.json";
|
||||
const path = require('path');
|
||||
const settingsTools = require('./settingsTools');
|
||||
const pathTools = require('./pathTools');
|
||||
const hassioApiTools = require('./hassioApiTools');
|
||||
const logger = require('../config/winston');
|
||||
|
||||
const request = require('request');
|
||||
|
||||
@ -23,7 +24,7 @@ class WebdavTools {
|
||||
init(ssl, host, username, password) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let status = statusTools.getStatus();
|
||||
console.log("Initilizing and checking webdav client...")
|
||||
logger.info("Initilizing and checking webdav client...");
|
||||
this.baseUrl = (ssl ? "https" : "http") + "://" + host + endpoint;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
@ -37,7 +38,7 @@ class WebdavTools {
|
||||
status.error_code = null;
|
||||
statusTools.setStatus(status);
|
||||
}
|
||||
console.debug("Nextcloud connection: \x1b[32mSuccess !\x1b[0m");
|
||||
logger.debug("Nextcloud connection: \x1b[32mSuccess !\x1b[0m");
|
||||
this.initFolder().then(() => {
|
||||
resolve();
|
||||
});
|
||||
@ -48,7 +49,7 @@ class WebdavTools {
|
||||
status.message = "Can't connect to Nextcloud (" + error + ") !"
|
||||
statusTools.setStatus(status);
|
||||
this.client = null;
|
||||
console.error("Can't connect to Nextcloud (" + error + ") !");
|
||||
logger.error("Can't connect to Nextcloud (" + error + ") !");
|
||||
reject("Can't connect to Nextcloud (" + error + ") !");
|
||||
});
|
||||
} catch (err) {
|
||||
@ -57,7 +58,7 @@ class WebdavTools {
|
||||
status.message = "Can't connect to Nextcloud (" + err + ") !"
|
||||
statusTools.setStatus(status);
|
||||
this.client = null;
|
||||
console.error("Can't connect to Nextcloud (" + err + ") !");
|
||||
logger.error("Can't connect to Nextcloud (" + err + ") !");
|
||||
reject("Can't connect to Nextcloud (" + err + ") !");
|
||||
}
|
||||
|
||||
@ -101,7 +102,7 @@ class WebdavTools {
|
||||
status.error_code = 2;
|
||||
status.message = "Nextcloud config invalid !"
|
||||
statusTools.setStatus(status);
|
||||
console.error(status.message);
|
||||
logger.error(status.message);
|
||||
reject("Nextcloud config invalid !");
|
||||
}
|
||||
}
|
||||
@ -110,7 +111,7 @@ class WebdavTools {
|
||||
status.error_code = 2;
|
||||
status.message = "Nextcloud config not found !"
|
||||
statusTools.setStatus(status);
|
||||
console.error(status.message);
|
||||
logger.error(status.message);
|
||||
reject("Nextcloud config not found !");
|
||||
}
|
||||
|
||||
@ -153,7 +154,7 @@ class WebdavTools {
|
||||
status.message = null;
|
||||
status.error_code = null;
|
||||
statusTools.setStatus(status);
|
||||
console.log('Uploading snap...');
|
||||
logger.info('Uploading snap...');
|
||||
let fileSize = fs.statSync('./temp/' + id + '.tar').size;
|
||||
let option = {
|
||||
url: this.baseUrl + encodeURI(path),
|
||||
@ -180,7 +181,7 @@ class WebdavTools {
|
||||
status.error_code = 4;
|
||||
status.message = "Fail to upload snapshot to nextcloud (" + err + ") !"
|
||||
statusTools.setStatus(status);
|
||||
console.error(status.message);
|
||||
logger.error(status.message);
|
||||
reject(status.message);
|
||||
|
||||
}).on('response', (res) => {
|
||||
@ -189,12 +190,12 @@ class WebdavTools {
|
||||
status.error_code = 4;
|
||||
status.message = "Fail to upload snapshot to nextcloud (Status code: " + res.statusCode + ") !"
|
||||
statusTools.setStatus(status);
|
||||
console.error(status.message);
|
||||
logger.error(status.message);
|
||||
fs.unlinkSync('./temp/' + id + '.tar')
|
||||
reject(status.message);
|
||||
}
|
||||
else {
|
||||
console.log("...Upload finish !");
|
||||
logger.log("...Upload finish !");
|
||||
status.status = "idle";
|
||||
status.progress = -1;
|
||||
status.message = null;
|
||||
@ -255,7 +256,7 @@ class WebdavTools {
|
||||
for (let i in toDel) {
|
||||
await this.client.deleteFile(toDel[i].filename);
|
||||
}
|
||||
console.log('Cloud clean done.')
|
||||
logger.log('Cloud clean done.')
|
||||
resolve();
|
||||
|
||||
}).catch((error) => {
|
||||
@ -263,7 +264,7 @@ class WebdavTools {
|
||||
status.error_code = 6;
|
||||
status.message = "Fail to clean Nexcloud (" + error + ") !"
|
||||
statusTools.setStatus(status);
|
||||
console.error(status.message);
|
||||
logger.error(status.message);
|
||||
reject(status.message);
|
||||
});
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user