mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: removed server
This commit is contained in:
1 parent
eb24f49766
commit
38f912dc0a
17 files changed
+14
-181
No files matched your search
@@ -21,7 +21,7 @@ import addRegionChoices from '../core/discord/addRegionChoices';
|
||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
|
||||
import { octokit } from '../core/express/octokit';
|
||||
import { octokit } from '../core/github/octokit';
|
||||
import throwError from '../core/node/throwError';
|
||||
import { CommandRegistryRaw } from '../events/interactionCreate';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RatingsInfo } from '../../commands/ratings';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { DATABASE_REPO } from '../database/getMidnightLeaderboard';
|
||||
import { octokit } from '../express/octokit';
|
||||
import { octokit } from '../github/octokit';
|
||||
import throwError from '../node/throwError';
|
||||
|
||||
export default async function getArchivedRatingsInfo(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BlitzkriegRatingsLeaderboard } from '../../../scripts/buildRatingsLeaderboard';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { octokit } from '../express/octokit';
|
||||
import { octokit } from '../github/octokit';
|
||||
|
||||
export const DATABASE_REPO = { owner: 'tresabhi', repo: 'blitzkrieg-db' };
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ButtonInteraction, CacheType } from 'discord.js';
|
||||
import { CYCLIC_API } from '../../constants/cyclic';
|
||||
import { Region } from '../../constants/regions';
|
||||
import resolvePeriodFromURL from '../express/resolvePeriodFromURL';
|
||||
import resolvePeriodFromURL from './resolvePeriodFromURL';
|
||||
|
||||
export default function resolvePeriodFromButton(
|
||||
server: Region,
|
||||
|
||||
@@ -2,11 +2,11 @@ import { Region } from '../../constants/regions';
|
||||
import getPeriodNow from '../blitzstars/getPeriodNow';
|
||||
import getPeriodStart from '../blitzstars/getPeriodStart';
|
||||
import getTimeDaysAgo from '../blitzstars/getTimeDaysAgo';
|
||||
import { PeriodSize, PeriodType } from '../discord/addPeriodSubCommands';
|
||||
import { PeriodSize, PeriodType } from './addPeriodSubCommands';
|
||||
import {
|
||||
ResolvedPeriod,
|
||||
getPeriodOptionName,
|
||||
} from '../discord/resolvePeriodFromCommand';
|
||||
} from './resolvePeriodFromCommand';
|
||||
|
||||
export default function resolvePeriodFromURL(
|
||||
server: Region,
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ButtonInteraction, CacheType } from 'discord.js';
|
||||
import { CYCLIC_API } from '../../constants/cyclic';
|
||||
import resolvePlayerFromURL from '../express/resolvePlayerFromURL';
|
||||
import resolvePlayerFromURL from './resolvePlayerFromURL';
|
||||
|
||||
export default async function resolvePlayerFromButton(
|
||||
interaction: ButtonInteraction<CacheType>,
|
||||
|
||||
File renamed without changes.
@@ -1,11 +0,0 @@
|
||||
import { RouteReturnable } from '../../server';
|
||||
import jsxToSvg from '../node/jsxToSvg';
|
||||
|
||||
export default async function normalizeRouteReturnable(
|
||||
returnable: RouteReturnable,
|
||||
) {
|
||||
const awaitedReturnable = await returnable;
|
||||
const svg = await jsxToSvg(awaitedReturnable);
|
||||
|
||||
return svg;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { Request } from 'express';
|
||||
import { CYCLIC_API } from '../../constants/cyclic';
|
||||
import { Region } from '../../constants/regions';
|
||||
import resolvePeriodFromURL from './resolvePeriodFromURL';
|
||||
|
||||
export default function resolvePeriodFromRequest(
|
||||
server: Region,
|
||||
request: Request,
|
||||
) {
|
||||
return resolvePeriodFromURL(server, `${CYCLIC_API}${request.url}`);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Request } from 'express';
|
||||
import { CYCLIC_API } from '../../constants/cyclic';
|
||||
import resolvePlayerFromURL from './resolvePlayerFromURL';
|
||||
|
||||
export default function resolvePlayerFromRequest(request: Request) {
|
||||
return resolvePlayerFromURL(`${CYCLIC_API}${request.originalUrl}`);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
export default function withAutoRefresh(svg: string, refreshAfter: number) {
|
||||
return `
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, ${refreshAfter});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
${svg}
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
File renamed without changes.
@@ -1,23 +0,0 @@
|
||||
import resolvePeriodFromRequest from '../core/express/resolvePeriodFromRequest';
|
||||
import resolvePlayerFromRequest from '../core/express/resolvePlayerFromRequest';
|
||||
import stats, { StatType } from '../renderers/stats';
|
||||
import { RouteRegistry } from '../server';
|
||||
|
||||
export const statsRoute: RouteRegistry = {
|
||||
route: '/stats/:type/:period',
|
||||
inProduction: true,
|
||||
|
||||
async handler(req) {
|
||||
const type = req.params.type as StatType;
|
||||
const player = resolvePlayerFromRequest(req);
|
||||
const period = resolvePeriodFromRequest(player.region, req);
|
||||
|
||||
return await stats(
|
||||
type,
|
||||
period,
|
||||
player,
|
||||
parseInt(req.query.tankId as string),
|
||||
true,
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
import resolvePlayerFromRequest from '../core/express/resolvePlayerFromRequest';
|
||||
import today from '../renderers/today';
|
||||
import { RouteRegistry } from '../server';
|
||||
|
||||
export const todayRoute: RouteRegistry = {
|
||||
route: '/today',
|
||||
inProduction: true,
|
||||
|
||||
async handler(req) {
|
||||
const player = resolvePlayerFromRequest(req);
|
||||
|
||||
return await today(
|
||||
player,
|
||||
req.query.cutoff ? parseInt(req.query.cutoff as string) : undefined,
|
||||
req.query.maximized ? parseInt(req.query.maximized as string) : undefined,
|
||||
req.query['show-total'] ? req.query['show-total'] === 'true' : undefined,
|
||||
true,
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
import express, { Request, Response } from 'express';
|
||||
import normalizeRouteReturnable from './core/express/normalizeRouteReturnable';
|
||||
import withAutoRefresh from './core/express/withAutoRefresh';
|
||||
import { Registry } from './events/interactionCreate';
|
||||
import { statsRoute } from './routes/stats';
|
||||
import { todayRoute } from './routes/today';
|
||||
|
||||
export type RouteReturnable = JSX.Element | Promise<JSX.Element>;
|
||||
|
||||
export interface RouteRegistry<HandlesInteraction extends boolean = false>
|
||||
extends Registry {
|
||||
route: string;
|
||||
handlesInteraction?: HandlesInteraction;
|
||||
|
||||
handler: (
|
||||
req: Request,
|
||||
res: Response,
|
||||
) => HandlesInteraction extends true ? void : RouteReturnable;
|
||||
}
|
||||
|
||||
const app = express();
|
||||
|
||||
([statsRoute, todayRoute] as RouteRegistry[]).forEach((registry) => {
|
||||
app.get(registry.route, async (req, res) => {
|
||||
console.log(req.originalUrl);
|
||||
|
||||
const returnable = registry.handler(req, res);
|
||||
if (registry.handlesInteraction) return;
|
||||
|
||||
res.send(
|
||||
withAutoRefresh(await normalizeRouteReturnable(returnable), 30 * 1000),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(process.env.PORT ?? 3000);
|
||||
Reference in new issue
Block a user