feat(SearchCommoServe): update fetch logic to handle proxy routing for cross-origin requests
This commit is contained in:
parent
c3a324976a
commit
5569526395
|
|
@ -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<string, string>) {
|
||||
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?<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: {
|
||||
'Client-Id': 'Commodore',
|
||||
'Accept-Encoding': 'identity',
|
||||
'X-Host': 'commoserve.files.commodore.net',
|
||||
'Client-Id': 'Commodore',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user