mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 15:48:23 -05:00
Move app to apps/web-react in pnpm workspace layout
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { refreshApiTokensCache } from "~/features/api-public/api-public-utils.server";
|
||||
import { refreshBannedCache } from "~/features/ban/core/banned.server";
|
||||
import { clearParticipationInfoMap } from "~/features/front-page/core/ShowcaseTournaments.server";
|
||||
import { refreshSendouQInstance } from "~/features/sendouq/core/SendouQ.server";
|
||||
import { clearSeasonSkillsCache } from "~/features/sendouq/q-utils.server";
|
||||
import {
|
||||
clearAllTournamentDataCache,
|
||||
refreshRunningTournaments,
|
||||
} from "~/features/tournament-bracket/core/Tournament.server";
|
||||
import { refreshTentativeTiersCache } from "~/features/tournament-organization/core/tentativeTiers.server";
|
||||
import { clearUserCardCache } from "~/features/user-card/UserCardRepository.server";
|
||||
import { cache } from "~/utils/cache.server";
|
||||
|
||||
/**
|
||||
* Clears and refreshes every in-process cache, so the server serves what is in
|
||||
* the database right now. E2E workers call this (via the route) after writing
|
||||
* test data straight into the database file.
|
||||
*/
|
||||
export async function refreshCaches() {
|
||||
clearAllTournamentDataCache();
|
||||
clearParticipationInfoMap();
|
||||
clearSeasonSkillsCache();
|
||||
clearUserCardCache();
|
||||
cache.clear();
|
||||
await refreshBannedCache();
|
||||
await refreshSendouQInstance();
|
||||
await refreshTentativeTiersCache();
|
||||
await refreshApiTokensCache();
|
||||
await refreshRunningTournaments();
|
||||
}
|
||||
13
apps/web-react/app/features/api-private/routes/end-season.ts
Normal file
13
apps/web-react/app/features/api-private/routes/end-season.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { ActionFunction } from "react-router";
|
||||
import { DANGEROUS_CAN_ACCESS_DEV_CONTROLS } from "~/features/admin/core/dev-controls";
|
||||
import * as Seasons from "~/features/mmr/core/Seasons";
|
||||
|
||||
export const action: ActionFunction = async () => {
|
||||
if (!DANGEROUS_CAN_ACCESS_DEV_CONTROLS) {
|
||||
throw new Response(null, { status: 400 });
|
||||
}
|
||||
|
||||
Seasons.DANGEROUS_setSeasonEndedOverride(true);
|
||||
|
||||
return Response.json(null);
|
||||
};
|
||||
23
apps/web-react/app/features/api-private/routes/patrons.ts
Normal file
23
apps/web-react/app/features/api-private/routes/patrons.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { ActionFunction, LoaderFunctionArgs } from "react-router";
|
||||
import * as UserRepository from "~/features/user-page/UserRepository.server";
|
||||
import { updatePatreonData } from "~/modules/patreon";
|
||||
import {
|
||||
canAccessLohiEndpoint,
|
||||
unauthorizedIfFalsy,
|
||||
} from "~/utils/remix.server";
|
||||
|
||||
export const action: ActionFunction = async ({ request }) => {
|
||||
if (!canAccessLohiEndpoint(request)) {
|
||||
throw new Response("Not authorized", { status: 403 });
|
||||
}
|
||||
|
||||
await updatePatreonData();
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const loader = ({ request }: LoaderFunctionArgs) => {
|
||||
unauthorizedIfFalsy(canAccessLohiEndpoint(request));
|
||||
|
||||
return UserRepository.findAllPatrons();
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { ActionFunctionArgs } from "react-router";
|
||||
import { DANGEROUS_CAN_ACCESS_DEV_CONTROLS } from "~/features/admin/core/dev-controls";
|
||||
import * as Seasons from "~/features/mmr/core/Seasons";
|
||||
import { refreshCaches } from "../core/refresh-caches.server";
|
||||
|
||||
export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
if (!DANGEROUS_CAN_ACCESS_DEV_CONTROLS) {
|
||||
throw new Response(null, { status: 400 });
|
||||
}
|
||||
|
||||
// only the start of an e2e test asks for this. mid-test cache flushes must
|
||||
// leave what the running test set up alone
|
||||
if (await wantsDevOverridesReset(request)) {
|
||||
Seasons.DANGEROUS_setSeasonEndedOverride(false);
|
||||
}
|
||||
|
||||
await refreshCaches();
|
||||
|
||||
return Response.json(null);
|
||||
};
|
||||
|
||||
async function wantsDevOverridesReset(request: Request) {
|
||||
if (!request.headers.get("content-type")) return false;
|
||||
|
||||
return (await request.formData()).get("resetDevOverrides") === "true";
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { ActionFunctionArgs } from "react-router";
|
||||
import { DANGEROUS_CAN_ACCESS_DEV_CONTROLS } from "~/features/admin/core/dev-controls";
|
||||
|
||||
export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
if (!DANGEROUS_CAN_ACCESS_DEV_CONTROLS) {
|
||||
throw new Response(null, { status: 400 });
|
||||
}
|
||||
|
||||
const routineName = (await request.formData()).get("name");
|
||||
|
||||
const { everyHourAt00, everyHourAt30, daily, everyTwoMinutes } = await import(
|
||||
"~/routines/list.server"
|
||||
);
|
||||
const routine = [
|
||||
...everyHourAt00,
|
||||
...everyHourAt30,
|
||||
...daily,
|
||||
...everyTwoMinutes,
|
||||
].find((routine) => routine.name === routineName);
|
||||
|
||||
if (!routine) {
|
||||
throw new Response(`Unknown routine: ${routineName}`, { status: 400 });
|
||||
}
|
||||
|
||||
await routine.run();
|
||||
|
||||
return Response.json(null);
|
||||
};
|
||||
16
apps/web-react/app/features/api-private/routes/seed.ts
Normal file
16
apps/web-react/app/features/api-private/routes/seed.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { ActionFunction } from "react-router";
|
||||
import { DANGEROUS_CAN_ACCESS_DEV_CONTROLS } from "~/features/admin/core/dev-controls";
|
||||
import { refreshCaches } from "../core/refresh-caches.server";
|
||||
|
||||
export const action: ActionFunction = async () => {
|
||||
if (!DANGEROUS_CAN_ACCESS_DEV_CONTROLS) {
|
||||
throw new Response(null, { status: 400 });
|
||||
}
|
||||
|
||||
const { seed } = await import("~/db/seed");
|
||||
await seed();
|
||||
|
||||
await refreshCaches();
|
||||
|
||||
return Response.json(null);
|
||||
};
|
||||
14
apps/web-react/app/features/api-private/routes/users.ts
Normal file
14
apps/web-react/app/features/api-private/routes/users.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { ActionFunction } from "react-router";
|
||||
import * as UserRepository from "~/features/user-page/UserRepository.server";
|
||||
import { canAccessLohiEndpoint } from "~/utils/remix.server";
|
||||
|
||||
export const action: ActionFunction = async ({ request }) => {
|
||||
if (!canAccessLohiEndpoint(request)) {
|
||||
throw new Response(null, { status: 403 });
|
||||
}
|
||||
|
||||
// input untyped but we trust Lohi to give us correctly shaped request here
|
||||
await UserRepository.updateMany(await request.json());
|
||||
|
||||
return null;
|
||||
};
|
||||
Reference in New Issue
Block a user