From 5af47cdcd1ee91388185602f9172093c054042ed Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Jan 2026 20:23:40 +0000 Subject: [PATCH] Address Steam Workshop search review notes Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com> --- .../steam_workshop/lib/SteamWorkshopService.php | 15 ++++++++------- modules/steam_workshop/steam_workshop.js | 8 +++++--- .../steam_workshop/views/partials/mod_picker.php | 6 +++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/modules/steam_workshop/lib/SteamWorkshopService.php b/modules/steam_workshop/lib/SteamWorkshopService.php index ff3b95a2..23b9adb6 100644 --- a/modules/steam_workshop/lib/SteamWorkshopService.php +++ b/modules/steam_workshop/lib/SteamWorkshopService.php @@ -5,6 +5,7 @@ class SteamWorkshopService { private const MIN_INTERVAL = 15; private const MAX_INTERVAL = 360; + private const STEAM_WORKSHOP_DETAIL_URL = 'https://steamcommunity.com/sharedfiles/filedetails/'; private OGPDatabase $db; private string $configDir; @@ -714,16 +715,16 @@ class SteamWorkshopService private function fetchWorkshopItemByScrape(string $id): array { - $id = preg_replace('/[^0-9]/', '', $id); + $sanitizedId = preg_replace('/[^0-9]/', '', $id); $request = [ 'backend' => 'scraper_http', - 'url' => 'https://steamcommunity.com/sharedfiles/filedetails/', - 'params' => ['id' => $id], + 'url' => self::STEAM_WORKSHOP_DETAIL_URL, + 'params' => ['id' => $sanitizedId], 'http_code' => null, 'transport_error' => null, ]; - if ($id === '') { + if ($sanitizedId === '') { $request['summary'] = $this->formatRequestSummary($request); return ['item' => null, 'request' => $request, 'error' => 'Invalid Workshop ID.']; } @@ -745,12 +746,12 @@ class SteamWorkshopService $title = $this->parseWorkshopTitle((string)$response['body']); if ($title === '') { - $title = '@' . $id; + $title = '@' . $sanitizedId; } return [ 'item' => [ - 'id' => $id, + 'id' => $sanitizedId, 'label' => $title, 'author' => '', 'preview_url' => '', @@ -960,7 +961,7 @@ class SteamWorkshopService $results = []; foreach ($sliceIds as $id) { - $detailResponse = $this->httpGet('https://steamcommunity.com/sharedfiles/filedetails/', ['id' => $id], $this->getScraperUserAgent()); + $detailResponse = $this->httpGet(self::STEAM_WORKSHOP_DETAIL_URL, ['id' => $id], $this->getScraperUserAgent()); $title = ''; if ($detailResponse['error'] === null && $detailResponse['http_code'] >= 200 && $detailResponse['http_code'] < 300 && $detailResponse['body'] !== null) { $title = $this->parseWorkshopTitle((string)$detailResponse['body']); diff --git a/modules/steam_workshop/steam_workshop.js b/modules/steam_workshop/steam_workshop.js index 554187ce..ef2b3059 100644 --- a/modules/steam_workshop/steam_workshop.js +++ b/modules/steam_workshop/steam_workshop.js @@ -5,6 +5,7 @@ function Picker(root) { this.root = root; this.endpoint = root.getAttribute('data-endpoint') || ''; + this.detailBase = root.getAttribute('data-detail-base') || 'https://steamcommunity.com/sharedfiles/filedetails/?id='; this.lang = { add: root.getAttribute('data-lang-add') || 'Add', remove: root.getAttribute('data-lang-remove') || 'Remove', @@ -260,9 +261,10 @@ this.requestSummary.textContent = base; return; } - var isId = /^\d+$/.test(term); - if (isId) { - this.requestSummary.textContent = 'https://steamcommunity.com/sharedfiles/filedetails/?id=' + encodeURIComponent(term); + // Numeric-only terms are treated as Workshop item IDs and link to detail pages instead of search. + var isWorkshopId = /^\d+$/.test(term); + if (isWorkshopId) { + this.requestSummary.textContent = this.detailBase + encodeURIComponent(term); return; } this.requestSummary.textContent = base + encodeURIComponent(term); diff --git a/modules/steam_workshop/views/partials/mod_picker.php b/modules/steam_workshop/views/partials/mod_picker.php index 58448921..82efd95c 100644 --- a/modules/steam_workshop/views/partials/mod_picker.php +++ b/modules/steam_workshop/views/partials/mod_picker.php @@ -15,7 +15,7 @@ if ($scriptPath[0] !== '/') { } $endpoint = sprintf('%s?m=steam_workshop&p=main&action=search&home_id=%d', $scriptPath, $homeId); $steamBase = 'https://steamcommunity.com/workshop/browse/?appid='; -$steamAppId = isset($appId) && $appId !== '' ? $appId : '0'; +$steamAppIdParam = $appId ?? ''; $initialItems = []; foreach ($config['workshop_items'] ?? [] as $item) { if (!is_array($item)) { @@ -46,7 +46,7 @@ $langAttrs = [ 'sync' => $lang['mod_picker_toggle_label'] ?? 'Sync', ]; ?> -