User stuff, config structure changes, web panel start, versioncheck fix, api start, recaptcha support for web panel
This commit is contained in:
@@ -4,5 +4,5 @@ import { APIUtils } from "../apiutils.ts";
|
||||
|
||||
export const route = APIUtils.createRouter('/api');
|
||||
|
||||
route.router.use(VersionCheckRoute.router);
|
||||
route.router.use(ConfigRoute.router);
|
||||
route.router.use(VersionCheckRoute.path, VersionCheckRoute.router);
|
||||
route.router.use(ConfigRoute.path, ConfigRoute.router);
|
||||
@@ -3,7 +3,7 @@ import { GameConfigs } from "../../data/config.ts";
|
||||
|
||||
export const route = APIUtils.createRouter('/config');
|
||||
|
||||
route.router.get('/v2', (rq, rs) => {
|
||||
route.router.get('/v2', (_rq, rs) => {
|
||||
const config = GameConfigs.getConfig();
|
||||
if (config == null) rs.sendStatus(500);
|
||||
else rs.json(config);
|
||||
|
||||
7
src/routes/api/gameconfigs.ts
Normal file
7
src/routes/api/gameconfigs.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { APIUtils } from "../../apiutils.ts";
|
||||
|
||||
export const route = APIUtils.createRouter('/gameconfigs');
|
||||
|
||||
route.router.get('/v1/all', (_rq, rs) => {
|
||||
rs.json([]);
|
||||
});
|
||||
@@ -4,20 +4,29 @@ export const route = APIUtils.createRouter('/versioncheck');
|
||||
|
||||
const validVersion = '20191120';
|
||||
|
||||
enum VersionStatus {
|
||||
UpdateRequired,
|
||||
ValidForMenu,
|
||||
ValidForPlay
|
||||
}
|
||||
type ValidVersionResponse = {
|
||||
ValidVersion: boolean
|
||||
VersionStatus: VersionStatus
|
||||
}
|
||||
|
||||
route.router.get('/v3', (rq, rs) => {
|
||||
route.router.get('/v4', (rq, rs) => {
|
||||
const requestedVer = rq.query['v'];
|
||||
if (typeof requestedVer !== 'string' || requestedVer !== validVersion) {
|
||||
if (typeof requestedVer == 'undefined') {
|
||||
rs.statusCode = 400;
|
||||
rs.json(APIUtils.genericResponseFormat(true, 'One or more query parameters were not found.'));
|
||||
}
|
||||
else if (requestedVer !== validVersion) {
|
||||
const res: ValidVersionResponse = {
|
||||
ValidVersion: false
|
||||
VersionStatus: VersionStatus.UpdateRequired
|
||||
}
|
||||
rs.json(res);
|
||||
} else {
|
||||
const res: ValidVersionResponse = {
|
||||
ValidVersion: true
|
||||
VersionStatus: VersionStatus.ValidForPlay
|
||||
}
|
||||
rs.json(res);
|
||||
}
|
||||
|
||||
@@ -20,19 +20,18 @@ type NameserverHosts = {
|
||||
Leaderboard: string
|
||||
}
|
||||
|
||||
const path = `${protocol}://${config.web.nameserverHost}`;
|
||||
const nameserver: NameserverHosts = {
|
||||
Auth: path,
|
||||
API: path,
|
||||
WWW: path,
|
||||
Notifications: path,
|
||||
Images: path,
|
||||
CDN: path,
|
||||
Commerce: path,
|
||||
Matchmaking: path,
|
||||
Storage: path,
|
||||
Chat: path,
|
||||
Leaderboard: path
|
||||
Auth: `${protocol}://${config.web.nameserverHost}/auth`,
|
||||
API: `${protocol}://${config.web.nameserverHost}`,
|
||||
WWW: `${protocol}://${config.web.nameserverHost}`,
|
||||
Notifications: `${protocol}://${config.web.nameserverHost}/notify`,
|
||||
Images: `${protocol}://${config.web.nameserverHost}/img`,
|
||||
CDN: `${protocol}://${config.web.nameserverHost}/cdn`,
|
||||
Commerce: `${protocol}://${config.web.nameserverHost}/commerce`,
|
||||
Matchmaking: `${protocol}://${config.web.nameserverHost}/match`,
|
||||
Storage: `${protocol}://${config.web.nameserverHost}/storage`,
|
||||
Chat: `${protocol}://${config.web.nameserverHost}/chat`,
|
||||
Leaderboard: `${protocol}://${config.web.nameserverHost}/leaderboard`
|
||||
}
|
||||
|
||||
route.router.get('*', (_rq, rs) => {
|
||||
|
||||
53
src/routes/user.ts
Normal file
53
src/routes/user.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { APIUtils, getSrcIpDefault } from "../apiutils.ts";
|
||||
// @ts-types = "npm:@types/express"
|
||||
import express from "express";
|
||||
import { User } from "../data/users.ts";
|
||||
import Recaptcha from "../data/recaptcha.ts";
|
||||
|
||||
export const route = APIUtils.createRouter('/user');
|
||||
|
||||
type CreateUserBody = {
|
||||
username: string,
|
||||
password: string,
|
||||
recaptcha: string
|
||||
}
|
||||
|
||||
type CreatedUserResponse = {
|
||||
uuid: string,
|
||||
backupcode: string
|
||||
}
|
||||
|
||||
const rateLimit = new APIUtils.RateLimiter(10, 1);
|
||||
|
||||
route.router.post('/create',
|
||||
|
||||
rateLimit.middle(),
|
||||
express.json(),
|
||||
APIUtils.checkBodyTypes<CreateUserBody>({ username: "test", password: "test", recaptcha: "test" }),
|
||||
|
||||
async (rq, rs) => {
|
||||
const body = rq.body as CreateUserBody;
|
||||
|
||||
const recaptchaStatus = await Recaptcha.siteVerify(body.recaptcha, getSrcIpDefault(rq));
|
||||
if (recaptchaStatus) {
|
||||
const userinit = await User.init({ username: body.username, password: body.password });
|
||||
if (userinit == null) {
|
||||
rs.statusCode = 400;
|
||||
rs.json(APIUtils.genericResponseFormat(true, "Username is already taken"));
|
||||
} else {
|
||||
|
||||
const res: CreatedUserResponse = {
|
||||
uuid: userinit.user.getUuid(),
|
||||
backupcode: userinit.backupcode
|
||||
}
|
||||
rs.json(APIUtils.genericResponseFormat(false, "User created successfully", res));
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
rs.statusCode = 400;
|
||||
rs.json(APIUtils.genericResponseFormat(true, "ReCAPTCHA error"));
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
Reference in New Issue
Block a user