From 5e96ac226c6bae065b2696095558ccde7fb94259 Mon Sep 17 00:00:00 2001
From: alekswilc <aleks@alekswilc.dev>
Date: Tue, 20 Aug 2024 19:46:48 +0200
Subject: [PATCH] fix #23

---
 src/http/routes/leaderboard.ts    | 1 -
 src/http/routes/profile.ts        | 7 +++----
 src/http/routes/stations.ts       | 6 +++---
 src/http/routes/trains.ts         | 4 ++--
 src/http/views/trains/details.ejs | 3 +--
 src/modules/stations.ts           | 8 ++++----
 src/util/PlayerUtil.ts            | 2 +-
 7 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/http/routes/leaderboard.ts b/src/http/routes/leaderboard.ts
index 8e791848..bb273f38 100644
--- a/src/http/routes/leaderboard.ts
+++ b/src/http/routes/leaderboard.ts
@@ -1,6 +1,5 @@
 import { Router } from 'express';
 import dayjs from 'dayjs';
-import { PlayerUtil } from '../../util/PlayerUtil.js';
 import { msToTime } from '../../util/time.js';
 
 import { PipelineStage } from 'mongoose';
diff --git a/src/http/routes/profile.ts b/src/http/routes/profile.ts
index 840a69ee..b2e64601 100644
--- a/src/http/routes/profile.ts
+++ b/src/http/routes/profile.ts
@@ -1,9 +1,8 @@
 import { Router } from 'express';
-import dayjs from 'dayjs';
-import { PlayerUtil } from '../../util/PlayerUtil.js';
 import { msToTime } from '../../util/time.js';
 import { MProfile } from '../../mongo/profile.js';
 import { MBlacklist } from '../../mongo/blacklist.js';
+import { SteamUtil } from '../../util/SteamUtil.js';
 
 
 
