From bce557cc2dc767628bed6aac87301a1be7c5431b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Tue, 4 Nov 2025 05:03:50 +0800 Subject: init commit --- src/config/media-api/browser.ts | 1 + src/config/media-api/search-jwt.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/config/media-api/browser.ts create mode 100644 src/config/media-api/search-jwt.ts (limited to 'src/config/media-api') diff --git a/src/config/media-api/browser.ts b/src/config/media-api/browser.ts new file mode 100644 index 0000000..91cf7c2 --- /dev/null +++ b/src/config/media-api/browser.ts @@ -0,0 +1 @@ +export const MEDIA_API_JWT = import.meta.env.BROWSER_MEDIA_API_JWT ?? ''; diff --git a/src/config/media-api/search-jwt.ts b/src/config/media-api/search-jwt.ts new file mode 100644 index 0000000..1f7e3d2 --- /dev/null +++ b/src/config/media-api/search-jwt.ts @@ -0,0 +1,27 @@ +export function shouldUseSearchJWT(url: URL): boolean { + // We should only ever use the "search" JWT on the server + if (!import.meta.env.SSR) { + return false; + } + + // Search API Endpoint + if (url.pathname.endsWith('/search')) { + return true; + } + + // All other endpoints should use the default JWT + return false; +} + +/** + * Creates the `Authorization` header using the App Store "search JWT" + * + * Note: this function specifically returns a bad value for a "browser" + * build so that the "search JWT" is removed from the browser payload + * by dead-code elimination + */ +export function makeSearchJWTAuthorizationHeader() { + return import.meta.env.SSR + ? { Authorization: `Bearer ${import.meta.env.SEARCH_MEDIA_API_JWT}` } + : { Authorization: '' }; +} -- cgit v1.2.3