Improve MineGeo UI and application flows
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 2m37s
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 2m37s
This commit is contained in:
38
lib/api.ts
38
lib/api.ts
@@ -24,6 +24,8 @@ import { jsonBody } from "./json-body";
|
||||
import { accountApi } from "./account-api";
|
||||
import { accountProfile } from "./profile";
|
||||
import { communityApi } from "./community-api";
|
||||
import { tournamentApi } from "./tournament-api";
|
||||
import { tournamentDiscordAfterResponse } from "./tournament-discord-server";
|
||||
import { multiplayerApi } from "./multiplayer-api";
|
||||
import { bugReportApi } from "./bug-report-api";
|
||||
import { moderatorUsersApi } from "./moderator-users-api";
|
||||
@@ -155,6 +157,20 @@ export async function handle(request: NextRequest, path: string[]) {
|
||||
return accountProfile(account);
|
||||
},
|
||||
});
|
||||
if (path[0] === "tournaments")
|
||||
return await tournamentApi(request, path, {
|
||||
db: admin(),
|
||||
account: async () => {
|
||||
const account = await user();
|
||||
if (account) await accountProfile(account);
|
||||
return account;
|
||||
},
|
||||
jsonBody,
|
||||
limit,
|
||||
mediaUrls,
|
||||
announce: tournamentDiscordAfterResponse,
|
||||
serverTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
});
|
||||
if (path[0] === "rooms")
|
||||
return await multiplayerApi(request, path, { jsonBody, limit });
|
||||
if (path[0] === "bug-reports")
|
||||
@@ -171,10 +187,17 @@ export async function handle(request: NextRequest, path: string[]) {
|
||||
const presets = required(
|
||||
await client
|
||||
.from("difficulty_presets")
|
||||
.select("id,name,seconds,zoom")
|
||||
.select(
|
||||
"id,name,seconds,zoom,pan,compass,coordinates,map_zoom,scoring",
|
||||
)
|
||||
.order("name", { ascending: true }),
|
||||
);
|
||||
return NextResponse.json({ presets });
|
||||
return NextResponse.json({
|
||||
presets: presets.map(({ map_zoom, ...preset }) => ({
|
||||
...preset,
|
||||
mapZoom: map_zoom,
|
||||
})),
|
||||
});
|
||||
}
|
||||
if (method === "POST") {
|
||||
const body = customDifficultySchema.parse(await jsonBody(request));
|
||||
@@ -182,13 +205,18 @@ export async function handle(request: NextRequest, path: string[]) {
|
||||
request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ||
|
||||
"unknown";
|
||||
await limit("difficulty-presets:" + hash(address), 8, 3600);
|
||||
const { mapZoom, ...fields } = body;
|
||||
const { data, error } = await client
|
||||
.from("difficulty_presets")
|
||||
.insert(body)
|
||||
.select("id,name,seconds,zoom")
|
||||
.insert({ ...fields, map_zoom: mapZoom })
|
||||
.select(
|
||||
"id,name,seconds,zoom,pan,compass,coordinates,map_zoom,scoring",
|
||||
)
|
||||
.single();
|
||||
checkDifficultyPresetError(error);
|
||||
return NextResponse.json({ preset: data });
|
||||
return NextResponse.json({
|
||||
preset: data ? { ...data, mapZoom: data.map_zoom } : null,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (path[0] === "health" && path.length === 1 && method === "GET") {
|
||||
|
||||
Reference in New Issue
Block a user