Update v1.0.3

Took 54 minutes
This commit is contained in:
2022-11-28 10:34:13 +01:00
parent 641120f7cc
commit 6ec0f82356
9 changed files with 74 additions and 23 deletions

View File

@ -5,4 +5,5 @@ export enum RequestType {
JOB = "JOB",
STARTFILL = "STARTFILL",
STOPFILL = "STOPFILL",
DOWNLOAD_DRINKS = "DOWNLOAD_DRINKS"
}

View File

@ -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<boolean> {
@ -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");
}

View File

@ -10,7 +10,7 @@ export class Database {
public static connect(): Promise<void> {
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();

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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() {