diff --git a/server/api.js b/server/api.js index e24580f..42f0c41 100644 --- a/server/api.js +++ b/server/api.js @@ -1,16 +1,27 @@ +import childProcess from 'node:child_process'; import path from 'node:path'; import url from 'node:url'; import fs from 'node:fs'; const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); +const packageFile = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'))); +const commits = await (await fetch(`https://api.github.com/repos/Skoolgq/Polaris/commits`)).json(); /** * @param {import('express').Express} app */ const routes = (app) => { - /*app.get('/api/changelog', async (req, res) => { - - });*/ + app.get('/api/changelog', async (req, res) => { + res.json({ + version: packageFile.version || 'unknown', + commit: { + sha: childProcess.execSync('git rev-parse HEAD').toString().trim() || 'Uuknown', + message: childProcess.execSync('git rev-list --format=%s --max-count=1 HEAD').toString().split('\n')[1].replace('changelog ', '') || 'unknown' + }, + upToDate: (commits[0].sha === childProcess.execSync('git rev-parse HEAD').toString().trim()) || false, + changelog: JSON.parse(fs.readFileSync(path.join(__dirname, '../static/assets/JSON/changelog.json'))) + }); + }); app.get('/api/favicon', async (req, res) => { try { diff --git a/server/index.js b/server/index.js index 8dac2fd..8ff1a19 100644 --- a/server/index.js +++ b/server/index.js @@ -7,6 +7,7 @@ import { pathToFile, TokenManager, rewriter } from './utils.js'; import config from '../polaris.config.js'; import api from './api.js'; +import childProcess from 'node:child_process'; import path from 'node:path'; import http from 'node:http'; import url from 'node:url'; @@ -15,9 +16,10 @@ import fs from 'node:fs'; const app = express(); const server = http.createServer(); const bareServer = createBareServer('/bare/'); +const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); +const packageFile = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'))); const mode = (process.argv[2] === 'prod' || process.argv[2] === 'dev' ? process.argv[2] : (process.argv[3] === 'prod' || process.argv[3] === 'dev' ? process.argv[3] : (config.mode === 'prod' || config.mode === 'dev' ? config.mode : 'prod'))); const port = (process.argv[2] !== 'prod' && process.argv[2] !== 'dev' && Boolean(Number(process.argv[2]))) ? process.argv[2] : (Boolean(Number(process.argv[3])) ? process.argv[3] : (Boolean(Number(config.port)) ? config.port : (mode === 'prod' ? 80 : 8080))); -const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); const swPaths = [ '/uv/sw.js', @@ -139,4 +141,4 @@ server.on('upgrade', (req, socket, head) => { else socket.end(); }); -server.listen(port, () => console.log(`Polaris running\n\nPort: ${server.address().port}\nMode: ${mode === 'dev' ? 'development' : 'production'}\nNode.js: ${process.version}`)); \ No newline at end of file +server.listen(port, () => console.log(`Polaris running\n\nPort: ${server.address().port}\nVersion: ${packageFile.version || 'Unknown'} ${childProcess.execSync('git rev-parse HEAD').toString().trim().slice(0, 7) || 'Unknown'}\nMode: ${mode === 'dev' ? 'development' : 'production'}\nNode.js: ${process.version}`)); \ No newline at end of file diff --git a/static/assets/js/changelog.js b/static/assets/js/changelog.js new file mode 100644 index 0000000..e69de29 diff --git a/static/assets/js/main.js b/static/assets/js/main.js index 03d44fa..9f0fd1d 100644 --- a/static/assets/js/main.js +++ b/static/assets/js/main.js @@ -48,6 +48,14 @@ if (window.self === window.top && location.pathname !== '/view') setTimeout(asyn if (location.pathname === '/cheats') Cheats.load(); }, 500); +fetch('/api/changelog') + .then(res => res.json()) + .then(changelog => { + document.querySelector('#version').textContent = changelog.version !== 'unknown' ? 'v' + changelog.version : changelog.version; + document.querySelector('#version_sha').textContent = changelog.commit.sha.slice(0, 7); + document.querySelector('#up_to_date').textContent = changelog.upToDate ? 'yes' : 'no'; + }); + if (location.pathname === '/') { fetch('/api/games') .then(res => res.json()) @@ -99,10 +107,10 @@ if (location.pathname === '/') { return (document.querySelector('.container.right').clientHeight - getVH(2)) - total; } - fetch('/assets/JSON/changelog.json') + fetch('/api/changelog') .then(res => res.json()) .then(changelog => { - changelog + changelog.changelog .filter((data, i) => !(i >= 3)) .forEach(change => { const log = document.createElement('div'); diff --git a/static/changelog.html b/static/changelog.html new file mode 100644 index 0000000..702875d --- /dev/null +++ b/static/changelog.html @@ -0,0 +1,33 @@ + + + + + + + + + + + Polaris + + + + + + +
+
+

Changelog

+ +
+ Coming Soon +
+
+
+ + + + + + + \ No newline at end of file diff --git a/templates/sidebar.html b/templates/sidebar.html index 493693d..c7c022f 100644 --- a/templates/sidebar.html +++ b/templates/sidebar.html @@ -7,7 +7,8 @@

Panic Key

- +
@@ -63,4 +64,18 @@
+ +
+
+ +

+ Running Polaris unknown +
+
+ + Commit: unknown +
+ Up to Date: no +
+

\ No newline at end of file