feat(SearchCommoServe): update fetch logic to handle proxy routing for cross-origin requests
This commit is contained in:
parent
c3a324976a
commit
5569526395
|
|
@ -8,15 +8,25 @@ import { EntryIcon } from './MediaEntry';
|
||||||
|
|
||||||
// ─── API ──────────────────────────────────────────────────────────────────────
|
// ─── API ──────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const LEET_BASE = 'https://commoserve.files.commodore.net/leet';
|
const LEET_BASE = 'http://commoserve.files.commodore.net/leet';
|
||||||
const PAGE_SIZE = 1000;
|
const PAGE_SIZE = 1000;
|
||||||
const DOWNLOAD_DIR = '/sd/downloads/commoserve';
|
const DOWNLOAD_DIR = '/sd/downloads/commoserve';
|
||||||
|
|
||||||
function leetFetch(path: string, query?: Record<string, string>) {
|
function leetFetch(path: string, query?: Record<string, string>) {
|
||||||
const url = new URL(LEET_BASE + path);
|
// Route through the device's /proxy endpoint with absolute target URLs.
|
||||||
if (query) Object.entries(query).forEach(([k, v]) => url.searchParams.set(k, v));
|
// The firmware intercepts cross-origin fetches and redirects them here,
|
||||||
return fetch(url.toString(), {
|
// 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?<url-encoded-base-path>%3F<query-params>
|
||||||
|
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: {
|
headers: {
|
||||||
|
'Accept-Encoding': 'identity',
|
||||||
|
'X-Host': 'commoserve.files.commodore.net',
|
||||||
'Client-Id': 'Commodore',
|
'Client-Id': 'Commodore',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user