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
@@ -0,0 +1,58 @@
|
||||
import type {
|
||||
GameReviewSummary,
|
||||
SteamAppDetails,
|
||||
SteamReviewQuery,
|
||||
} from "@/lib/game/game-profile-types";
|
||||
import { resolveGameLocale } from "@/lib/game/game-format";
|
||||
import { warnDev } from "@/lib/log";
|
||||
|
||||
export async function getSteamDetails(
|
||||
steamId: string,
|
||||
lang = "en",
|
||||
country = "US",
|
||||
): Promise<SteamAppDetails["data"] | null> {
|
||||
try {
|
||||
const { steamLang } = resolveGameLocale(lang);
|
||||
const response = await fetch(
|
||||
`https://store.steampowered.com/api/appdetails?appids=${steamId}&l=${steamLang}&cc=${country}`,
|
||||
{ next: { revalidate: 86_400 } },
|
||||
);
|
||||
if (!response.ok) {
|
||||
warnDev(`steam details failed: ${response.status}`);
|
||||
return null;
|
||||
}
|
||||
const json = (await response.json()) as Record<string, SteamAppDetails>;
|
||||
const entry = json[steamId];
|
||||
return entry?.success ? (entry.data ?? null) : null;
|
||||
} catch (error) {
|
||||
warnDev(`steam details request failed: ${error instanceof Error ? error.message : error}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
export async function getSteamReviewSummary(steamId: string): Promise<GameReviewSummary | null> {
|
||||
try {
|
||||
const url =
|
||||
`https://store.steampowered.com/appreviews/${steamId}` +
|
||||
"?json=1&language=all&purchase_type=all&num_per_page=0";
|
||||
const response = await fetch(url, { next: { revalidate: 3600 } });
|
||||
if (!response.ok) {
|
||||
warnDev(`steam reviews failed: ${response.status}`);
|
||||
return null;
|
||||
}
|
||||
const json = (await response.json()) as { query_summary?: SteamReviewQuery };
|
||||
const summary = json.query_summary;
|
||||
if (!summary || typeof summary.total_reviews !== "number") {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
label: summary.review_score_desc ?? "",
|
||||
total: summary.total_reviews,
|
||||
positive: summary.total_positive ?? null,
|
||||
negative: summary.total_negative ?? null,
|
||||
url: `https://store.steampowered.com/app/${steamId}/#app_reviews_hash`,
|
||||
};
|
||||
} catch (error) {
|
||||
warnDev(`steam reviews request failed: ${error instanceof Error ? error.message : error}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user