@@ -18,8 +17,8 @@ export class ProfilesRoute {
             if (!player) return res.render('profiles/private.ejs');
             const blacklist = await MBlacklist.findOne({ steam: req.params.id! });
             if (blacklist && blacklist.status) return res.render('profiles/private.ejs');
-            const steam = await PlayerUtil.getPlayer(player?.steam!);
-            const steamStats = await PlayerUtil.getPlayerStats(player?.steam!);
+            const steam = await SteamUtil.getPlayer(player?.steam!);
+            const steamStats = await SteamUtil.getPlayerStats(player?.steam!);
 
             res.render('profiles/index.ejs', {
                 player, steam, steamStats: steamStats,
diff --git a/src/http/routes/stations.ts b/src/http/routes/stations.ts
index 01b53f56..43e50e6f 100644
--- a/src/http/routes/stations.ts
+++ b/src/http/routes/stations.ts
@@ -1,10 +1,10 @@
 import { Router } from 'express';
-import { MLog, raw_schema } from '../../mongo/logs.js';
+import { MLog } from '../../mongo/logs.js';
 import dayjs from 'dayjs';
-import { PlayerUtil } from '../../util/PlayerUtil.js';
 import { msToTime } from '../../util/time.js';
 import { PipelineStage } from 'mongoose';
 import { MBlacklist } from '../../mongo/blacklist.js';
+import { SteamUtil } from '../../util/SteamUtil.js';
 
 const generateSearch = (regex: RegExp) => [
     {
@@ -58,7 +58,7 @@ export class StationsRoute {
             const record = await MLog.findOne({ id: req.params.id });
             const blacklist = await MBlacklist.findOne({ steam: record?.userSteamId! });
             if (blacklist && blacklist.status) return res.redirect('/stations/');
-            const player = await PlayerUtil.getPlayer(record?.userSteamId!);
+            const player = await SteamUtil.getPlayer(record?.userSteamId!);
 
             res.render('stations/details.ejs', {
                 record,
diff --git a/src/http/routes/trains.ts b/src/http/routes/trains.ts
index 91345626..07de90fd 100644
--- a/src/http/routes/trains.ts
+++ b/src/http/routes/trains.ts
@@ -1,10 +1,10 @@
 import { Router } from 'express';
 import dayjs from 'dayjs';
-import { PlayerUtil } from '../../util/PlayerUtil.js';
 import { msToTime } from '../../util/time.js';
 import { PipelineStage } from 'mongoose';
 import { MTrainLog, raw_schema } from '../../mongo/trainLogs.js';
 import { MBlacklist } from '../../mongo/blacklist.js';
+import { SteamUtil } from '../../util/SteamUtil.js';
 
 const generateSearch = (regex: RegExp) => [
     {
@@ -50,7 +50,7 @@ export class TrainsRoute {
         app.get('/details/:id', async (req, res) => {
             if (!req.params.id) return res.redirect('/trains/');
             const record = await MTrainLog.findOne({ id: req.params.id });
-            const player = await PlayerUtil.getPlayer(record?.userSteamId!);
+            const player = await SteamUtil.getPlayer(record?.userSteamId!);
             const blacklist = await MBlacklist.findOne({ steam: record?.userSteamId! });
             if (blacklist && blacklist.status) return res.redirect('/trains/');
 
diff --git a/src/http/views/trains/details.ejs b/src/http/views/trains/details.ejs
index c6124981..a8d5b5fe 100644
--- a/src/http/views/trains/details.ejs
+++ b/src/http/views/trains/details.ejs
@@ -52,8 +52,7 @@
         <p>Użytkownik: <a href="/profiles/<%- record.userSteamId %>">
                 <%- record.userUsername %>
             </a></p>
-        <p>Stacja: <%- record.stationName %>
-        </p>
+
         <p>Pociąg: <%- record.trainName %> <%- record.trainNumber %>
         </p>
         <p>Data wejścia: <%- record.joinedDate ? dayjs(record.joinedDate).format('HH:mm DD/MM/YYYY') : '--:-- --/--/--'
diff --git a/src/modules/stations.ts b/src/modules/stations.ts
index 9e2ef9df..1759da63 100644
--- a/src/modules/stations.ts
+++ b/src/modules/stations.ts
@@ -4,28 +4,28 @@ import { IPlayer } from '../types/player.js';
 import { SimrailClientEvents } from '../util/SimrailClient.js';
 import { v4 } from 'uuid';
 import { MProfile } from '../mongo/profile.js';
-import { PlayerUtil } from '../util/PlayerUtil.js';
+import { SteamUtil } from '../util/SteamUtil.js';
 
 export class StationsModule {
     public static load() {
 
         client.on(SimrailClientEvents.StationLeft, async (server: Server, station: Station, player: IPlayer, joinedAt: number) => {
-            const stats = await PlayerUtil.getPlayerStats(player.steamid);
+            const stats = await SteamUtil.getPlayerStats(player.steamid);
             const date = new Date();
             if (stats) {
                 const time = (date.getTime() - joinedAt) ?? 0;
-                
+
                 const userProfile = await MProfile.findOne({ steam: player.steamid }) ?? await MProfile.create({ steam: player.steamid, id: v4(), steamName: player.personaname });
                 if (!userProfile.dispatcherStats) userProfile.dispatcherStats = {};
 
                 if (userProfile.dispatcherStats[station.Name]) {
                     userProfile.dispatcherStats[station.Name].time = userProfile.dispatcherStats[station.Name].time + time;
-
                 } else {
                     userProfile.dispatcherStats[station.Name] = {
                         time
                     }
                 }
+
                 if (Number.isNaN(userProfile.dispatcherStats[station.Name].time)) userProfile.dispatcherStats[station.Name].time = 0;
 
                 if (!userProfile.dispatcherTime) userProfile.dispatcherTime = 0;
diff --git a/src/util/PlayerUtil.ts b/src/util/PlayerUtil.ts
index 9ea2c832..49c3e5da 100644
--- a/src/util/PlayerUtil.ts
+++ b/src/util/PlayerUtil.ts
@@ -14,7 +14,7 @@ const fetchFuckingSteamApi = (url: string) => {
                     console.log('STEAM request failed! ', url.replace(STEAM_API_KEY!, '[XXX]'), retries)
 
                     retries++;
-                    setTimeout(() => req(), 500);
+                    setTimeout(() => req(), 1000);
                 })
         }
         req();