Improve MineGeo interface and functionality

This commit is contained in:
2026-10-06 19:24:41 +05:00
parent 7404f1dc1c
commit 233e4d57f0
67 changed files with 3053 additions and 643 deletions

View File

@@ -16,6 +16,8 @@ import { ServiceError, checkServiceError } from "./service-error";
import { requestOrigin, verifyOrigin } from "./request-origin";
import { accountApi } from "./account-api";
import { contributionCutoff, reportSchema } from "../shared/moderation";
import { siteSettingsSchema } from "../shared/site-settings";
import { getSiteSettings } from "./site-settings";
const hash = (value: string) =>
createHash("sha256").update(value).digest("hex");
const idSchema = z.string().uuid();
@@ -109,6 +111,11 @@ export async function handle(request: NextRequest, path: string[]) {
return await accountApi(request, path, { jsonBody, limit });
const client = admin(),
method = request.method;
if (path[0] === "site-settings" && path.length === 1 && method === "GET") {
return NextResponse.json(await getSiteSettings(), {
headers: { "Cache-Control": "no-store" },
});
}
if (path[0] === "health" && path.length === 1 && method === "GET") {
const { error } = await client
.from("catalog_servers")
@@ -782,6 +789,15 @@ export async function handle(request: NextRequest, path: string[]) {
}
if (path[0] === "moderation") {
const reviewer = await moderator(request);
if (path[1] === "settings" && path.length === 2 && method === "PATCH") {
const body = siteSettingsSchema.parse(await jsonBody(request));
const enabled = required(await client.rpc("set_beta_badge", {
p_reviewer: reviewer, p_enabled: body.betaBadgeEnabled,
}));
return NextResponse.json({ betaBadgeEnabled: enabled }, {
headers: { "Cache-Control": "no-store" },
});
}
if (path[1] === "appeals" && path.length === 3 && method === "POST") {
const body = z
.object({

31
lib/i18n.ts Normal file
View File

@@ -0,0 +1,31 @@
import "server-only";
import { cache } from "react";
import { cookies, headers } from "next/headers";
import {
detectLocale,
languageCookie,
localeTag,
resolveLocale,
translator,
type LanguagePreference,
} from "@/shared/i18n";
export const getI18n = cache(async () => {
const [jar, requestHeaders] = await Promise.all([cookies(), headers()]);
const preference = jar.get(languageCookie)?.value;
const locale = resolveLocale(
preference,
requestHeaders.get("accept-language"),
);
const languagePreference: LanguagePreference =
preference === "en" || preference === "ru" ? preference : "auto";
return {
locale,
preference: languagePreference,
detectedLocale: detectLocale(requestHeaders.get("accept-language")),
t: translator(locale),
formatNumber: (value: number) => value.toLocaleString(localeTag(locale)),
formatDate: (value: string) =>
new Date(value).toLocaleDateString(localeTag(locale)),
};
});

24
lib/site-settings.ts Normal file
View File

@@ -0,0 +1,24 @@
import "server-only";
import { cache } from "react";
import { admin, required } from "./supabase";
import { defaultSiteSettings, type SiteSettings } from "@/shared/site-settings";
export const getSiteSettings = cache(async (): Promise<SiteSettings> => {
const row = required(
await admin()
.from("site_settings")
.select("beta_badge_enabled")
.eq("id", true)
.single(),
);
return { betaBadgeEnabled: row.beta_badge_enabled };
});
export async function initialSiteSettings(): Promise<SiteSettings> {
try {
return await getSiteSettings();
} catch {
// A settings outage must not block the site from rendering.
return defaultSiteSettings;
}
}