diff --git a/.gitignore b/.gitignore index b3aed83..09ff856 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules rename.sh data-persistence.json +log-journal.json diff --git a/index.js b/index.js index ae109b2..1d6e761 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,8 @@ const bodyParser = require("body-parser"); const ws = require('ws'); const helper = require("./helpers.js"); const loggy = require("./logging") +const Eta = require("eta"); + loggy.init(true) loggy.log("Preparing server", "info", "Server"); @@ -57,6 +59,9 @@ const dataToBeWritten = {}; currentState = Object.assign({}, currentState, loadedData); currentState.textColors = currentState.colorSegments +loggy.log("Reading language file", "info", "Language") +const languageProfile = JSON.parse(fs.readFileSync("lang/en_uk.json", "utf8")); + loggy.log("Preparing websocket", "info", "Websocket"); const wsServer = new ws.Server({ noServer: true }); @@ -88,7 +93,11 @@ function updatedData() { loggy.log("Preparing routes", "info", "Server"); app.get("/", function (req, res) { const data = fs.readFileSync("templates/newAdminPanel.html", "utf8"); - res.send(data); + + res.send( + Eta.render(data, { + lang: languageProfile + })); }); app.get("/timer", function (req, res) { @@ -323,10 +332,23 @@ app.use(function(req, res, next) { +app.use(function(err, req, res, next) { + console.error(err.stack); + if(String(err.stack).includes("TypeError: Cannot read properties of undefined")) { + const data = fs.readFileSync("templates/brokenTranslation.html", "utf8"); + res.send(data); + }else{ + res.status(500).send('Something broke!'); + } + +}); + + + loggy.log("Starting server", "info", "Server"); -const port = 3005 +const port = 3006 process.on('SIGINT', function () { loggy.log("Caught interrupt signal and shutting down gracefully", "info", "Shutdown"); diff --git a/lang/de_de.json b/lang/de_de.json new file mode 100644 index 0000000..438bd04 --- /dev/null +++ b/lang/de_de.json @@ -0,0 +1,31 @@ +{ + "titles": { + "home": "Startseite", + "preview": "Vorschau", + "mode": "Modus", + "messaging": "Nachrichten", + "countdownToTime": "Auf Uhrzeit runterzählen" + }, + "sidebar": { + "home": "Startseite", + "settings": "Einstellungen", + "debug": "Debug", + "about": "Über" + }, + "hints": + { + "previewHint": "Eine Vorschau der Timeransicht.", + "modeHint": "", + "messagingHint": "Zeigt eine Nachricht auf der Timeransicht an." + }, + "placeholders": { + "msgHere": "Message here" + }, + "others": + { + "timer": "Timer", + "clock": "Uhr", + "black": "Schwarz", + "test": "Testbild" + } +} \ No newline at end of file diff --git a/lang/en_uk.json b/lang/en_uk.json new file mode 100644 index 0000000..32859c1 --- /dev/null +++ b/lang/en_uk.json @@ -0,0 +1,46 @@ +{ + "titles": { + "home": "Homepage", + "preview": "Preview", + "mode": "Mode", + "messaging": "Messaging", + "countdownToTime": "Countdown to time" + }, + "sidebar": { + "home": "Home", + "settings": "Settings", + "debug": "Debug", + "about": "About" + }, + "hints": + { + "previewHint": "A preview of what is currently visible on the countdown view", + "modeHint": "", + "messagingHint": "Shows a given message on the timer view" + }, + "placeholders": { + "msgHere": "Message here" + }, + "others": + { + "timer": "Timer", + "clock": "Clock", + "black": "Black", + "test": "Testimage" + }, + "labels": + { + "clockOnTimer": "Show clock on Timer:", + "showMillis": "Show Milliseconds on Timer:", + "showProgress": "Show progressbar:", + "progbarColors": "Progressbar Colors", + "time": "Time", + "color": "Color", + "remove": "Remove" + }, + "_metadata": { + "lang": "en", + "version": "1.0.0", + "authors": ["TheGreydiamond"] + } +} \ No newline at end of file diff --git a/log-journal.json b/log-journal.json index 0c3da15..d5410ac 100644 --- a/log-journal.json +++ b/log-journal.json @@ -1 +1 @@ -[{"timestamp":"2022-03-29 20:16:25.083","level":"info","module":"Logging","message":"2022-03-29 20:16:25.083 [info] [Logging] Logging initialized"},{"timestamp":"2022-03-29 20:16:25.084","level":"info","module":"Server","message":"2022-03-29 20:16:25.084 [info] [Server] Preparing server"},{"timestamp":"2022-03-29 20:16:25.085","level":"info","module":"Server","message":"2022-03-29 20:16:25.085 [info] [Server] Preparing static routes"},{"timestamp":"2022-03-29 20:16:25.087","level":"info","module":"Server","message":"2022-03-29 20:16:25.087 [info] [Server] Preparing middlewares"},{"timestamp":"2022-03-29 20:16:25.088","level":"info","module":"Config","message":"2022-03-29 20:16:25.088 [info] [Config] Loading config"},{"timestamp":"2022-03-29 20:16:25.088","level":"info","module":"Websocket","message":"2022-03-29 20:16:25.088 [info] [Websocket] Preparing websocket"},{"timestamp":"2022-03-29 20:16:25.089","level":"info","module":"Server","message":"2022-03-29 20:16:25.089 [info] [Server] Preparing routes"},{"timestamp":"2022-03-29 20:16:25.091","level":"info","module":"Server","message":"2022-03-29 20:16:25.091 [info] [Server] Starting server"},{"timestamp":"2022-03-29 20:16:35.159","level":"info","module":"Shutdown","message":"2022-03-29 20:16:35.159 [info] [Shutdown] Caught interrupt signal and shutting down gracefully"}] \ No newline at end of file +[{"timestamp":"2022-04-06 20:17:16.831","level":"info","module":"Logging","message":"2022-04-06 20:17:16.831 [info] [Logging] Logging initialized"},{"timestamp":"2022-04-06 20:17:16.833","level":"info","module":"Server","message":"2022-04-06 20:17:16.833 [info] [Server] Preparing server"},{"timestamp":"2022-04-06 20:17:16.834","level":"info","module":"Server","message":"2022-04-06 20:17:16.834 [info] [Server] Preparing static routes"},{"timestamp":"2022-04-06 20:17:16.836","level":"info","module":"Server","message":"2022-04-06 20:17:16.836 [info] [Server] Preparing middlewares"},{"timestamp":"2022-04-06 20:17:16.837","level":"info","module":"Config","message":"2022-04-06 20:17:16.837 [info] [Config] Loading config"},{"timestamp":"2022-04-06 20:17:16.838","level":"info","module":"Language","message":"2022-04-06 20:17:16.838 [info] [Language] Reading language file"},{"timestamp":"2022-04-06 20:17:16.838","level":"info","module":"Websocket","message":"2022-04-06 20:17:16.838 [info] [Websocket] Preparing websocket"},{"timestamp":"2022-04-06 20:17:16.839","level":"info","module":"Server","message":"2022-04-06 20:17:16.839 [info] [Server] Preparing routes"},{"timestamp":"2022-04-06 20:17:16.840","level":"info","module":"Server","message":"2022-04-06 20:17:16.840 [info] [Server] Starting server"},{"timestamp":"2022-04-06 20:17:22.971","level":"info","module":"Shutdown","message":"2022-04-06 20:17:22.971 [info] [Shutdown] Caught interrupt signal and shutting down gracefully"}] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 68f645e..5a6840b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "bootstrap-icons": "^1.8.1", "colors": "^1.4.0", "darkreader": "^4.9.44", + "eta": "^1.12.3", "express": "^4.17.3", "flatpickr": "^4.6.11", "jquery": "^3.6.0", @@ -215,6 +216,17 @@ "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" }, + "node_modules/eta": { + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/eta/-/eta-1.12.3.tgz", + "integrity": "sha512-qHixwbDLtekO/d51Yr4glcaUJCIjGVJyTzuqV4GPlgZo1YpgOKG+avQynErZIYrfM6JIJdtiG2Kox8tbb+DoGg==", + "engines": { + "node": ">=6.0.0" + }, + "funding": { + "url": "https://github.com/eta-dev/eta?sponsor=1" + } + }, "node_modules/etag": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", @@ -881,6 +893,11 @@ "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" }, + "eta": { + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/eta/-/eta-1.12.3.tgz", + "integrity": "sha512-qHixwbDLtekO/d51Yr4glcaUJCIjGVJyTzuqV4GPlgZo1YpgOKG+avQynErZIYrfM6JIJdtiG2Kox8tbb+DoGg==" + }, "etag": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", diff --git a/package.json b/package.json index 0583105..80d774b 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "bootstrap-icons": "^1.8.1", "colors": "^1.4.0", "darkreader": "^4.9.44", + "eta": "^1.12.3", "express": "^4.17.3", "flatpickr": "^4.6.11", "jquery": "^3.6.0", diff --git a/templates/brokenTranslation.html b/templates/brokenTranslation.html new file mode 100644 index 0000000..19d5c66 --- /dev/null +++ b/templates/brokenTranslation.html @@ -0,0 +1,120 @@ + + + +
+ + + +