refactor: remove communityPresets schema, API, and routes
This commit is contained in:
@@ -11,9 +11,6 @@ import {
|
||||
performanceRoutes,
|
||||
performanceVerifyRoutes,
|
||||
performanceSubmitRoutes,
|
||||
presetsRoutes,
|
||||
presetUpvoteRoutes,
|
||||
presetSettingsRoutes,
|
||||
commentsRoutes,
|
||||
savedGamesRoutes,
|
||||
} from "@/lib/api"
|
||||
@@ -68,10 +65,6 @@ export const app = new Elysia({ prefix: "/api" })
|
||||
.use(performanceRoutes)
|
||||
.use(performanceVerifyRoutes)
|
||||
.use(performanceSubmitRoutes)
|
||||
// Presets
|
||||
.use(presetsRoutes)
|
||||
.use(presetUpvoteRoutes)
|
||||
.use(presetSettingsRoutes)
|
||||
// Comments
|
||||
.use(commentsRoutes)
|
||||
// Steam search proxy
|
||||
|
||||
@@ -48,6 +48,13 @@ export default function Navbar() {
|
||||
const { data: session, isPending: isSessionLoading } = useSession()
|
||||
const [userMenuOpen, setUserMenuOpen] = useState(false)
|
||||
|
||||
// Prevent hydration mismatch: useSession resolves differently on
|
||||
// server (isPending=true) vs client. We delay rendering the
|
||||
// auth-dependent UI until after the first client paint.
|
||||
const [mounted, setMounted] = useState(false)
|
||||
useEffect(() => setMounted(true), [])
|
||||
const showAuth = mounted && !isSessionLoading
|
||||
|
||||
// Sync search query with URL ?q= param
|
||||
const searchQueryRef = useRef(searchQuery)
|
||||
useEffect(() => {
|
||||
@@ -239,7 +246,7 @@ export default function Navbar() {
|
||||
mode='popLayout'
|
||||
initial={false}
|
||||
>
|
||||
{isSessionLoading ? (
|
||||
{!showAuth ? (
|
||||
<motion.li
|
||||
key='loading-placeholder'
|
||||
initial={{ opacity: 0 }}
|
||||
@@ -389,7 +396,7 @@ export default function Navbar() {
|
||||
</nav>
|
||||
{/* Mobile Auth Controls */}
|
||||
<div className='mt-auto p-4 border-t border-text/8'>
|
||||
{isSessionLoading ? (
|
||||
{!showAuth ? (
|
||||
<div className='w-full h-10 rounded-lg bg-text/3 animate-pulse' />
|
||||
) : session ? (
|
||||
<div className='space-y-2'>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
ALTER TYPE "public"."fsr_version" RENAME TO "upscaler_type";--> statement-breakpoint
|
||||
ALTER TYPE "public"."frame_gen_method" ADD VALUE 'lsfg';--> statement-breakpoint
|
||||
ALTER TYPE "public"."frame_gen_method" ADD VALUE 'other';--> statement-breakpoint
|
||||
ALTER TABLE "performance_entries" RENAME COLUMN "fsr_version" TO "upscaler_type";--> statement-breakpoint
|
||||
ALTER TABLE "performance_entries" ALTER COLUMN "upscaler_type" SET DATA TYPE text;--> statement-breakpoint
|
||||
ALTER TABLE "performance_entries" ALTER COLUMN "upscaler_type" SET DEFAULT 'none'::text;--> statement-breakpoint
|
||||
DROP TYPE "public"."upscaler_type";--> statement-breakpoint
|
||||
CREATE TYPE "public"."upscaler_type" AS ENUM('none', 'fsr', 'dlss', 'xess', 'lsfg', 'other');--> statement-breakpoint
|
||||
ALTER TABLE "performance_entries" ALTER COLUMN "upscaler_type" SET DEFAULT 'none'::"public"."upscaler_type";--> statement-breakpoint
|
||||
ALTER TABLE "performance_entries" ALTER COLUMN "upscaler_type" SET DATA TYPE "public"."upscaler_type" USING "upscaler_type"::"public"."upscaler_type";--> statement-breakpoint
|
||||
DROP INDEX "perf_hardware_fsr_idx";--> statement-breakpoint
|
||||
ALTER TABLE "performance_entries" ADD COLUMN "upscaler_version" text;--> statement-breakpoint
|
||||
ALTER TABLE "performance_entries" ADD COLUMN "estimated_battery_min" integer;--> statement-breakpoint
|
||||
ALTER TABLE "performance_entries" ADD COLUMN "custom_system" boolean DEFAULT false NOT NULL;--> statement-breakpoint
|
||||
CREATE INDEX "perf_hardware_upscaler_idx" ON "performance_entries" USING btree ("hardware_slug","upscaler_type");
|
||||
File diff suppressed because it is too large
Load Diff
@@ -50,6 +50,13 @@
|
||||
"when": 1777300000000,
|
||||
"tag": "0006_upscaler_battery_custom_system",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "7",
|
||||
"when": 1777267706280,
|
||||
"tag": "0007_mighty_electro",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -4,11 +4,6 @@ export { gamesRoutes, gameVersionsRoutes } from "./games"
|
||||
export { hardwareRoutes } from "./hardware"
|
||||
export { performanceRoutes, performanceVerifyRoutes } from "./performance"
|
||||
export { performanceSubmitRoutes } from "./performance-submit"
|
||||
export {
|
||||
presetsRoutes,
|
||||
presetUpvoteRoutes,
|
||||
presetSettingsRoutes,
|
||||
} from "./presets"
|
||||
export { commentsRoutes } from "./comments"
|
||||
export { gameStatsRoutes } from "./game-stats"
|
||||
export { hardwareStatsRoutes } from "./hardware-stats"
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
import { Elysia, t } from "elysia"
|
||||
import { createCrudRoutes } from "./crud-builder"
|
||||
import { communityPresets } from "@/lib/db/schema"
|
||||
import { db } from "@/lib/db/index"
|
||||
import { eq, sql } from "drizzle-orm"
|
||||
import { requireRole } from "@/lib/auth/guard"
|
||||
|
||||
// ── Community Presets CRUD ────────────────────────────────────────
|
||||
export const presetsRoutes = createCrudRoutes(communityPresets, {
|
||||
prefix: "/presets",
|
||||
name: "Preset",
|
||||
auth: { read: "public", write: "user", delete: "admin" },
|
||||
search: { fields: ["name", "description"] },
|
||||
filter: { fields: ["gameId", "hardwareSlug"] },
|
||||
paramName: "presetId",
|
||||
})
|
||||
|
||||
// ── Upvote endpoint ───────────────────────────────────────────────
|
||||
export const presetUpvoteRoutes = new Elysia({ prefix: "/presets" }).post(
|
||||
"/:presetId/upvote",
|
||||
async ({ params, request, set }) => {
|
||||
const guard = await requireRole(request.headers, [
|
||||
"user",
|
||||
"contributor",
|
||||
"admin",
|
||||
])
|
||||
if (!guard.ok) {
|
||||
set.status = guard.status
|
||||
return { error: guard.error }
|
||||
}
|
||||
|
||||
const [preset] = await db
|
||||
.select()
|
||||
.from(communityPresets)
|
||||
.where(eq(communityPresets.id, params.presetId))
|
||||
.limit(1)
|
||||
|
||||
if (!preset) {
|
||||
set.status = 404
|
||||
return { error: "Preset not found" }
|
||||
}
|
||||
|
||||
const [updated] = await db
|
||||
.update(communityPresets)
|
||||
.set({
|
||||
upvotes: sql`${communityPresets.upvotes} + 1`,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(communityPresets.id, params.presetId))
|
||||
.returning()
|
||||
|
||||
return updated
|
||||
},
|
||||
{
|
||||
params: t.Object({ presetId: t.String() }),
|
||||
},
|
||||
)
|
||||
|
||||
// ── Preset Settings (nested under /presets/:presetId/settings) ────
|
||||
// Settings are stored as freeform JSON on the preset itself.
|
||||
export const presetSettingsRoutes = new Elysia({
|
||||
prefix: "/presets/:presetId/settings",
|
||||
})
|
||||
// GET the settings JSON for a preset
|
||||
.get(
|
||||
"/",
|
||||
async ({ params, set }) => {
|
||||
const [preset] = await db
|
||||
.select({ settingsJson: communityPresets.settingsJson })
|
||||
.from(communityPresets)
|
||||
.where(eq(communityPresets.id, params.presetId))
|
||||
.limit(1)
|
||||
|
||||
if (!preset) {
|
||||
set.status = 404
|
||||
return { error: "Preset not found" }
|
||||
}
|
||||
|
||||
return preset.settingsJson ?? []
|
||||
},
|
||||
{
|
||||
params: t.Object({ presetId: t.String() }),
|
||||
},
|
||||
)
|
||||
// PUT (replace) the settings JSON for a preset
|
||||
.put(
|
||||
"/",
|
||||
async ({ params, body, request, set }) => {
|
||||
const guard = await requireRole(request.headers, [
|
||||
"user",
|
||||
"contributor",
|
||||
"admin",
|
||||
])
|
||||
if (!guard.ok) {
|
||||
set.status = guard.status
|
||||
return { error: guard.error }
|
||||
}
|
||||
|
||||
// Verify preset exists and user is the creator (or admin)
|
||||
const [preset] = await db
|
||||
.select()
|
||||
.from(communityPresets)
|
||||
.where(eq(communityPresets.id, params.presetId))
|
||||
.limit(1)
|
||||
|
||||
if (!preset) {
|
||||
set.status = 404
|
||||
return { error: "Preset not found" }
|
||||
}
|
||||
|
||||
if (preset.createdBy !== guard.user.id && guard.user.role !== "admin") {
|
||||
set.status = 403
|
||||
return { error: "Not authorized to modify this preset" }
|
||||
}
|
||||
|
||||
const [updated] = await db
|
||||
.update(communityPresets)
|
||||
.set({
|
||||
settingsJson: body.settings,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(communityPresets.id, params.presetId))
|
||||
.returning()
|
||||
|
||||
return updated
|
||||
},
|
||||
{
|
||||
params: t.Object({ presetId: t.String() }),
|
||||
body: t.Object({
|
||||
settings: t.Array(
|
||||
t.Object({
|
||||
category: t.String(),
|
||||
settings: t.Array(
|
||||
t.Object({
|
||||
title: t.String(),
|
||||
value: t.Union([t.String(), t.Number(), t.Boolean()]),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
},
|
||||
)
|
||||
@@ -1,53 +0,0 @@
|
||||
import {
|
||||
integer,
|
||||
jsonb,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
unique,
|
||||
} from "drizzle-orm/pg-core"
|
||||
import { games } from "./games"
|
||||
import { hardware } from "./hardware"
|
||||
import { performanceEntries } from "./performanceEntries"
|
||||
import { user } from "./auth"
|
||||
|
||||
export const communityPresets = pgTable(
|
||||
"community_presets",
|
||||
{
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
gameId: text("game_id")
|
||||
.notNull()
|
||||
.references(() => games.id, { onDelete: "cascade" }),
|
||||
hardwareSlug: text("hardware_slug")
|
||||
.notNull()
|
||||
.references(() => hardware.slug, { onDelete: "restrict" }),
|
||||
name: text("name").notNull(),
|
||||
description: text("description"),
|
||||
createdBy: text("created_by").references(() => user.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
upvotes: integer("upvotes").default(0).notNull(),
|
||||
performanceEntryId: text("performance_entry_id").references(
|
||||
() => performanceEntries.id,
|
||||
{ onDelete: "set null" },
|
||||
),
|
||||
// Freeform settings JSON — same flexible structure as performanceEntries.settingsJson
|
||||
settingsJson: jsonb("settings_json").$type<
|
||||
{
|
||||
category: string
|
||||
settings: { title: string; value: string | number | boolean }[]
|
||||
}[]
|
||||
>(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
||||
},
|
||||
(table) => [
|
||||
unique("preset_game_hardware_name_unique").on(
|
||||
table.gameId,
|
||||
table.hardwareSlug,
|
||||
table.name,
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -5,6 +5,5 @@ export * from "./gameVersions"
|
||||
export * from "./hardware"
|
||||
export * from "./performanceEntries"
|
||||
export * from "./gamePlatformSupport"
|
||||
export * from "./communityPresets"
|
||||
export * from "./gameComments"
|
||||
export * from "./savedGames"
|
||||
|
||||
Reference in New Issue
Block a user