Browse Source

Added config versions and config version checking and alerting

Kristian Vos 4 years ago
parent
commit
740ff0cb23

+ 2 - 1
backend/config/template.json

@@ -90,5 +90,6 @@
                 "Requeing"
             ]
         }
-    }
+	},
+	"configVersion": 1
 }

+ 7 - 0
backend/index.js

@@ -3,6 +3,8 @@ import "./loadEnvVariables.js";
 import util from "util";
 import config from "config";
 
+const REQUIRED_CONFIG_VERSION = 1;
+
 // eslint-disable-next-line
 Array.prototype.remove = function (item) {
 	this.splice(this.indexOf(item), 1);
@@ -27,6 +29,11 @@ console.log = (...args) => {
 	if (!blacklisted) oldConsole.log.apply(null, args);
 };
 
+if (!config.has("configVersion") || config.get("configVersion") !== REQUIRED_CONFIG_VERSION) {
+	console.log("CONFIG VERSION IS WRONG. PLEASE UPDATE YOUR CONFIG WITH THE HELP OF THE TEMPLATE FILE AND THE README FILE.");
+	process.exit();
+}
+
 const fancyConsole = config.get("fancyConsole");
 
 if (config.debug && config.debug.traceUnhandledPromises === true) {

+ 2 - 1
frontend/dist/config/template.json

@@ -16,5 +16,6 @@
 		"logo_blue": "/assets/blue_wordmark.png",
 		"siteName": "Musare",
 		"github": "https://github.com/Musare/MusareNode"
-	}
+	},
+	"configVersion": 1
 }

+ 1 - 1
frontend/dist/index.tpl.html

@@ -36,7 +36,7 @@
 	<link rel='stylesheet' href='/index.css'>
 	<script src='https://www.youtube.com/iframe_api'></script>
 	<script type='text/javascript' src='/vendor/can-autoplay.min.js'></script>
-	<script src="/vendor/socket.io.2.2.0.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I="></script>
+	<script src="/vendor/socket.io.2.2.0.js"></script>
 	<script type='text/javascript' src='/vendor/lofig.1.3.3.min.js'></script>
 </head>
 <body>

+ 11 - 0
frontend/src/main.js

@@ -6,6 +6,8 @@ import store from "./store";
 import App from "./App.vue";
 import io from "./io";
 
+const REQUIRED_CONFIG_VERSION = 1;
+
 const handleMetadata = attrs => {
 	document.title = `Musare | ${attrs.title}`;
 };
@@ -136,6 +138,15 @@ const router = new VueRouter({
 });
 
 lofig.folder = "../config/default.json";
+lofig.get("configVersion").then(configVersion => {
+	if (configVersion !== REQUIRED_CONFIG_VERSION) {
+		// eslint-disable-next-line no-alert
+		alert(
+			"CONFIG VERSION IS WRONG. PLEASE UPDATE YOUR CONFIG WITH THE HELP OF THE TEMPLATE FILE AND THE README FILE."
+		);
+		window.stop();
+	}
+});
 lofig.get("serverDomain").then(serverDomain => {
 	io.init(serverDomain);
 	io.getSocket(socket => {