v.0.1.4
This commit is contained in:
parent
6da023d12a
commit
0329e84548
8
.hmrc
8
.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": [],
|
||||
|
@ -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
|
||||
|
@ -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": [],
|
||||
|
@ -1,5 +1,6 @@
|
||||
<h1>Changelog</h1>
|
||||
<p>All notable changes to this project will be documented in this file.</p>
|
||||
<h2>0.1.4 - 2024-07-20</h2>
|
||||
<h2>0.1.3 - 2024-07-18</h2>
|
||||
<h3>Added</h3>
|
||||
<ul>
|
||||
|
@ -1,22 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Domino Tiles</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="domino" data-top="1" data-bottom="5">
|
||||
<div class="half top"></div>
|
||||
<div class="half bottom"></div>
|
||||
</div>
|
||||
|
||||
<div class="domino" data-top="1" data-bottom="5">
|
||||
<div class="half top"></div>
|
||||
<div class="half bottom"></div>
|
||||
</div>
|
||||
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -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];
|
||||
}
|
@ -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%);
|
||||
}
|
@ -31,17 +31,35 @@ export class AuthController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
_jwtSignUser(user: User | null, res: Response) {
|
||||
async refresh(req: Request, res: Response): Promise<void> {
|
||||
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' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
33
src/server/controllers/UpdaterController.ts
Normal file
33
src/server/controllers/UpdaterController.ts
Normal file
@ -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<any> {
|
||||
this.logger.info('Checking for updates');
|
||||
return res.json(json).status(200).end();
|
||||
|
||||
return res.status(204).end();
|
||||
}
|
||||
|
||||
// async startMatchSession(data: any): Promise<any> {
|
||||
// const response = await this.sessionManager.startSession(data);
|
||||
// return response;
|
||||
// }
|
||||
|
||||
// async joinMatchSession(data: any, socketId: string): Promise<any> {
|
||||
// const response = await this.sessionManager.joinSession(data, socketId);
|
||||
// return response;
|
||||
// }
|
||||
}
|
@ -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'));
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user