refactor: convert to bun workspaces monorepo
- Move web app into apps/web/ - Create packages/shared/ with shared types - Create plugins/decky-vault/ scaffold - Root package.json manages workspaces only
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import { notFound, redirect } from "next/navigation"
|
||||
import { headers } from "next/headers"
|
||||
import { db } from "@/lib/db/index"
|
||||
import { games, gamePlatformSupport, hardware } from "@/lib/db/schema"
|
||||
import { eq } from "drizzle-orm"
|
||||
import { auth } from "@/lib/auth"
|
||||
import { NonSteamEditForm } from "@/components/wizard/non-steam-edit-form"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata = {
|
||||
title: "Edit Game",
|
||||
}
|
||||
|
||||
async function resolveGame(id: string) {
|
||||
const isNumeric = /^\d+$/.test(id)
|
||||
if (isNumeric) {
|
||||
const rows = await db.select().from(games).where(eq(games.steamAppId, Number(id))).limit(1)
|
||||
return rows[0]
|
||||
}
|
||||
const rows = await db.select().from(games).where(eq(games.id, id)).limit(1)
|
||||
return rows[0]
|
||||
}
|
||||
|
||||
export default async function EditGamePage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}) {
|
||||
const { id } = await params
|
||||
const h = await headers()
|
||||
const session = await auth.api.getSession({ headers: h })
|
||||
if (!session?.user) redirect("/login")
|
||||
|
||||
const game = await resolveGame(id)
|
||||
if (!game) notFound()
|
||||
|
||||
if (game.source === "steam") {
|
||||
notFound()
|
||||
}
|
||||
|
||||
const platformSupport = await db
|
||||
.select()
|
||||
.from(gamePlatformSupport)
|
||||
.where(eq(gamePlatformSupport.gameId, game.id))
|
||||
|
||||
const hardwareList = await db
|
||||
.select({ slug: hardware.slug, name: hardware.name, deviceType: hardware.deviceType })
|
||||
.from(hardware)
|
||||
.orderBy(hardware.sortOrder)
|
||||
|
||||
const serializedGame = {
|
||||
id: game.id,
|
||||
title: game.title,
|
||||
developer: game.developer,
|
||||
publisher: game.publisher,
|
||||
description: game.description,
|
||||
source: game.source,
|
||||
storeUrl: game.storeUrl,
|
||||
headerImage: game.headerImage,
|
||||
capsuleImage: game.capsuleImage,
|
||||
genres: game.genres,
|
||||
releaseDate: game.releaseDate,
|
||||
createdBy: game.createdBy,
|
||||
}
|
||||
|
||||
const serializedPlatformSupport = platformSupport.map(ps => ({
|
||||
hardwareSlug: ps.hardwareSlug,
|
||||
isSupported: ps.isSupported,
|
||||
protonStatus: ps.protonStatus,
|
||||
}))
|
||||
|
||||
return (
|
||||
<div className="max-w-3xl mx-auto px-4 py-8 w-full">
|
||||
<div className="mb-8">
|
||||
<h1 className="text-2xl font-bold mb-2">Edit Game</h1>
|
||||
<p className="text-sm text-text/60">
|
||||
Update details for <span className="text-text font-medium">{game.title}</span>
|
||||
</p>
|
||||
</div>
|
||||
<NonSteamEditForm
|
||||
game={serializedGame}
|
||||
platformSupport={serializedPlatformSupport}
|
||||
hardwareList={hardwareList}
|
||||
isOwner={session.user.id === game.createdBy}
|
||||
isAdmin={session.user.role === "admin"}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,84 @@
|
||||
import { ImageResponse } from "next/og"
|
||||
import { db } from "@/lib/db/index"
|
||||
import { games, gameVersions, performanceEntries } from "@/lib/db/schema"
|
||||
import { eq, and, sql } from "drizzle-orm"
|
||||
import { readFile } from "node:fs/promises"
|
||||
import { join } from "node:path"
|
||||
|
||||
// This needs live data — skip static generation at build time
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const alt = "DeckyVault - Game Benchmarks"
|
||||
export const size = { width: 1200, height: 630 }
|
||||
export const contentType = "image/png"
|
||||
|
||||
export default async function Image({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params
|
||||
const isNumeric = /^\d+$/.test(id)
|
||||
|
||||
let game
|
||||
if (isNumeric) {
|
||||
const rows = await db.select().from(games).where(eq(games.steamAppId, Number(id))).limit(1)
|
||||
game = rows[0]
|
||||
} else {
|
||||
const rows = await db.select().from(games).where(eq(games.id, id)).limit(1)
|
||||
game = rows[0]
|
||||
}
|
||||
|
||||
if (!game) {
|
||||
return new ImageResponse(
|
||||
(
|
||||
<div style={{ width: "100%", height: "100%", display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", background: "#100b14", color: "#ebe4f1", fontFamily: "sans-serif", gap: "16px" }}>
|
||||
<div style={{ fontSize: 48, fontWeight: 700 }}>Game Not Found</div>
|
||||
<div style={{ fontSize: 24, opacity: 0.7 }}>DeckyVault</div>
|
||||
</div>
|
||||
),
|
||||
{ ...size }
|
||||
)
|
||||
}
|
||||
|
||||
// Get best FPS stat
|
||||
let avgFps: number | null = null
|
||||
try {
|
||||
const [bestStat] = await db
|
||||
.select({ avgFps: sql<number>`round(avg(${performanceEntries.fpsAvg})::numeric, 1)` })
|
||||
.from(performanceEntries)
|
||||
.innerJoin(gameVersions, eq(performanceEntries.versionId, gameVersions.id))
|
||||
.where(and(eq(gameVersions.gameId, game.id), eq(performanceEntries.isRemoved, false)))
|
||||
.limit(1)
|
||||
avgFps = bestStat?.avgFps ?? null
|
||||
} catch {
|
||||
// No FPS data available — that's fine
|
||||
}
|
||||
|
||||
const logoData = await readFile(join(process.cwd(), "app/icon.png"), "base64")
|
||||
const logoSrc = `data:image/png;base64,${logoData}`
|
||||
|
||||
return new ImageResponse(
|
||||
(
|
||||
<div style={{ width: "100%", height: "100%", display: "flex", flexDirection: "column", justifyContent: "center", padding: "60px", background: "#100b14", color: "#ebe4f1", fontFamily: "sans-serif" }}>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "16px", marginBottom: "24px" }}>
|
||||
<img src={logoSrc} alt="" height={48} style={{ borderRadius: "8px" }} />
|
||||
<span style={{ fontSize: 24, fontWeight: 600, opacity: 0.8 }}>DeckyVault</span>
|
||||
</div>
|
||||
<div style={{ fontSize: 56, fontWeight: 700, lineHeight: 1.1, marginBottom: "16px", maxWidth: "900px" }}>
|
||||
{game.title}
|
||||
</div>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "24px", fontSize: 24, opacity: 0.8 }}>
|
||||
{game.developer && <span>by {game.developer}</span>}
|
||||
{avgFps !== null && <span style={{ color: "#22c55e" }}>~{avgFps} avg FPS</span>}
|
||||
</div>
|
||||
{game.genres && game.genres.length > 0 && (
|
||||
<div style={{ display: "flex", gap: "8px", marginTop: "16px" }}>
|
||||
{game.genres.slice(0, 4).map((genre: string) => (
|
||||
<span key={genre} style={{ padding: "4px 12px", borderRadius: "9999px", background: "rgba(139,92,246,0.15)", border: "1px solid rgba(139,92,246,0.3)", fontSize: 16 }}>
|
||||
{genre}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
{ ...size }
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
import type { Metadata } from "next"
|
||||
import { Suspense } from "react"
|
||||
import { notFound } from "next/navigation"
|
||||
import { after } from "next/server"
|
||||
import { db } from "@/lib/db/index"
|
||||
import {
|
||||
games,
|
||||
gameVersions,
|
||||
performanceEntries,
|
||||
gameComments,
|
||||
gamePlatformSupport,
|
||||
hardware,
|
||||
user,
|
||||
entryScreenshots,
|
||||
} from "@/lib/db/schema"
|
||||
import { and, desc, eq, sql } from "drizzle-orm"
|
||||
import { isSyncStale, syncSteamGame, ensureSteamGame } from "@/lib/steam/sync"
|
||||
import { getR2PublicUrl } from "@/lib/storage"
|
||||
import { smartTruncate, buildBreadcrumbList } from "@/lib/utils/seo"
|
||||
import { GamePageClient } from "./game-page-client"
|
||||
|
||||
// This page needs live data — skip static generation at build time
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
async function resolveGame(id: string) {
|
||||
const isNumeric = /^\d+$/.test(id)
|
||||
let game
|
||||
if (isNumeric) {
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(games)
|
||||
.where(eq(games.steamAppId, Number(id)))
|
||||
.limit(1)
|
||||
game = rows[0]
|
||||
} else {
|
||||
// Try UUID first
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(games)
|
||||
.where(eq(games.id, id))
|
||||
.limit(1)
|
||||
game = rows[0]
|
||||
|
||||
// Fallback: try slug lookup
|
||||
if (!game) {
|
||||
const slugRows = await db
|
||||
.select()
|
||||
.from(games)
|
||||
.where(eq(games.slug, id))
|
||||
.limit(1)
|
||||
game = slugRows[0]
|
||||
}
|
||||
}
|
||||
return game
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise<Metadata> {
|
||||
const { id } = await params
|
||||
const game = await resolveGame(id)
|
||||
|
||||
if (!game) {
|
||||
return { title: "Game Not Found | DeckyVault" }
|
||||
}
|
||||
|
||||
const description = game.description
|
||||
? smartTruncate(game.description, 160)
|
||||
: `Find benchmarks, community presets, and performance settings for ${game.title} on Steam Deck. Compare FPS, TDP, and battery life from community reports.`
|
||||
|
||||
return {
|
||||
title: `${game.title} - Benchmarks & Settings`,
|
||||
description,
|
||||
alternates: { canonical: `https://deckyvault.xyz/game/${game.id}` },
|
||||
openGraph: {
|
||||
title: `${game.title} - Benchmarks & Settings | DeckyVault`,
|
||||
description: game.description ? smartTruncate(game.description, 200) : `Benchmarks and settings for ${game.title}`,
|
||||
url: `https://deckyvault.xyz/game/${game.id}`,
|
||||
images: [{ url: `/game/${game.id}/opengraph-image`, width: 1200, height: 630 }],
|
||||
type: "website",
|
||||
siteName: "DeckyVault",
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: `${game.title} - Benchmarks & Settings | DeckyVault`,
|
||||
description: game.description ? smartTruncate(game.description, 200) : `Benchmarks and settings for ${game.title}`,
|
||||
images: [`/game/${game.id}/opengraph-image`],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async function createGameStub(steamAppId: number) {
|
||||
const result = await ensureSteamGame(steamAppId)
|
||||
if (!result.game) {
|
||||
notFound()
|
||||
}
|
||||
// If the sync determined this is not a game (DLC, soundtrack, etc.),
|
||||
// treat it as not found rather than showing a broken page
|
||||
if (result.game.syncStatus === "error" && result.error?.includes("not a game")) {
|
||||
notFound()
|
||||
}
|
||||
return result.game
|
||||
}
|
||||
|
||||
export default async function GamePage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
searchParams: Promise<{ sync?: string }>
|
||||
}) {
|
||||
const { id } = await params
|
||||
const { sync } = await searchParams
|
||||
const isNumeric = /^\d+$/.test(id)
|
||||
const forceSync = sync === "1"
|
||||
|
||||
// ── Resolve game ────────────────────────────────────────────────
|
||||
let game = await resolveGame(id)
|
||||
|
||||
if (!game && isNumeric) {
|
||||
try {
|
||||
game = await createGameStub(Number(id))
|
||||
} catch (err) {
|
||||
console.error("Failed to auto-create game stub:", err)
|
||||
}
|
||||
}
|
||||
|
||||
if (!game) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
// ── Fetch related data in parallel ──────────────────────────────
|
||||
const [
|
||||
benchmarkCount,
|
||||
presetCount,
|
||||
commentCount,
|
||||
platformSupport,
|
||||
presetRows,
|
||||
] = await Promise.all([
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(performanceEntries)
|
||||
.innerJoin(
|
||||
gameVersions,
|
||||
eq(performanceEntries.versionId, gameVersions.id),
|
||||
)
|
||||
.where(eq(gameVersions.gameId, game.id))
|
||||
.then((r) => r[0]?.count ?? 0),
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(performanceEntries)
|
||||
.innerJoin(gameVersions, eq(performanceEntries.versionId, gameVersions.id))
|
||||
.where(
|
||||
and(
|
||||
eq(gameVersions.gameId, game.id),
|
||||
eq(performanceEntries.isRemoved, false),
|
||||
sql`${performanceEntries.settingsJson} IS NOT NULL`,
|
||||
),
|
||||
)
|
||||
.then((r) => r[0]?.count ?? 0),
|
||||
db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(gameComments)
|
||||
.where(eq(gameComments.gameId, game.id))
|
||||
.then((r) => r[0]?.count ?? 0),
|
||||
db
|
||||
.select()
|
||||
.from(gamePlatformSupport)
|
||||
.where(eq(gamePlatformSupport.gameId, game.id))
|
||||
.then((r) => r),
|
||||
db
|
||||
.select({
|
||||
id: performanceEntries.id,
|
||||
hardwareSlug: performanceEntries.hardwareSlug,
|
||||
hardwareName: hardware.name,
|
||||
upvotes: performanceEntries.upvotes,
|
||||
settingsJson: performanceEntries.settingsJson,
|
||||
fpsAvg: performanceEntries.fpsAvg,
|
||||
fpsLow: performanceEntries.fpsLow,
|
||||
fpsHigh: performanceEntries.fpsHigh,
|
||||
fpsOnePercentLow: performanceEntries.fpsOnePercentLow,
|
||||
upscalerType: performanceEntries.upscalerType,
|
||||
upscalerVersion: performanceEntries.upscalerVersion,
|
||||
frameGenMethod: performanceEntries.frameGenMethod,
|
||||
protonVersion: performanceEntries.protonVersion,
|
||||
osVersion: performanceEntries.osVersion,
|
||||
createdAt: performanceEntries.createdAt,
|
||||
userId: performanceEntries.userId,
|
||||
userName: user.name,
|
||||
userImage: user.image,
|
||||
downvotes: performanceEntries.downvotes,
|
||||
launchOptions: performanceEntries.launchOptions,
|
||||
loadTimeSsd: performanceEntries.loadTimeSsd,
|
||||
loadTimeSd: performanceEntries.loadTimeSd,
|
||||
tdpWatts: performanceEntries.tdpWatts,
|
||||
youtubeVideoId: performanceEntries.youtubeVideoId,
|
||||
customSystem: performanceEntries.customSystem,
|
||||
userNotes: performanceEntries.userNotes,
|
||||
versionString: gameVersions.versionString,
|
||||
buildId: gameVersions.buildId,
|
||||
gameAntiCheatName: gamePlatformSupport.antiCheatName,
|
||||
gameAntiCheatStatus: gamePlatformSupport.antiCheatStatus,
|
||||
verifiedAt: performanceEntries.verifiedAt,
|
||||
isPinned: performanceEntries.isPinned,
|
||||
pinnedAt: performanceEntries.pinnedAt,
|
||||
})
|
||||
.from(performanceEntries)
|
||||
.innerJoin(gameVersions, eq(performanceEntries.versionId, gameVersions.id))
|
||||
.innerJoin(hardware, eq(performanceEntries.hardwareSlug, hardware.slug))
|
||||
.innerJoin(user, eq(performanceEntries.userId, user.id))
|
||||
.innerJoin(
|
||||
gamePlatformSupport,
|
||||
and(
|
||||
eq(gamePlatformSupport.gameId, gameVersions.gameId),
|
||||
eq(gamePlatformSupport.hardwareSlug, performanceEntries.hardwareSlug),
|
||||
),
|
||||
)
|
||||
.where(
|
||||
and(
|
||||
eq(gameVersions.gameId, game.id),
|
||||
eq(performanceEntries.isRemoved, false),
|
||||
sql`${performanceEntries.settingsJson} IS NOT NULL`,
|
||||
),
|
||||
)
|
||||
.orderBy(desc(performanceEntries.isPinned), desc(performanceEntries.upvotes)),
|
||||
])
|
||||
|
||||
// ── Sync logic: force or stale-while-revalidate ────────────────
|
||||
const shouldSync =
|
||||
game.source === "steam" &&
|
||||
game.steamAppId &&
|
||||
(forceSync || isSyncStale(game.lastSync))
|
||||
|
||||
if (shouldSync) {
|
||||
if (forceSync) {
|
||||
// Block render on forced sync so user sees fresh data immediately
|
||||
await syncSteamGame(game.steamAppId!)
|
||||
// Re-fetch game after sync so serialized data is fresh
|
||||
const refreshed = await resolveGame(game.steamAppId!.toString())
|
||||
if (refreshed) game = refreshed
|
||||
} else {
|
||||
// Stale sync happens after response so page isn't delayed
|
||||
after(async () => {
|
||||
await syncSteamGame(game.steamAppId!)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize for client component (Dates → strings)
|
||||
const serializedGame = {
|
||||
id: game.id,
|
||||
steamAppId: game.steamAppId,
|
||||
title: game.title,
|
||||
description: game.description,
|
||||
developer: game.developer,
|
||||
publisher: game.publisher,
|
||||
genres: game.genres,
|
||||
headerImage: game.headerImage,
|
||||
capsuleImage: game.capsuleImage,
|
||||
storeUrl: game.storeUrl,
|
||||
source: game.source,
|
||||
slug: game.slug,
|
||||
lastSync: game.lastSync ? game.lastSync.toISOString() : null,
|
||||
syncStatus: game.syncStatus,
|
||||
createdAt: game.createdAt.toISOString(),
|
||||
systemRequirements: game.systemRequirements,
|
||||
metacriticScore: game.metacriticScore,
|
||||
metacriticUrl: game.metacriticUrl,
|
||||
recommendationsTotal: game.recommendationsTotal,
|
||||
priceCurrent: game.priceCurrent,
|
||||
priceInitial: game.priceInitial,
|
||||
priceCurrency: game.priceCurrency,
|
||||
isFree: game.isFree,
|
||||
releaseDate: game.releaseDate,
|
||||
categories: game.categories,
|
||||
platforms: game.platforms,
|
||||
steamReviewScore: game.steamReviewScore,
|
||||
steamReviewSentiment: game.steamReviewSentiment,
|
||||
steamReviewCount: game.steamReviewCount,
|
||||
}
|
||||
|
||||
const serializedPresets = presetRows.map((p) => ({
|
||||
id: p.id,
|
||||
gameId: game.id,
|
||||
hardwareSlug: p.hardwareSlug,
|
||||
hardwareName: p.hardwareName,
|
||||
upvotes: p.upvotes,
|
||||
settingsCount: Array.isArray(p.settingsJson)
|
||||
? p.settingsJson.reduce(
|
||||
(sum: number, cat: { settings: unknown[] }) =>
|
||||
sum + cat.settings.length,
|
||||
0,
|
||||
)
|
||||
: 0,
|
||||
fpsAvg: p.fpsAvg,
|
||||
fpsLow: p.fpsLow,
|
||||
fpsHigh: p.fpsHigh,
|
||||
fpsOnePercentLow: p.fpsOnePercentLow ?? null,
|
||||
upscalerType: p.upscalerType,
|
||||
upscalerVersion: p.upscalerVersion,
|
||||
frameGenMethod: p.frameGenMethod,
|
||||
protonVersion: p.protonVersion,
|
||||
osVersion: p.osVersion,
|
||||
createdAt: p.createdAt.toISOString(),
|
||||
settingsJson: p.settingsJson,
|
||||
launchOptions: p.launchOptions,
|
||||
loadTimeSsd: p.loadTimeSsd ?? null,
|
||||
loadTimeSd: p.loadTimeSd ?? null,
|
||||
tdpWatts: p.tdpWatts ?? null,
|
||||
youtubeVideoId: p.youtubeVideoId ?? null,
|
||||
screenshots: null as Array<{ id: string; url: string; width: number; height: number; orderIndex: number }> | null,
|
||||
hardwareWattHours: null as number | null,
|
||||
hardwareDeviceType: null as string | null,
|
||||
customSystem: p.customSystem ?? false,
|
||||
userNotes: p.userNotes,
|
||||
versionString: p.versionString ?? null,
|
||||
buildId: p.buildId ?? null,
|
||||
gameAntiCheatName: p.gameAntiCheatName ?? null,
|
||||
gameAntiCheatStatus: p.gameAntiCheatStatus ?? null,
|
||||
userId: p.userId,
|
||||
userName: p.userName,
|
||||
userImage: p.userImage,
|
||||
downvotes: p.downvotes,
|
||||
verifiedAt: p.verifiedAt ? p.verifiedAt.toISOString() : null,
|
||||
isPinned: p.isPinned,
|
||||
pinnedAt: p.pinnedAt ? p.pinnedAt.toISOString() : null,
|
||||
}))
|
||||
|
||||
// Fetch screenshots and hardware details for each preset
|
||||
const publicUrl = getR2PublicUrl()
|
||||
for (const preset of serializedPresets) {
|
||||
const screenshots = await db
|
||||
.select({
|
||||
id: entryScreenshots.id,
|
||||
storageKey: entryScreenshots.storageKey,
|
||||
orderIndex: entryScreenshots.orderIndex,
|
||||
width: entryScreenshots.width,
|
||||
height: entryScreenshots.height,
|
||||
})
|
||||
.from(entryScreenshots)
|
||||
.where(eq(entryScreenshots.entryId, preset.id))
|
||||
.orderBy(entryScreenshots.orderIndex)
|
||||
|
||||
preset.screenshots = screenshots.map((ss) => ({
|
||||
id: ss.id,
|
||||
url: `${publicUrl}/${ss.storageKey}`,
|
||||
width: ss.width,
|
||||
height: ss.height,
|
||||
orderIndex: ss.orderIndex,
|
||||
}))
|
||||
|
||||
const [hw] = await db
|
||||
.select({
|
||||
wattHours: hardware.wattHours,
|
||||
deviceType: hardware.deviceType,
|
||||
})
|
||||
.from(hardware)
|
||||
.where(eq(hardware.slug, preset.hardwareSlug))
|
||||
.limit(1)
|
||||
|
||||
preset.hardwareWattHours = hw?.wattHours ? Number(hw.wattHours) : null
|
||||
preset.hardwareDeviceType = hw?.deviceType ?? null
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: JSON.stringify({
|
||||
"@context": "https://schema.org",
|
||||
"@type": "VideoGame",
|
||||
name: game.title,
|
||||
...(game.developer && { developer: { "@type": "Organization", name: game.developer } }),
|
||||
...(game.genres && game.genres.length > 0 && { genre: game.genres }),
|
||||
...(game.headerImage && { image: game.headerImage }),
|
||||
url: `https://deckyvault.xyz/game/${game.id}`,
|
||||
applicationCategory: "Game",
|
||||
operatingSystem: "SteamOS",
|
||||
...(game.storeUrl && { offers: { "@type": "Offer", url: game.storeUrl } }),
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: JSON.stringify(
|
||||
buildBreadcrumbList([
|
||||
{ name: "Home", url: "https://deckyvault.xyz" },
|
||||
{ name: "Games", url: "https://deckyvault.xyz/games" },
|
||||
{ name: game.title, url: `https://deckyvault.xyz/game/${game.id}` },
|
||||
]),
|
||||
),
|
||||
}}
|
||||
/>
|
||||
{/* AggregateRating — based on Steam review score when available */}
|
||||
{game.steamReviewScore != null && (
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: JSON.stringify({
|
||||
"@context": "https://schema.org",
|
||||
"@type": "AggregateRating",
|
||||
itemReviewed: {
|
||||
"@type": "VideoGame",
|
||||
name: game.title,
|
||||
},
|
||||
ratingValue: (game.steamReviewScore / 10).toFixed(1),
|
||||
bestRating: "10",
|
||||
worstRating: "0",
|
||||
ratingCount: game.steamReviewCount ?? undefined,
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<Suspense fallback={<div className="min-h-screen" />}>
|
||||
<GamePageClient
|
||||
game={serializedGame}
|
||||
counts={{
|
||||
benchmarks: benchmarkCount,
|
||||
presets: presetCount,
|
||||
comments: commentCount,
|
||||
}}
|
||||
platformSupport={platformSupport}
|
||||
presets={serializedPresets}
|
||||
gameId={game.id}
|
||||
/>
|
||||
</Suspense>
|
||||
</>
|
||||
)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,157 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import { db } from "@/lib/db/index"
|
||||
import { games, gameVersions, performanceEntries, gamePlatformSupport, entryScreenshots } from "@/lib/db/schema"
|
||||
import { eq, sql } from "drizzle-orm"
|
||||
import { GameEntryWizard, type GameVersionInfo } from "@/components/wizard/game-entry-wizard"
|
||||
import { getR2PublicUrl } from "@/lib/storage/r2-client"
|
||||
|
||||
// This page needs live data — skip static generation at build time
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
export const metadata = {
|
||||
title: "Submit Benchmark",
|
||||
}
|
||||
|
||||
interface PageProps {
|
||||
params: Promise<{ id: string }>
|
||||
searchParams: Promise<{ edit?: string }>
|
||||
}
|
||||
|
||||
export default async function SubmitBenchmarkPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: PageProps) {
|
||||
const { id } = await params
|
||||
const { edit } = await searchParams
|
||||
|
||||
// Resolve game
|
||||
const isNumeric = /^\d+$/.test(id)
|
||||
let game
|
||||
|
||||
if (isNumeric) {
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(games)
|
||||
.where(eq(games.steamAppId, Number(id)))
|
||||
.limit(1)
|
||||
game = rows[0]
|
||||
} else {
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(games)
|
||||
.where(eq(games.id, id))
|
||||
.limit(1)
|
||||
game = rows[0]
|
||||
}
|
||||
|
||||
if (!game) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
// Fetch all game versions for version selection
|
||||
const allVersions = await db
|
||||
.select({
|
||||
id: gameVersions.id,
|
||||
versionString: gameVersions.versionString,
|
||||
buildId: gameVersions.buildId,
|
||||
isLatest: gameVersions.isLatest,
|
||||
})
|
||||
.from(gameVersions)
|
||||
.where(eq(gameVersions.gameId, game.id))
|
||||
.orderBy(sql`${gameVersions.createdAt} DESC`)
|
||||
|
||||
// Create a default version if none exists
|
||||
if (allVersions.length === 0) {
|
||||
const [newVersion] = await db
|
||||
.insert(gameVersions)
|
||||
.values({
|
||||
gameId: game.id,
|
||||
isLatest: true,
|
||||
})
|
||||
.returning()
|
||||
allVersions.push({
|
||||
id: newVersion.id,
|
||||
versionString: newVersion.versionString,
|
||||
buildId: newVersion.buildId,
|
||||
isLatest: newVersion.isLatest,
|
||||
})
|
||||
}
|
||||
|
||||
// If editing, fetch the existing performance entry
|
||||
let editEntry: any = null
|
||||
if (edit) {
|
||||
const [entry] = await db
|
||||
.select()
|
||||
.from(performanceEntries)
|
||||
.where(eq(performanceEntries.id, edit))
|
||||
.limit(1)
|
||||
|
||||
if (entry) {
|
||||
const publicUrl = getR2PublicUrl()
|
||||
const screenshots = await db
|
||||
.select({
|
||||
id: entryScreenshots.id,
|
||||
storageKey: entryScreenshots.storageKey,
|
||||
orderIndex: entryScreenshots.orderIndex,
|
||||
width: entryScreenshots.width,
|
||||
height: entryScreenshots.height,
|
||||
})
|
||||
.from(entryScreenshots)
|
||||
.where(eq(entryScreenshots.entryId, entry.id))
|
||||
.orderBy(entryScreenshots.orderIndex)
|
||||
|
||||
editEntry = {
|
||||
...entry,
|
||||
screenshots: screenshots.map((ss) => ({
|
||||
id: ss.id,
|
||||
url: `${publicUrl}/${ss.storageKey}`,
|
||||
width: ss.width,
|
||||
height: ss.height,
|
||||
orderIndex: ss.orderIndex,
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine default version: when editing, use the entry's version;
|
||||
// otherwise, use the latest (first in DESC order)
|
||||
let defaultVersionId = allVersions[0].id
|
||||
if (editEntry?.versionId) {
|
||||
defaultVersionId = editEntry.versionId
|
||||
}
|
||||
|
||||
const gameVersionInfos: GameVersionInfo[] = allVersions
|
||||
|
||||
// Fetch platform support for anti-cheat awareness
|
||||
const platformSupport = await db
|
||||
.select({
|
||||
hardwareSlug: gamePlatformSupport.hardwareSlug,
|
||||
antiCheatRelevant: gamePlatformSupport.antiCheatRelevant,
|
||||
antiCheatName: gamePlatformSupport.antiCheatName,
|
||||
antiCheatStatus: gamePlatformSupport.antiCheatStatus,
|
||||
})
|
||||
.from(gamePlatformSupport)
|
||||
.where(eq(gamePlatformSupport.gameId, game.id))
|
||||
|
||||
return (
|
||||
<div className="max-w-7xl mx-auto px-4 py-8 w-full">
|
||||
<div className="mb-8">
|
||||
<h1 className="text-2xl font-bold mb-2">
|
||||
{editEntry ? "Edit Benchmark" : "Submit Benchmark"}
|
||||
</h1>
|
||||
<p className="text-sm text-text/60">
|
||||
{editEntry ? "Update your performance data for" : "Submit performance data for"}{" "}
|
||||
<span className="text-text font-medium">{game.title}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<GameEntryWizard
|
||||
gameId={game.id}
|
||||
gameVersions={gameVersionInfos}
|
||||
defaultVersionId={defaultVersionId}
|
||||
editEntry={editEntry}
|
||||
platformSupport={platformSupport}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user