From 748616df9d3df80d0e9e5861ce9e15433f4bb9a3 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sat, 5 Sep 2026 19:16:14 -0400 Subject: [PATCH] feat(games): accept full Steam store URL in create() Allow callers to pass either a raw Steam app ID or a full store URL (e.g. https://store.steampowered.com/app/730/...) in req.body.steamId. In create() in controllers/games.js: - normalize input into a local steamId variable: if the value includes store.steampowered.com, extract the numeric ID via match(/\d+/)[0], otherwise use the value as-is - use the normalized steamId for both duplicate checks: user-scoped lookup (steamId + accessedBy.user) and global lookup This lets users paste a copied store link directly without manually stripping the app ID, while keeping existing raw-ID behavior unchanged. --- controllers/games.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/controllers/games.js b/controllers/games.js index 1e393cf..530ef6b 100644 --- a/controllers/games.js +++ b/controllers/games.js @@ -77,6 +77,11 @@ export const show = asyncHandler(async (req, res, next) => { */ export const create = asyncHandler(async (req, res, next) => { let oldGame; + let steamId; + + if (req.body.steamId.includes("store.steampowered.com")) + steamId = req.body.steamId.match(/\d+/)[0]; + else steamId = req.body.steamId; if (req.body.shortDesc && isValid(req.body.shortDesc)) req.body.shortDesc = decode(req.body.shortDesc); @@ -115,9 +120,9 @@ export const create = asyncHandler(async (req, res, next) => { )) : ""; - req.body.steamId.length > 0 + steamId.length > 0 ? (oldGame = await Game.findOne({ - steamId: req.body.steamId, + steamId: steamId, "accessedBy.user": req.user.id, })) : (oldGame = await Game.findOne({ @@ -133,8 +138,8 @@ export const create = asyncHandler(async (req, res, next) => { ), ); - req.body.steamId.length > 0 - ? (oldGame = await Game.findOne({ steamId: req.body.steamId })) + steamId.length > 0 + ? (oldGame = await Game.findOne({ steamId: steamId })) : (oldGame = await Game.findOne({ title: req.body.title })); if (oldGame) {