diff --git a/.hmrc b/.hmrc
index 60bb073..d4489dd 100644
--- a/.hmrc
+++ b/.hmrc
@@ -2,7 +2,7 @@
"path": "G:\\Other\\Development\\Projects\\[ideas]\\domino",
"name": "domino-server",
"initialVersion": "0.1.1",
- "version": "0.1.3",
+ "version": "0.1.4",
"docker": {
"useRegistry": true,
"registry": "192.168.1.115:5000",
@@ -75,7 +75,7 @@
},
"_backup": {
"name": "domino-server",
- "version": "0.1.2",
+ "version": "0.1.3",
"description": "",
"main": "index.js",
"engines": {
@@ -88,8 +88,8 @@
"test": "node --env-file=.env -r ts-node/register src/test.ts",
"test:watch": "node --env-file=.env --watch -r ts-node/register src/test.ts",
"docker-build": "docker build -t 192.168.1.115:5000/arhuako/domino-server:latest .",
- "docker-tag": "docker tag 192.168.1.115:5000/arhuako/domino-server:latest 192.168.1.115:5000/arhuako/domino-server:0.1.2",
- "docker-push": "docker push 192.168.1.115:5000/arhuako/domino-server:latest && docker push 192.168.1.115:5000/arhuako/domino-server:0.1.2",
+ "docker-tag": "docker tag 192.168.1.115:5000/arhuako/domino-server:latest 192.168.1.115:5000/arhuako/domino-server:0.1.3",
+ "docker-push": "docker push 192.168.1.115:5000/arhuako/domino-server:latest && docker push 192.168.1.115:5000/arhuako/domino-server:0.1.3",
"publish": "npm run docker-build && npm run docker-tag && npm run docker-push"
},
"keywords": [],
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cd5a941..c1b0e7f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
## Unreleased
+## 0.1.4 - 2024-07-20
+
## 0.1.3 - 2024-07-18
### Added
- game by rounds
diff --git a/package.json b/package.json
index 47a97b0..1961a19 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "domino-server",
- "version": "0.1.3",
+ "version": "0.1.4",
"description": "",
"main": "index.js",
"engines": {
@@ -13,8 +13,8 @@
"test": "node --env-file=.env -r ts-node/register src/test.ts",
"test:watch": "node --env-file=.env --watch -r ts-node/register src/test.ts",
"docker-build": "docker build -t 192.168.1.115:5000/arhuako/domino-server:latest .",
- "docker-tag": "docker tag 192.168.1.115:5000/arhuako/domino-server:latest 192.168.1.115:5000/arhuako/domino-server:0.1.3",
- "docker-push": "docker push 192.168.1.115:5000/arhuako/domino-server:latest && docker push 192.168.1.115:5000/arhuako/domino-server:0.1.3",
+ "docker-tag": "docker tag 192.168.1.115:5000/arhuako/domino-server:latest 192.168.1.115:5000/arhuako/domino-server:0.1.4",
+ "docker-push": "docker push 192.168.1.115:5000/arhuako/domino-server:latest && docker push 192.168.1.115:5000/arhuako/domino-server:0.1.4",
"publish": "npm run docker-build && npm run docker-tag && npm run docker-push"
},
"keywords": [],
diff --git a/public/CHANGELOG.html b/public/CHANGELOG.html
index 287e56a..c69d4d3 100644
--- a/public/CHANGELOG.html
+++ b/public/CHANGELOG.html
@@ -1,5 +1,6 @@
Changelog
All notable changes to this project will be documented in this file.
+0.1.4 - 2024-07-20
0.1.3 - 2024-07-18
Added
diff --git a/public/index.html b/public/index.html
deleted file mode 100644
index 7b7a371..0000000
--- a/public/index.html
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
- Domino Tiles
-
-
-
-
-
-
-
-
-
-
diff --git a/public/script.js b/public/script.js
deleted file mode 100644
index 0da70e6..0000000
--- a/public/script.js
+++ /dev/null
@@ -1,35 +0,0 @@
-document.querySelectorAll('.domino').forEach(domino => {
- const topValue = domino.getAttribute('data-top');
- const bottomValue = domino.getAttribute('data-bottom');
-
- addPips(domino.querySelector('.top'), topValue);
- addPips(domino.querySelector('.bottom'), bottomValue);
-});
-
-function addPips(half, value) {
- const pipPositions = getPipPositions(value);
- pipPositions.forEach(pos => {
- const pip = document.createElement('div');
- pip.className = 'pip';
- pip.style.left = pos[0];
- pip.style.top = pos[1];
- half.appendChild(pip);
- });
-}
-
-function getPipPositions(value) {
- const p1 = '17%';
- const p2 = '42%';
- const p3 = '67%';
-
- const positions = {
- 0: [],
- 1: [[p2, p2]],
- 2: [[p1, p1], [p3, p3]],
- 3: [[p1, p1], [p2, p2], [p3, p3]],
- 4: [[p1, p1], [p1, p3], [p3, p1], [p3, p3]],
- 5: [[p1, p1], [p1, p3], [p2, p2], [p3, p1], [p3, p3]],
- 6: [[p1, p1], [p1, p3], [p2, p1], [p2, p3], [p3, p1], [p3, p3]],
- };
- return positions[value];
-}
diff --git a/public/styles.css b/public/styles.css
deleted file mode 100644
index 8ec5a31..0000000
--- a/public/styles.css
+++ /dev/null
@@ -1,77 +0,0 @@
-body {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- background: #f0f0f0;
- font-family: Arial, sans-serif;
-}
-
-.domino {
- width: 100px;
- height: 200px;
- background: white;
- border: 2px solid black;
- border-radius: 10px;
- position: relative;
- display: flex;
- flex-direction: column;
-}
-
-.half {
- flex: 1;
- display: flex;
- justify-content: center;
- align-items: center;
- position: relative;
-}
-
-.top {
- border-bottom: 2px solid black;
-}
-
-.pip {
- width: 15px;
- height: 15px;
- background: black;
- border-radius: 50%;
- position: absolute;
-}
-
-.pip[data-number="1"] {
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
-}
-
-.pip[data-number="2"] {
- left: 25%;
- top: 25%;
-}
-
-.pip[data-number="3"] {
- right: 25%;
- top: 25%;
-}
-
-.pip[data-number="4"] {
- left: 25%;
- bottom: 25%;
-}
-
-.pip[data-number="5"] {
- right: 25%;
- bottom: 25%;
-}
-
-.pip[data-number="6"] {
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
-}
-
-.pip[data-number="7"] {
- right: 50%;
- top: 50%;
- transform: translate(50%, -50%);
-}
diff --git a/src/server/controllers/AuthController.ts b/src/server/controllers/AuthController.ts
index abccd04..a5cecc1 100644
--- a/src/server/controllers/AuthController.ts
+++ b/src/server/controllers/AuthController.ts
@@ -31,17 +31,35 @@ export class AuthController extends BaseController {
}
}
- _jwtSignUser(user: User | null, res: Response) {
+ async refresh(req: Request, res: Response): Promise {
+ const { log } = req;
+ try {
+ const { token } = req.body;
+ const user = await this.security.verifyJwt(token);
+ this._jwtSignUser(user, res, true);
+ } catch (error) {
+ this.handleError(res, error);
+ }
+ }
+
+ _jwtSignUser(user: User | null, res: Response, isRefresh: boolean = false) {
if (user === null) {
res.status(401).json({ error: 'Unauthorized' }).end();
return;
}
delete user.hash;
- const token = this.security.signJwt(user);
+ const token = this.security.signJwt(user, false);
if (token === null) {
res.status(401).json({ error: 'Unauthorized' }).end();
} else {
- res.status(200).json({ token }).end();
+ const data: {
+ token: string,
+ refreshToken?: string
+ } = { token };
+ if (!isRefresh) {
+ data.refreshToken = this.security.signJwt(user, true);
+ }
+ res.status(200).json(data).end();
}
return;
}
@@ -173,7 +191,7 @@ export class AuthController extends BaseController {
req.user = user;
next();
} catch (error) {
- return res.status(403).json({ error: 'Forbidden' });
+ return res.status(401).json({ error: 'Unauthorized' });
}
}
}
@@ -194,7 +212,7 @@ export class AuthController extends BaseController {
req.token = apiToken;
next();
} catch (error) {
- return res.status(403).json({ error: 'Forbidden' });
+ return res.status(401).json({ error: 'Unauthorized' });
}
}
}
diff --git a/src/server/controllers/UpdaterController.ts b/src/server/controllers/UpdaterController.ts
new file mode 100644
index 0000000..9735388
--- /dev/null
+++ b/src/server/controllers/UpdaterController.ts
@@ -0,0 +1,33 @@
+import { Request, Response } from "express";
+import { BaseController } from "./BaseController";
+
+const json = {
+ "version": "0.1.10",
+ "notes": "ADDEDD\n======\n- Updater\n- Refresh authentication when expires\n- Match summary page phase 1",
+ "pub_date": "2024-07-20T10:25:57Z",
+ "platforms": {
+ "windows-x86_64": {
+ "signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVTdDh5VEM1Y1hnUUF0N0lJVEl0SDM0QnAvRCs0OXpzMUhyQ3A3UHNxbUsrSWFMOWFDTkJqVVZBRXdNWmR3ME5hUU8wUEh4ajhaUktoZGEycFhoaFpwTno2WlZBRlhaRHdrPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNzIxNDgwMDM3CWZpbGU6ZG9taW5vLWNsaWVudF8wLjEuMTBfeDY0LXNldHVwLm5zaXMuemlwCk0rTDNUR3N6WHY5VnRRQU9hRnVFQnQybStFcndYRDRQY0hQNng1eFFDKzFvVngzaXhOaGZRRjBndkhxYXQxUkNrT1RNcHo2enM0VXh0eUJITHlveENnPT0K",
+ "url": "https://test.xintanalabs.net/updates/domino-client_0.1.10_x64-setup.nsis.zip"
+ }
+ }
+}
+
+export class UpdaterController extends BaseController {
+ async checkUpdate(req: Request, res: Response): Promise {
+ this.logger.info('Checking for updates');
+ return res.json(json).status(200).end();
+
+ return res.status(204).end();
+ }
+
+ // async startMatchSession(data: any): Promise {
+ // const response = await this.sessionManager.startSession(data);
+ // return response;
+ // }
+
+ // async joinMatchSession(data: any, socketId: string): Promise {
+ // const response = await this.sessionManager.joinSession(data, socketId);
+ // return response;
+ // }
+}
\ No newline at end of file
diff --git a/src/server/index.ts b/src/server/index.ts
index 810bf16..2d63264 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -24,6 +24,7 @@ app.use(express.text());
app.use(express.urlencoded({extended: true }));
app.use(useRouter())
+app.use(express.static(join(process.cwd(), 'public')));
app.get('/', (req, res) => {
res.sendFile(join(__dirname, 'index.html'));
diff --git a/src/server/managers/SecurityManager.ts b/src/server/managers/SecurityManager.ts
index b898e5c..83b1ecb 100644
--- a/src/server/managers/SecurityManager.ts
+++ b/src/server/managers/SecurityManager.ts
@@ -2,8 +2,9 @@ import crypto from 'crypto';
import jwt from 'jsonwebtoken';
import bcrypt from 'bcryptjs';
import { User } from '../db/interfaces';
+import { ManagerBase } from './ManagerBase';
-export class SecurityManager {
+export class SecurityManager extends ManagerBase {
saltRounds = Number(process.env.SALT_ROUNDS);
jwtSecretKey = process.env.JWT_SECRET_KEY || '';
@@ -20,8 +21,11 @@ export class SecurityManager {
return crypto.randomBytes(32).toString('hex');
}
- signJwt(data: any) {
- return jwt.sign(data, this.jwtSecretKey, { expiresIn: '3h' });
+ signJwt(data: any, longTerm: boolean = false): string {
+ const expiresIn: string = longTerm ? '7d' : '3h'
+ delete data.iat;
+ delete data.exp;
+ return jwt.sign(data, this.jwtSecretKey, { expiresIn });
}
// TODO: verificar esto
diff --git a/src/server/router/apiRouter.ts b/src/server/router/apiRouter.ts
index 997de0e..9ab229f 100644
--- a/src/server/router/apiRouter.ts
+++ b/src/server/router/apiRouter.ts
@@ -1,5 +1,6 @@
import { Request, Response, Router } from 'express';
import { AuthController } from '../controllers/AuthController';
+import { UpdaterController } from '../controllers/UpdaterController';
import adminRouter from './adminRouter';
import userRouter from './userRouter';
@@ -8,13 +9,19 @@ import gameRouter from './gameRouter';
export default function(): Router {
const router = Router();
const authController = new AuthController();
+ const updaterController = new UpdaterController();
router.get('/version', async function(req: Request, res: Response){
- res.send('1.0.0').end();
+ res.json({
+ app: 'domino',
+ version: '0.1.4-test',
+ }).end();
});
router.post('/auth/code', (req: Request, res: Response) => authController.twoFactorCodeAuthentication(req, res));
router.post('/login', (req: Request, res: Response) => authController.login(req, res));
+ router.post('/refresh', (req: Request, res: Response) => authController.refresh(req, res));
+ router.get('/updater/:target/:arch/:currentVersion', (req: Request, res: Response) => updaterController.checkUpdate(req, res));
router.use('/admin', adminRouter());
router.use('/user', userRouter());