From a98cf59111b02cc5137913c7d8083dc51386345d Mon Sep 17 00:00:00 2001 From: Moepchi Date: Fri, 18 Sep 2026 06:46:38 +0000 Subject: [PATCH] Design store: fix hasScreenshot/rating defaults for pre-existing themes Themes published before this schema existed have no screenshot/rating fields at all, so `t.screenshot !== null` (undefined) and the rating counters (undefined += n) were both wrong for them. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- gateway/src/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gateway/src/index.ts b/gateway/src/index.ts index 89aee42..723e618 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -439,7 +439,9 @@ function setStoreCors(res: ServerResponse) { } function storeRating(theme: StoreTheme): { average: number; count: number } { - return { average: theme.ratingCount ? theme.ratingSum / theme.ratingCount : 0, count: theme.ratingCount }; + // theme.ratingCount is undefined for themes submitted before this field existed. + const count = theme.ratingCount ?? 0; + return { average: count ? theme.ratingSum / count : 0, count }; } async function handleStoreList(res: ServerResponse) { @@ -452,8 +454,8 @@ async function handleStoreList(res: ServerResponse) { name: t.name, baseTheme: t.baseTheme, author: t.author, - description: t.description, - hasScreenshot: t.screenshot !== null, + description: t.description ?? "", + hasScreenshot: Boolean(t.screenshot), rating: storeRating(t), createdAt: t.createdAt, })); @@ -536,8 +538,8 @@ async function handleStoreRate(req: IncomingMessage, res: ServerResponse, id: st return; } - theme.ratingSum += stars; - theme.ratingCount += 1; + theme.ratingSum = (theme.ratingSum ?? 0) + stars; + theme.ratingCount = (theme.ratingCount ?? 0) + 1; try { await saveStoreThemes(themes); } catch (err) {