From 8ea160bd05e75540015a5367ef43db434c2c29f3 Mon Sep 17 00:00:00 2001 From: Adrian Bonpin Date: Sat, 9 May 2026 22:29:34 +0800 Subject: [PATCH] feat: accept tdpWatts and youtubeVideoId in performance submit/edit APIs --- lib/api/performance-submit.ts | 21 +++++++++++++++++++++ lib/api/performance.ts | 16 ++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/api/performance-submit.ts b/lib/api/performance-submit.ts index a432786..1da6b19 100644 --- a/lib/api/performance-submit.ts +++ b/lib/api/performance-submit.ts @@ -95,6 +95,21 @@ export const performanceSubmitRoutes = new Elysia({ prefix: "/performance" }) return { error: "Hardware not found" } } + // Validate YouTube video ID format (11 alphanumeric + dash/underscore) + if (body.youtubeVideoId) { + const ytId = body.youtubeVideoId.trim() + if (!/^[a-zA-Z0-9_-]{11}$/.test(ytId)) { + set.status = 400 + return { error: "Invalid YouTube video ID format (must be 11 characters)" } + } + } + + // Validate TDP + if (body.tdpWatts !== null && body.tdpWatts !== undefined && body.tdpWatts <= 0) { + set.status = 400 + return { error: "TDP must be greater than 0" } + } + // Create the performance entry const [entry] = await db .insert(performanceEntries) @@ -115,6 +130,10 @@ export const performanceSubmitRoutes = new Elysia({ prefix: "/performance" }) frameGenMethod: body.frameGenMethod ?? "none", loadTimeSsd: body.loadTimeSsd ?? null, loadTimeSd: body.loadTimeSd ?? null, + tdpWatts: body.tdpWatts ?? null, + youtubeVideoId: body.youtubeVideoId + ? body.youtubeVideoId.trim() + : null, launchOptions: body.launchOptions ?? null, settingsJson: body.settingsJson ?? null, userNotes: body.userNotes ?? null, @@ -203,6 +222,8 @@ export const performanceSubmitRoutes = new Elysia({ prefix: "/performance" }) ), loadTimeSsd: t.Optional(t.Union([t.Number(), t.Null()])), loadTimeSd: t.Optional(t.Union([t.Number(), t.Null()])), + tdpWatts: t.Optional(t.Union([t.Number(), t.Null()])), + youtubeVideoId: t.Optional(t.Union([t.String(), t.Null()])), launchOptions: t.Optional(t.Union([t.String(), t.Null()])), settingsJson: t.Optional( t.Union([ diff --git a/lib/api/performance.ts b/lib/api/performance.ts index 9807e79..d64fb77 100644 --- a/lib/api/performance.ts +++ b/lib/api/performance.ts @@ -288,6 +288,20 @@ export const performanceVerifyRoutes = new Elysia({ updateData.settingsJson = body.settingsJson if (body.userNotes !== undefined) updateData.userNotes = body.userNotes + if (body.tdpWatts !== undefined) updateData.tdpWatts = body.tdpWatts ?? undefined + if (body.youtubeVideoId !== undefined) { + // Validate format + if (body.youtubeVideoId !== null) { + const ytId = body.youtubeVideoId.trim() + if (!/^[a-zA-Z0-9_-]{11}$/.test(ytId)) { + set.status = 400 + return { error: "Invalid YouTube video ID format" } + } + updateData.youtubeVideoId = ytId + } else { + updateData.youtubeVideoId = null + } + } const [updated] = await db .update(performanceEntries) @@ -398,6 +412,8 @@ export const performanceVerifyRoutes = new Elysia({ launchOptions: t.Optional(t.Union([t.String(), t.Null()])), settingsJson: t.Optional(t.Union([t.Array(t.Any()), t.Null()])), userNotes: t.Optional(t.Union([t.String(), t.Null()])), + tdpWatts: t.Optional(t.Union([t.Number(), t.Null()])), + youtubeVideoId: t.Optional(t.Union([t.String(), t.Null()])), antiCheatRelevant: t.Optional(t.Boolean()), antiCheatName: t.Optional(t.Union([t.String(), t.Null()])), antiCheatStatus: t.Optional(