Added resources downloader and hash getter
This commit is contained in:
parent
e7b56fe792
commit
9416be4105
|
@ -12,6 +12,36 @@
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
|
|
||||||
|
//Get the latest commit hash from github
|
||||||
|
getHash(callback) {
|
||||||
|
this.download("api.github.com", "/repos/Jiiks/BetterDiscordApp/commits/master", data => {
|
||||||
|
//TODO use the new soon to be implemented tryparse
|
||||||
|
callback(JSON.parse(data).sha);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
download(host, path, callback) {
|
||||||
|
_logger.log(`Downloading Resource: ${host}${path}`);
|
||||||
|
var options = {
|
||||||
|
host: host,
|
||||||
|
path: path,
|
||||||
|
headers: this.headers
|
||||||
|
};
|
||||||
|
|
||||||
|
_https.get(options, res => {
|
||||||
|
var data = "";
|
||||||
|
res.on('data', chunk => {
|
||||||
|
data += chunk;
|
||||||
|
});
|
||||||
|
res.on('end', () => {
|
||||||
|
callback(data);
|
||||||
|
});
|
||||||
|
}).on('error', () => {
|
||||||
|
//TODO error logging
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//Returns a datestring: [DD/MM/YYYY - HH:MM:SS]
|
//Returns a datestring: [DD/MM/YYYY - HH:MM:SS]
|
||||||
get dateString() {
|
get dateString() {
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
|
@ -24,6 +54,10 @@ class Utils {
|
||||||
`${("00" + d.getSeconds()).slice(-2)}`;
|
`${("00" + d.getSeconds()).slice(-2)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get headers() {
|
||||||
|
return { 'user-agent': 'Mozilla/5.0' };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
|
@ -59,7 +93,8 @@ class Logger {
|
||||||
const _utils = new Utils(),
|
const _utils = new Utils(),
|
||||||
_logger = new Logger(),
|
_logger = new Logger(),
|
||||||
_fs = require('fs'),
|
_fs = require('fs'),
|
||||||
{EOL} = require('os');
|
{EOL} = require('os'),
|
||||||
|
_https = require('https');
|
||||||
|
|
||||||
exports._utils = _utils;
|
exports._utils = _utils;
|
||||||
exports._logger = _logger;
|
exports._logger = _logger;
|
Loading…
Reference in New Issue