mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: split up some more
This commit is contained in:
1 parent
7c6f381bbe
commit
2c9a7f9a99
24 files changed
+36
-37
No files matched your search
@@ -1,10 +0,0 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { NextResponse } from 'next/server';
|
||||
import getRatingInfo from '../../../../../../core/blitz/getRatingInfo';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { region: Region } },
|
||||
) {
|
||||
return NextResponse.json(await getRatingInfo(params.region));
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getRatingLeague } from '../../../../../../../core/blitz/getRatingLeague';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { region: Region; league: number } },
|
||||
) {
|
||||
return NextResponse.json(
|
||||
await getRatingLeague(params.region, params.league, true),
|
||||
);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { Region } from '@blitzkit/core';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { searchCurrentRatingPlayers } from '../../../../../../../core/blitz/searchCurrentRatingPlayers';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { region: Region; username: string } },
|
||||
) {
|
||||
return NextResponse.json(
|
||||
await searchCurrentRatingPlayers(params.region, params.username),
|
||||
);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { assertSecret } from '@blitzkit/core';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { code: string } },
|
||||
) {
|
||||
const response = await fetch(
|
||||
`https://www.patreon.com/api/oauth2/token?code=${
|
||||
params.code
|
||||
}&grant_type=authorization_code&client_id=${assertSecret(
|
||||
process.env.NEXT_PUBLIC_PATREON_CLIENT_ID,
|
||||
)}&client_secret=${assertSecret(
|
||||
process.env.PATREON_CLIENT_SECRET,
|
||||
)}&redirect_uri=${assertSecret(
|
||||
process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI,
|
||||
)}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
},
|
||||
);
|
||||
const json = await response.json();
|
||||
|
||||
return NextResponse.json(json);
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
import { assertSecret } from '@blitzkit/core';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
interface PatreonMembershipResponse {
|
||||
data: {
|
||||
attributes: unknown;
|
||||
id: `${number}`;
|
||||
relationships: {
|
||||
memberships: {
|
||||
data: {
|
||||
id: string; // uuid
|
||||
type: 'member';
|
||||
}[];
|
||||
};
|
||||
};
|
||||
type: 'user';
|
||||
};
|
||||
included: (
|
||||
| {
|
||||
attributes: {
|
||||
patron_status:
|
||||
| 'active_patron'
|
||||
| 'declined_patron'
|
||||
| 'former_patron'
|
||||
| null; // null = never a paid member
|
||||
};
|
||||
id: string; // uuid
|
||||
relationships: {
|
||||
campaign: {
|
||||
data: {
|
||||
id: `${number}`; // id of my campaign to check against
|
||||
type: 'campaign';
|
||||
};
|
||||
links: {
|
||||
related: string; // url
|
||||
};
|
||||
};
|
||||
};
|
||||
type: 'member';
|
||||
}
|
||||
| {
|
||||
attributes: {};
|
||||
id: `${number}`;
|
||||
type: 'campaign'; // ignore this discriminator
|
||||
}
|
||||
)[];
|
||||
links: {
|
||||
self: 'https://www.patreon.com/api/oauth2/v2/user/124201389';
|
||||
};
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { token: string } },
|
||||
) {
|
||||
const response = await fetch(
|
||||
encodeURI(
|
||||
'https://www.patreon.com/api/oauth2/v2/identity?include=memberships.campaign&fields[member]=patron_status',
|
||||
),
|
||||
{ headers: { Authorization: `Bearer ${params.token}` } },
|
||||
);
|
||||
|
||||
if (!response.ok) return NextResponse.json(false);
|
||||
|
||||
const json = (await response.json()) as PatreonMembershipResponse;
|
||||
|
||||
return NextResponse.json(
|
||||
json.included.some(
|
||||
(item) =>
|
||||
item.type === 'member' &&
|
||||
item.relationships.campaign.data.id ===
|
||||
assertSecret(process.env.PATREON_CAMPAIGN_ID) &&
|
||||
item.attributes.patron_status === 'active_patron',
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { assertSecret } from '@blitzkit/core';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { token: string } },
|
||||
) {
|
||||
const response = await fetch(
|
||||
`https://www.patreon.com/api/oauth2/token?grant_type=refresh_token&refresh_token=${
|
||||
params.token
|
||||
}&client_id=${assertSecret(
|
||||
process.env.NEXT_PUBLIC_PATREON_CLIENT_ID,
|
||||
)}&client_secret=${assertSecret(process.env.PATREON_CLIENT_SECRET)}`,
|
||||
{ method: 'POST' },
|
||||
);
|
||||
const json = await response.json();
|
||||
|
||||
return NextResponse.json(json);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { blitzStarsTankAverages } from '@blitzkit/core/src/blitzstars/tankAverages';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(await blitzStarsTankAverages);
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
import { tankDefinitions, usersDatabase } from '@blitzkit/core';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { isValidBlitzId } from '../../../../../core/blitz/isValidBlitzId';
|
||||
import {
|
||||
BlitzkitResponse,
|
||||
BlitzkitResponseError,
|
||||
} from '../../../../../hooks/useTankVotes';
|
||||
import { TankVoteCategory } from '../cast/route';
|
||||
|
||||
export interface TankVotes {
|
||||
categories: Record<TankVoteCategory, number | null>;
|
||||
votes: number;
|
||||
last_updated?: number;
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } },
|
||||
) {
|
||||
const id = Number(params.id);
|
||||
const awaitedTankDefinitions = await tankDefinitions;
|
||||
|
||||
if (isNaN(id) || !awaitedTankDefinitions[id]) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
error: 'INVALID_TANK_ID',
|
||||
} satisfies BlitzkitResponseError);
|
||||
}
|
||||
|
||||
const blitzIdString = request.nextUrl.searchParams.get('player');
|
||||
const blitzId = Number(blitzIdString);
|
||||
const blitzToken = request.nextUrl.searchParams.get('token');
|
||||
|
||||
if ((blitzIdString === null) !== (blitzToken === null)) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
error: 'UNDEFINED_TOKEN_OR_PLAYER_ID',
|
||||
} satisfies BlitzkitResponseError);
|
||||
}
|
||||
|
||||
if (
|
||||
blitzIdString !== null &&
|
||||
(!(await isValidBlitzId(blitzId, blitzToken ?? undefined)) ||
|
||||
isNaN(blitzId))
|
||||
) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
error: 'INVALID_TOKEN_OR_PLAYER_ID',
|
||||
} satisfies BlitzkitResponseError);
|
||||
}
|
||||
|
||||
try {
|
||||
const aggregation = await usersDatabase.tankVote.aggregate({
|
||||
where: { id },
|
||||
_count: { id: true },
|
||||
_avg: {
|
||||
easiness: true,
|
||||
firepower: true,
|
||||
maneuverability: true,
|
||||
survivability: true,
|
||||
},
|
||||
});
|
||||
const userVote = await usersDatabase.tankVote.findUnique({
|
||||
where: { id, user_blitz_id: blitzId },
|
||||
select: { last_updated: true },
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
status: 'ok',
|
||||
data: {
|
||||
categories: aggregation._avg,
|
||||
votes: aggregation._count.id,
|
||||
last_updated: userVote?.last_updated.getTime(),
|
||||
},
|
||||
} satisfies BlitzkitResponse<TankVotes>);
|
||||
} catch (message) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
error: 'DATABASE_ERROR',
|
||||
message,
|
||||
} satisfies BlitzkitResponseError);
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
import { tankDefinitions, usersDatabase } from '@blitzkit/core';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { isValidBlitzId } from '../../../../../core/blitz/isValidBlitzId';
|
||||
import {
|
||||
BlitzkitResponse,
|
||||
BlitzkitResponseError,
|
||||
} from '../../../../../hooks/useTankVotes';
|
||||
import { StarsInt } from '../../../../tools/tankopedia/[id]/components/Model/MetaSection/components/Stars';
|
||||
|
||||
export const TANK_VOTE_CATEGORIES = [
|
||||
'easiness',
|
||||
'firepower',
|
||||
'maneuverability',
|
||||
'survivability',
|
||||
];
|
||||
|
||||
export type TankVoteCategory = (typeof TANK_VOTE_CATEGORIES)[number];
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } },
|
||||
) {
|
||||
const tankId = Number(params.id);
|
||||
const awaitedTankDefinitions = await tankDefinitions;
|
||||
|
||||
if (isNaN(tankId) || !awaitedTankDefinitions[tankId]) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
error: 'INVALID_TANK_ID',
|
||||
} satisfies BlitzkitResponseError);
|
||||
}
|
||||
|
||||
const blitzIdString = request.nextUrl.searchParams.get('player');
|
||||
const blitzId = Number(blitzIdString);
|
||||
const blitzToken = request.nextUrl.searchParams.get('token');
|
||||
|
||||
if (blitzIdString === null || blitzToken === null) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
error: 'UNDEFINED_TOKEN_OR_PLAYER_ID',
|
||||
} satisfies BlitzkitResponseError);
|
||||
}
|
||||
|
||||
if (
|
||||
blitzIdString !== null &&
|
||||
(!(await isValidBlitzId(blitzId, blitzToken ?? undefined)) ||
|
||||
isNaN(blitzId))
|
||||
) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
error: 'INVALID_TOKEN_OR_PLAYER_ID',
|
||||
} satisfies BlitzkitResponseError);
|
||||
}
|
||||
|
||||
const votes: Partial<Record<TankVoteCategory, StarsInt>> = {};
|
||||
let recognizedVoteCategories = 0;
|
||||
|
||||
for (const category of TANK_VOTE_CATEGORIES) {
|
||||
const voteRaw = request.nextUrl.searchParams.get(category);
|
||||
|
||||
if (voteRaw === null) continue;
|
||||
|
||||
const vote = Number(voteRaw);
|
||||
|
||||
if (isNaN(vote) || !Number.isInteger(vote) || vote < 1 || vote > 5) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
error: 'INVALID_VOTE',
|
||||
} satisfies BlitzkitResponseError);
|
||||
}
|
||||
|
||||
votes[category] = vote as StarsInt;
|
||||
recognizedVoteCategories++;
|
||||
}
|
||||
|
||||
if (recognizedVoteCategories === 0) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
error: 'NO_VOTES',
|
||||
} satisfies BlitzkitResponseError);
|
||||
}
|
||||
|
||||
try {
|
||||
await usersDatabase.user.upsert({
|
||||
where: { blitz_id: blitzId },
|
||||
update: {
|
||||
last_used: new Date(),
|
||||
tank_votes: {
|
||||
upsert: {
|
||||
where: { id: tankId },
|
||||
update: { ...votes, last_updated: new Date() },
|
||||
create: { ...votes, id: tankId, last_updated: new Date() },
|
||||
},
|
||||
},
|
||||
},
|
||||
create: {
|
||||
blitz_id: blitzId,
|
||||
last_used: new Date(),
|
||||
tank_votes: {
|
||||
create: { ...votes, id: tankId, last_updated: new Date() },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
status: 'ok',
|
||||
data: undefined,
|
||||
} satisfies BlitzkitResponse);
|
||||
} catch (message) {
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
error: 'DATABASE_ERROR',
|
||||
message,
|
||||
} satisfies BlitzkitResponseError);
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,12 @@
|
||||
import {
|
||||
FIRST_MINIMAL_ARCHIVED_RATING_SEASON,
|
||||
LEAGUES,
|
||||
RatingInfo,
|
||||
Region,
|
||||
REGIONS,
|
||||
UNLOCALIZED_REGION_NAMES,
|
||||
Var,
|
||||
} from '@blitzkit/core';
|
||||
import { RatingInfo } from '@blitzkit/core/src/blitz/leagues';
|
||||
import { RatingPlayer } from '@blitzkit/core/src/statistics/deltaBkrlBlitzStats';
|
||||
import { blackA, orangeDark } from '@radix-ui/colors';
|
||||
import { MagnifyingGlassIcon } from '@radix-ui/react-icons';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Region, asset } from '@blitzkit/core';
|
||||
import { RatingInfo } from '@blitzkit/core/src/blitz/leagues';
|
||||
import { RatingInfo, Region, asset } from '@blitzkit/core';
|
||||
import { superDecompress } from '@blitzkit/core/src/blitzkit/superDecompress';
|
||||
|
||||
const cache: Record<
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
declare module '*.glsl' {
|
||||
const value: string;
|
||||
export default value;
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
declare module '*.proto' {
|
||||
const value: string;
|
||||
export default value;
|
||||
}
|
||||
Reference in new issue
Block a user