diff --git a/doc/installPi.sh b/doc/installPi.sh index ffeda76..3f9e2e2 100644 --- a/doc/installPi.sh +++ b/doc/installPi.sh @@ -1,19 +1,49 @@ #!/bin/bash -apt update -apt install +if [ "$EUID" -ne 0 ] +then + echo "Please run as root!" + exit +fi -apt install --no-install-recommends xserver-xorg x11-xserver-utils xinit openbox -y -apt purge nodejs npm -y -curl -fsSL https://deb.nodesource.com/setup_19.x | sudo bash - -apt install -y nodejs -apt install gcc g++ make -y -curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null -echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list apt update -apt install yarn git cmake make chromium-browser unclutter -y -apt upgrade -y + +apt install --no-install-recommends ufw xserver-xorg x11-xserver-utils xinit openbox -y +apt install git gcc g++ make cmake chromium-browser unclutter -y +apt purge nodejs npm -y + +# XServer echo "allowed_users=anybody" >/etc/X11/Xwrapper.config cp autostart.config /etc/xdg/openbox/autostart + +# Keys and stuff --- +# Nodejs +curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash + +# Yarn +curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null +echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list + +# MongoDB +wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - +echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list + +# End Keys and stuff --- + + +# Firewall +ufw allow ssh +ufw allow 3000/tcp +ufw allow 3015/tcp +ufw --force enable + +# Final update +apt update +apt install nodejs yarn mongodb-org -y +apt upgrade -y + +systemctl daemon-reload +systemctl enable mongod + reboot now diff --git a/public/stylesheets/settings.css b/public/stylesheets/settings.css index 8ab0cda..a807447 100644 --- a/public/stylesheets/settings.css +++ b/public/stylesheets/settings.css @@ -1,6 +1,7 @@ #settings { display: grid; - grid-template-columns: repeat(4, calc(90% / 4)); - grid-template-rows: repeat(5, calc(90% / 5)); - grid-gap: 10% 5%; + grid-template-columns: repeat(4, calc(85% / 4)); + grid-template-rows: repeat(4, calc(85% / 4)); + grid-gap: 5% 5%; + width: 100%; } \ No newline at end of file diff --git a/src/RequestType.ts b/src/RequestType.ts index 7382c13..0cfa1cb 100644 --- a/src/RequestType.ts +++ b/src/RequestType.ts @@ -5,4 +5,5 @@ export enum RequestType { JOB = "JOB", STARTFILL = "STARTFILL", STOPFILL = "STOPFILL", + DOWNLOAD_DRINKS = "DOWNLOAD_DRINKS" } \ No newline at end of file diff --git a/src/Utils.ts b/src/Utils.ts index b4a95ce..d5dce86 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -1,6 +1,7 @@ import * as dns from "dns"; import * as fs from "fs"; import * as https from 'https'; +import path from "path"; export class Utils { public static checkInternet(): Promise { @@ -22,7 +23,14 @@ export class Utils { } static downloadImage(url, filepath) { + return new Promise((resolve, reject) => { + try { + if (!fs.existsSync(path.dirname(filepath))) + fs.mkdirSync(path.dirname(filepath)); + } catch (e) { + + } https.get(url, (res) => { if (res.statusCode === 200) { res.pipe(fs.createWriteStream(filepath)) @@ -38,19 +46,16 @@ export class Utils { }); } - static deleteImage( id ) - { + static deleteImage(id) { try { fs.unlinkSync("./public/images/" + id + ".png"); - } catch( e ) - { + } catch (e) { } } - static checkForImage( id ) - { + static checkForImage(id) { return fs.existsSync("./public/images/" + id + ".png"); } diff --git a/src/database/Database.ts b/src/database/Database.ts index 404401f..d6ed6e7 100644 --- a/src/database/Database.ts +++ b/src/database/Database.ts @@ -10,7 +10,7 @@ export class Database { public static connect(): Promise { return new Promise(async (resolve, reject) => { try { - await Mongoose.connect("mongodb://localhost:27017/iTender?retryWrites=true"); + await Mongoose.connect("mongodb://127.0.0.1:27017/iTender?retryWrites=true"); log("Connected to Database"); /*if (Mongoose.connection.readyState == Mongoose.ConnectionStates.connected) { resolve(); diff --git a/src/iTender.ts b/src/iTender.ts index 5665282..af52182 100644 --- a/src/iTender.ts +++ b/src/iTender.ts @@ -357,11 +357,12 @@ export class iTender { // Download thumbnail if (!Utils.checkForImage(remote._id)) { + let url = "https://itender.iif.li/images/" + remote._id + ".png"; try { - await Utils.downloadImage("https://itender.iif.li/images/" + remote._id + ".png", "./public/images/" + drink._id + ".png") + await Utils.downloadImage(url, "./public/images/" + drink._id + ".png") log("Drink " + remote.name + "'s Thumbnail downloaded"); } catch (e) { - log("Drink " + remote.name + " failed to download thumbnail!\n" + e); + log("Drink " + remote.name + " failed to download thumbnail! (" + url + ") | " + e); } } diff --git a/src/routes/ws/websocketRoute.ts b/src/routes/ws/websocketRoute.ts index ae00efd..5340e05 100644 --- a/src/routes/ws/websocketRoute.ts +++ b/src/routes/ws/websocketRoute.ts @@ -145,6 +145,11 @@ router.ws('/', async (ws, req, next) => { WebSocketHandler.answerRequest(msg.data["type"] as RequestType, iTender.currentJob); break; } + case RequestType.DOWNLOAD_DRINKS: { + await iTender.refreshFromServer(); + WebSocketHandler.answerRequest(msg.data["type"] as RequestType, "ok"); + break; + } } break; diff --git a/src/web/main.ts b/src/web/main.ts index e6fb0c5..ba2c86f 100644 --- a/src/web/main.ts +++ b/src/web/main.ts @@ -102,6 +102,13 @@ function setupOnClickEvents() { WebWebSocketHandler.request(RequestType.CONTAINERS).then(Setup.onContainerUpdate); + + // Settings Btns + const downloadDrinks = document.getElementById("settings_refreshDrinks") as HTMLButtonElement; + downloadDrinks.onclick = () => { + WebWebSocketHandler.request(RequestType.DOWNLOAD_DRINKS); + } + } function load() { diff --git a/views/index.pug b/views/index.pug index 4a7d7dc..d4b7c22 100644 --- a/views/index.pug +++ b/views/index.pug @@ -54,5 +54,6 @@ block settings button.btn.btn-primary#settings_refreshDrinks Getränke herunterladen + block main // Main is build dynamically