Startup fixes #11
1 changed files with 30 additions and 40 deletions
70
EUS.js
70
EUS.js
|
@ -36,74 +36,64 @@ if (!fs.existsSync(__dirname + BASE_PATH + "/i")) {
|
||||||
console.log(`[EUS] Made EUS images folder`);
|
console.log(`[EUS] Made EUS images folder`);
|
||||||
}
|
}
|
||||||
// Makes the image-type file
|
// Makes the image-type file
|
||||||
fs.access(`${__dirname}${BASE_PATH}/image-type.json`, error => {
|
if (fs.existsSync(__dirname + BASE_PATH + "image-type.json")) {
|
||||||
if (error) {
|
// Doesn't exist, create it.
|
||||||
// Doesn't exist, create it.
|
fs.writeFileSync(`${__dirname}${BASE_PATH}/image-type.json`, '{}');
|
||||||
fs.writeFile(`${__dirname}${BASE_PATH}/image-type.json`, '{\n}', function(err) {
|
console.log("[EUS] Created image-type File!");
|
||||||
if (err) throw err;
|
// File has been created, load it.
|
||||||
global.modules.consoleHelper.printInfo(emoji.heavy_check, "Created image-type File!");
|
image_json = require(`${__dirname}${BASE_PATH}/image-type.json`);
|
||||||
// File has been created, load it.
|
} else {
|
||||||
image_json = require(`${__dirname}${BASE_PATH}/image-type.json`);
|
// File already exists, load it.
|
||||||
});
|
image_json = require(`${__dirname}${BASE_PATH}/image-type.json`);
|
||||||
} else {
|
}
|
||||||
// File already exists, load it.
|
|
||||||
image_json = require(`${__dirname}${BASE_PATH}/image-type.json`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Makes the config file
|
// Makes the config file
|
||||||
fs.access(`${__dirname}${BASE_PATH}/config.json`, error => {
|
if (fs.existsSync(__dirname + BASE_PATH + "config.json")) {
|
||||||
if (error) {
|
// Config doesn't exist, make it.
|
||||||
// Config doesn't exist, make it.
|
fs.writeFileSync(`${__dirname}${BASE_PATH}/config.json`, '{\n\t"baseURL":"http://example.com/",\n\t"acceptedTypes": [\n\t\t".png",\n\t\t".jpg",\n\t\t".jpeg",\n\t\t".gif"\n\t],\n\t"uploadKey": ""\n}');
|
||||||
fs.writeFile(`${__dirname}${BASE_PATH}/config.json`, '{\n\t"baseURL":"http://example.com/",\n\t"acceptedTypes": [\n\t\t".png",\n\t\t".jpg",\n\t\t".jpeg",\n\t\t".gif"\n\t],\n\t"uploadKey": ""\n}', function(err) {
|
console.log("[EUS] Created config File!");
|
||||||
if (err) throw err;
|
console.log("[EUS] Please edit the EUS Config file before restarting.");
|
||||||
global.modules.consoleHelper.printInfo(emoji.heavy_check, "Created config File!");
|
// Config has been made, close framework.
|
||||||
global.modules.consoleHelper.printInfo(emoji.wave, "Please edit the EUS Config file before restarting.");
|
process.exit(0);
|
||||||
// Config has been made, close framework.
|
} else {
|
||||||
process.exit(0);
|
eusConfig = require(`${__dirname}${BASE_PATH}/config.json`);
|
||||||
});
|
if (validateConfig(eusConfig)) console.log("[EUS] EUS config passed all checks");
|
||||||
} else {
|
}
|
||||||
eusConfig = require(`${__dirname}${BASE_PATH}/config.json`);
|
|
||||||
if (validateConfig(eusConfig)) global.modules.consoleHelper.printInfo(emoji.thumb_up, "EUS config passed all checks");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function validateConfig(json) {
|
function validateConfig(json) {
|
||||||
let performShutdownAfterValidation = false;
|
let performShutdownAfterValidation = false;
|
||||||
// URL Tests
|
// URL Tests
|
||||||
if (json["baseURL"] == null) {
|
if (json["baseURL"] == null) {
|
||||||
global.modules.consoleHelper.printError(emoji.dizzy, "EUS baseURL property does not exist!");
|
console.error("EUS baseURL property does not exist!");
|
||||||
performShutdownAfterValidation = true;
|
performShutdownAfterValidation = true;
|
||||||
} else {
|
} else {
|
||||||
if (json["baseURL"] == "")
|
if (json["baseURL"] == "")
|
||||||
global.modules.consoleHelper.printWarn(emoji.dizzy, "EUS baseURL property is blank");
|
console.warn("EUS baseURL property is blank");
|
||||||
const bURL = `${json["baseURL"]}`.split("");
|
const bURL = `${json["baseURL"]}`.split("");
|
||||||
if (bURL.length > 1) {
|
if (bURL.length > 1) {
|
||||||
if (bURL[bURL.length-1] != "/") global.modules.consoleHelper.printWarn(emoji.dizzy, "EUS baseURL property doesn't have a / at the end, this can lead to unpredictable results!");
|
if (bURL[bURL.length-1] != "/") console.warn("EUS baseURL property doesn't have a / at the end, this can lead to unpredictable results!");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (json["baseURL"] != "http://" || json["baseURL"] != "https://") global.modules.consoleHelper.printWarn(emoji.dizzy, "EUS baseURL property is possibly invalid!");
|
if (json["baseURL"] != "http://" || json["baseURL"] != "https://") console.warn("EUS baseURL property is possibly invalid!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// acceptedTypes checks
|
// acceptedTypes checks
|
||||||
if (json["acceptedTypes"] == null) {
|
if (json["acceptedTypes"] == null) {
|
||||||
global.modules.consoleHelper.printError(emoji.dizzy, "EUS acceptedTypes array does not exist!");
|
console.error("EUS acceptedTypes array does not exist!");
|
||||||
performShutdownAfterValidation = true;
|
performShutdownAfterValidation = true;
|
||||||
} else {
|
} else {
|
||||||
if (json["acceptedTypes"].length < 1) global.modules.consoleHelper.printWarn(emoji.dizzy, "EUS acceptedTypes array has no extentions in it, users will not be able to upload images!");
|
if (json["acceptedTypes"].length < 1) console.warn("EUS acceptedTypes array has no extentions in it, users will not be able to upload images!");
|
||||||
}
|
}
|
||||||
// uploadKey checks
|
// uploadKey checks
|
||||||
if (json["uploadKey"] == null) {
|
if (json["uploadKey"] == null) {
|
||||||
global.modules.consoleHelper.printError(emoji.dizzy, "EUS uploadKey property does not exist!");
|
console.error("EUS uploadKey property does not exist!");
|
||||||
performShutdownAfterValidation = true;
|
performShutdownAfterValidation = true;
|
||||||
} else {
|
} else {
|
||||||
if (json["uploadKey"] == "") useUploadKey = false;
|
if (json["uploadKey"] == "") useUploadKey = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if server needs to be shutdown
|
// Check if server needs to be shutdown
|
||||||
if (performShutdownAfterValidation) {
|
if (performShutdownAfterValidation) throw "EUS config properties are missing, refer to docs for more details (https://docs.ethanus.ml)";
|
||||||
global.modules.consoleHelper.printError(emoji.cross, "EUS config properties are missing, refer to docs for more details (https://docs.ethanus.ml)");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
else return true;
|
else return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue