desloppify: code health overhaul plus abuse hardening (140 green, strict 87.2)
Honest baseline after removing 45 gaming suppressions. Structural: lib/game plus root hooks extraction, CORS origin echo, DEV_ORIGINS layering. Fixes: error-cause binding, discord 5xx split, null-cache guard, co-located tests, rejecting-fetch coverage, naming and typing cleanup, socket controller, cache bound, cascade helpers, latch resets. Hardening: per-IP rate limit on API routes, deterministic-miss UX, retry cooldown plus cap. Suite 140 green, build plus lint clean.
This commit is contained in:
78 files changed
+4908
-1430
No files matched your search
@@ -49,11 +49,12 @@
|
||||
"loadError": "Spieldaten konnten nicht geladen werden.",
|
||||
"retry": "Erneut versuchen",
|
||||
"partialFail": "Einige Daten konnten nicht geladen werden.",
|
||||
"noGameData": "Für diese App wurden keine Spieldaten gefunden.",
|
||||
"screenshots": "Screenshots",
|
||||
"reviewsUnit": "Bewertungen",
|
||||
"scrollBack": "Zurück",
|
||||
"scrollForward": "Weiter",
|
||||
"totalReviews": "Bewertungen insgesamt",
|
||||
"totalReviews": "Steam",
|
||||
"steamdbRating": "SteamDB-Wertung",
|
||||
"reviewScores": {
|
||||
"overwhelminglyPositive": "Äußerst positiv",
|
||||
|
||||
@@ -49,11 +49,12 @@
|
||||
"loadError": "Couldn't load game info.",
|
||||
"retry": "Retry",
|
||||
"partialFail": "Some data failed to load.",
|
||||
"noGameData": "No game data found for this app.",
|
||||
"screenshots": "Screenshots",
|
||||
"reviewsUnit": "reviews",
|
||||
"scrollBack": "Back",
|
||||
"scrollForward": "Forward",
|
||||
"totalReviews": "Total Reviews",
|
||||
"totalReviews": "Steam",
|
||||
"steamdbRating": "SteamDB Rating",
|
||||
"reviewScores": {
|
||||
"overwhelminglyPositive": "Overwhelmingly Positive",
|
||||
|
||||
@@ -49,11 +49,12 @@
|
||||
"loadError": "Oyun bilgileri yüklenemedi.",
|
||||
"retry": "Tekrar Dene",
|
||||
"partialFail": "Bazı veriler yüklenemedi.",
|
||||
"noGameData": "Bu uygulama için oyun verisi bulunamadı.",
|
||||
"screenshots": "Görseller",
|
||||
"reviewsUnit": "değerlendirme",
|
||||
"scrollBack": "Geri",
|
||||
"scrollForward": "İleri",
|
||||
"totalReviews": "Toplam Değerlendirme",
|
||||
"totalReviews": "Steam",
|
||||
"steamdbRating": "SteamDB Puanı",
|
||||
"reviewScores": {
|
||||
"overwhelminglyPositive": "Son Derece Olumlu",
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getDictionary } from "@/lib/i18n/get-dictionary";
|
||||
import { DEFAULT_LOCALE, matchLocale, type Locale } from "@/lib/i18n/locales";
|
||||
|
||||
describe("getDictionary", () => {
|
||||
it("returns the requested locale", () => {
|
||||
expect(getDictionary("de").discord.gameProfile).toBe("Spielprofil");
|
||||
});
|
||||
|
||||
it("falls back to Turkish for unknown locales", () => {
|
||||
expect(getDictionary(matchLocale("fr"))).toEqual(getDictionary("tr"));
|
||||
});
|
||||
|
||||
it("keeps all locales structurally in sync", () => {
|
||||
const shape = (locale: Locale): string => JSON.stringify(getDictionary(locale));
|
||||
expect(Object.keys(JSON.parse(shape("en"))).sort()).toEqual(
|
||||
Object.keys(JSON.parse(shape("tr"))).sort(),
|
||||
);
|
||||
expect(Object.keys(JSON.parse(shape("de"))).sort()).toEqual(
|
||||
Object.keys(JSON.parse(shape("tr"))).sort(),
|
||||
);
|
||||
});
|
||||
|
||||
it("defaults to Turkish", () => {
|
||||
expect(DEFAULT_LOCALE).toBe("tr");
|
||||
});
|
||||
});
|
||||
@@ -8,5 +8,5 @@ const dictionaries = { tr, en, de } as const;
|
||||
export type Dictionary = typeof tr;
|
||||
|
||||
export function getDictionary(locale: Locale): Dictionary {
|
||||
return dictionaries[locale] ?? dictionaries.tr;
|
||||
return dictionaries[locale];
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("next/headers", () => ({
|
||||
cookies: vi.fn(),
|
||||
}));
|
||||
|
||||
import { cookies } from "next/headers";
|
||||
import { getLocale } from "@/lib/i18n/get-locale";
|
||||
|
||||
describe("getLocale", () => {
|
||||
it("returns the cookie locale when valid", async () => {
|
||||
vi.mocked(cookies).mockResolvedValue({ get: () => ({ value: "de" }) } as never);
|
||||
await expect(getLocale()).resolves.toBe("de");
|
||||
});
|
||||
|
||||
it("falls back to default without a cookie", async () => {
|
||||
vi.mocked(cookies).mockResolvedValue({ get: () => undefined } as never);
|
||||
await expect(getLocale()).resolves.toBe("tr");
|
||||
});
|
||||
|
||||
it("falls back on unknown values", async () => {
|
||||
vi.mocked(cookies).mockResolvedValue({ get: () => ({ value: "fr" }) } as never);
|
||||
await expect(getLocale()).resolves.toBe("tr");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isLocale, matchLocale } from "@/lib/i18n/locales";
|
||||
|
||||
describe("isLocale", () => {
|
||||
it("accepts supported locales", () => {
|
||||
expect(isLocale("tr")).toBe(true);
|
||||
expect(isLocale("en")).toBe(true);
|
||||
expect(isLocale("de")).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects anything else", () => {
|
||||
expect(isLocale("fr")).toBe(false);
|
||||
expect(isLocale("")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("matchLocale", () => {
|
||||
it("defaults without a header", () => {
|
||||
expect(matchLocale(null)).toBe("tr");
|
||||
expect(matchLocale("")).toBe("tr");
|
||||
});
|
||||
|
||||
it("matches primary ranges", () => {
|
||||
expect(matchLocale("en-US,en;q=0.9")).toBe("en");
|
||||
expect(matchLocale("de-DE,de;q=0.9,en;q=0.8")).toBe("de");
|
||||
});
|
||||
|
||||
it("respects q-values", () => {
|
||||
expect(matchLocale("en;q=0.5,tr;q=0.9")).toBe("tr");
|
||||
});
|
||||
|
||||
it("falls back on unknown or wildcard ranges", () => {
|
||||
expect(matchLocale("fr-FR,fr;q=0.9")).toBe("tr");
|
||||
expect(matchLocale("*")).toBe("tr");
|
||||
});
|
||||
});
|
||||
@@ -1,16 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import { cookies } from "next/headers";
|
||||
import { LOCALE_COOKIE, isLocale, type Locale } from "./locales";
|
||||
|
||||
export async function setLocaleCookie(locale: Locale): Promise<void> {
|
||||
if (!isLocale(locale)) {
|
||||
return;
|
||||
}
|
||||
const store = await cookies();
|
||||
store.set(LOCALE_COOKIE, locale, {
|
||||
path: "/",
|
||||
maxAge: 60 * 60 * 24 * 365,
|
||||
sameSite: "lax",
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user