diff --git a/src/http/api.ts b/src/http/api.ts index 87fc996f..494c6f0a 100644 --- a/src/http/api.ts +++ b/src/http/api.ts @@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url'; import path from 'node:path'; import dayjs from 'dayjs'; import { PlayerUtil } from '../util/PlayerUtil.js'; +import { msToTime } from '../util/time.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -22,7 +23,8 @@ export class ApiModule { .limit(30) res.render('index.ejs', { records, - dayjs + dayjs, + msToTime }); }) @@ -62,7 +64,8 @@ export class ApiModule { res.render('search.ejs', { records, dayjs, - q: req.query.q + q: req.query.q, + msToTime }); }) @@ -74,7 +77,8 @@ export class ApiModule { res.render('details.ejs', { record, dayjs, - player + player, + msToTime }); }) diff --git a/src/http/views/details.ejs b/src/http/views/details.ejs index 2e15fe11..dbab6b6e 100644 --- a/src/http/views/details.ejs +++ b/src/http/views/details.ejs @@ -5,11 +5,13 @@ <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>simrail.alekswilc.dev</title> - <meta name="description" content="<%= record.stationName %> | <%= record.userUsername %> | <%= dayjs(record.leftDate).format('hh:mm DD/MM/YYYY') %>"> + <meta name="description" + content="<%= record.stationName %> | <%= record.userUsername %> | <%= dayjs(record.leftDate).format('hh:mm DD/MM/YYYY') %>"> <meta property="og:title" content="Simrail Log"> <meta property="og:url" content="https://simrail.alekswilc.dev/details/<%= record.id %>/"> - <meta property="og:description" content="<%= record.stationName %> | <%= record.userUsername %> | <%= dayjs(record.leftDate).format('hh:mm DD/MM/YYYY') %>""> - <meta property="og:type" content="website"> + <meta property="og:description" + content="<%= record.stationName %> | <%= record.userUsername %> | <%= dayjs(record.leftDate).format('hh:mm DD/MM/YYYY') %>""> + <meta property=" og:type" content="website"> <meta property="og:image" content="<%= record.userAvatar %>" /> <meta name="twitter:card" content="summary_large_image"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/open-fonts@1.1.1/fonts/inter.min.css"> @@ -57,12 +59,12 @@ </p> <p>Serwer: <%= record.server.toUpperCase() %> </p> - <p>Data wejścia: <%= record.joinedDate ? dayjs(record.joinedDate).format('HH:mm DD/MM/YYYY') : '--:-- --/--/--' %> (<%= - record.joinedDate ? dayjs(record.joinedDate).fromNow() : '--' %>)</p> + <p>Data wejścia: <%= record.joinedDate ? dayjs(record.joinedDate).format('HH:mm DD/MM/YYYY') : '--:-- --/--/--' + %> (<%= record.joinedDate ? dayjs(record.joinedDate).fromNow() : '--' %>)</p> <p>Data wyjścia: <%= dayjs(record.leftDate).format('HH:mm DD/MM/YYYY') %> (<%= dayjs(record.leftDate).fromNow() %>)</p> - - + <p>Spędzony czas: <%= record.joinedDate ? msToTime(record.leftDate - record.joinedDate) : '--' %> + </p> <br /> <code class="clickable" style="white-space: pre-line" onclick="copydata()" id="data">;station: <%= record.stationName %> diff --git a/src/http/views/index.ejs b/src/http/views/index.ejs index 79a13773..42ec6532 100644 --- a/src/http/views/index.ejs +++ b/src/http/views/index.ejs @@ -51,10 +51,14 @@ <%= dayjs(record.leftDate).format('HH:mm DD/MM/YYYY') %> </p> </summary> - <p>Data dołączenia: <%= record.joinedDate ? dayjs(record.joinedDate).format('HH:mm DD/MM/YYYY') : '--:-- --/--/--' %> (<%= - record.joinedDate ? dayjs(record.joinedDate).fromNow() : '--' %>)</p> + <p>Data dołączenia: <%= record.joinedDate ? dayjs(record.joinedDate).format('HH:mm DD/MM/YYYY') + : '--:-- --/--/--' %> (<%= record.joinedDate ? dayjs(record.joinedDate).fromNow() : '--' %>) + </p> <p>Data wyjścia: <%= dayjs(record.leftDate).format('HH:mm DD/MM/YYYY') %> (<%= dayjs(record.leftDate).fromNow() %>)</p> + <p>Spędzony czas: <%= record.joinedDate ? msToTime(record.leftDate - record.joinedDate) : '--' %> + </p> + <a href="/details/<%= record.id %>"> <button>Więcej</button> </a> diff --git a/src/http/views/search.ejs b/src/http/views/search.ejs index 568d1bf7..6991b6d0 100644 --- a/src/http/views/search.ejs +++ b/src/http/views/search.ejs @@ -53,10 +53,14 @@ <%= dayjs(record.leftDate).format('HH:mm DD/MM/YYYY') %> </p> </summary> - <p>Data dołączenia: <%= record.joinedDate ? dayjs(record.joinedDate).format('HH:mm DD/MM/YYYY') : '--:-- --/--/--' %> (<%= - record.joinedDate ? dayjs(record.joinedDate).fromNow() : '--' %>)</p> + <p>Data dołączenia: <%= record.joinedDate ? dayjs(record.joinedDate).format('HH:mm DD/MM/YYYY') + : '--:-- --/--/--' %> (<%= record.joinedDate ? dayjs(record.joinedDate).fromNow() : '--' %>) + </p> <p>Data wyjścia: <%= dayjs(record.leftDate).format('HH:mm DD/MM/YYYY') %> (<%= dayjs(record.leftDate).fromNow() %>)</p> + <p>Spędzony czas: <%= record.joinedDate ? msToTime(record.leftDate - record.joinedDate) : '--' %> + </p> + <a href="/details/<%= record.id %>"> <button>Więcej</button> </a> diff --git a/src/index.ts b/src/index.ts index 8e9df414..af4fc7e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { createClient, RedisClientType } from 'redis'; -import './util/dayjs.js'; +import './util/time.js'; import { SimrailClient, SimrailClientEvents } from './util/SimrailClient.js'; import dayjs from 'dayjs'; import { StationsModule } from './modules/stations.js'; diff --git a/src/util/dayjs.ts b/src/util/dayjs.ts deleted file mode 100644 index a9369e84..00000000 --- a/src/util/dayjs.ts +++ /dev/null @@ -1,6 +0,0 @@ -import dayjs from 'dayjs'; -import relativeTime from 'dayjs/plugin/relativeTime.js'; -import pl from 'dayjs/locale/pl.js'; - -dayjs.extend(relativeTime); -dayjs.locale(pl) \ No newline at end of file