From 556952639576cb27e33710471485311610e103c3 Mon Sep 17 00:00:00 2001 From: Jaime Idolpx Date: Mon, 22 Jun 2026 14:17:21 -0400 Subject: [PATCH] feat(SearchCommoServe): update fetch logic to handle proxy routing for cross-origin requests --- src/app/components/SearchCommoServe.tsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/app/components/SearchCommoServe.tsx b/src/app/components/SearchCommoServe.tsx index cd05bf3..a9e7ab9 100644 --- a/src/app/components/SearchCommoServe.tsx +++ b/src/app/components/SearchCommoServe.tsx @@ -8,16 +8,26 @@ import { EntryIcon } from './MediaEntry'; // ─── API ────────────────────────────────────────────────────────────────────── -const LEET_BASE = 'https://commoserve.files.commodore.net/leet'; +const LEET_BASE = 'http://commoserve.files.commodore.net/leet'; const PAGE_SIZE = 1000; const DOWNLOAD_DIR = '/sd/downloads/commoserve'; function leetFetch(path: string, query?: Record) { - const url = new URL(LEET_BASE + path); - if (query) Object.entries(query).forEach(([k, v]) => url.searchParams.set(k, v)); - return fetch(url.toString(), { + // Route through the device's /proxy endpoint with absolute target URLs. + // The firmware intercepts cross-origin fetches and redirects them here, + // but its rewriter has a relative-path bug: it resolves new paths against + // the previously proxied URL, so /search/aql/0/1000 ends up appended after + // /search/aql/presets instead of replacing it. Constructing the proxy URL + // ourselves avoids this entirely. + // Proxy format: /proxy?%3F + let proxyParam = encodeURIComponent(LEET_BASE + path); + if (query && Object.keys(query).length > 0) + proxyParam += '%3F' + new URLSearchParams(query).toString(); + return fetch(`${window.location.origin}/proxy?${proxyParam}`, { headers: { - 'Client-Id': 'Commodore', + 'Accept-Encoding': 'identity', + 'X-Host': 'commoserve.files.commodore.net', + 'Client-Id': 'Commodore', }, }); }