pstream is dead; long live pstream taciturnaxolotl.github.io/pstream-ng/
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #972 from movie-web/config-improvements

Config improvements

authored by

William Oldham and committed by
GitHub
22cb2a25 95a75f81

+37 -33
+2 -2
public/config.js
··· 4 4 VITE_CORS_PROXY_URL: "", 5 5 6 6 // The READ API key to access TMDB 7 - VITE_TMDB_READ_API_KEY: "CHANGEME", 7 + VITE_TMDB_READ_API_KEY: "", 8 8 9 9 // The DMCA email displayed in the footer, null to hide the DMCA link 10 10 VITE_DMCA_EMAIL: null, ··· 16 16 VITE_BACKEND_URL: null, 17 17 18 18 // A comma separated list of disallowed IDs in the case of a DMCA claim - in the format "series-<id>" and "movie-<id>" 19 - VITE_DISALLOWED_IDS: "" 19 + VITE_DISALLOWED_IDS: "", 20 20 };
+5 -1
src/backend/metadata/tmdb.ts
··· 144 144 145 145 const baseURL = "https://api.themoviedb.org/3"; 146 146 147 + const apiKey = conf().TMDB_READ_API_KEY; 148 + 147 149 const headers = { 148 150 accept: "application/json", 149 - Authorization: `Bearer ${conf().TMDB_READ_API_KEY}`, 151 + Authorization: `Bearer ${apiKey}`, 150 152 }; 151 153 152 154 async function get<T>(url: string, params?: object): Promise<T> { 155 + if (!apiKey) throw new Error("TMDB API key not set"); 156 + 153 157 const res = await mwFetch<any>(encodeURI(url), { 154 158 headers, 155 159 baseURL,
+1 -1
src/hooks/auth/useBackendUrl.ts
··· 1 1 import { conf } from "@/setup/config"; 2 2 import { useAuthStore } from "@/stores/auth"; 3 3 4 - export function useBackendUrl(): string | undefined { 4 + export function useBackendUrl(): string | null { 5 5 const backendUrl = useAuthStore((s) => s.backendUrl); 6 6 return backendUrl ?? conf().BACKEND_URL; 7 7 }
+1 -1
src/pages/parts/admin/TMDBTestPart.tsx
··· 25 25 errorText: "", 26 26 }); 27 27 28 - if (tmdbApiKey.length === 0) { 28 + if (!tmdbApiKey || tmdbApiKey.length === 0) { 29 29 return setStatus({ 30 30 hasTested: true, 31 31 success: false,
+1 -1
src/pages/parts/settings/SidebarPart.tsx
··· 14 14 15 15 const rem = 16; 16 16 17 - function SecureBadge(props: { url: string | undefined }) { 17 + function SecureBadge(props: { url: string | null }) { 18 18 const { t } = useTranslation(); 19 19 const secure = props.url ? props.url.startsWith("https://") : false; 20 20 return (
+27 -27
src/setup/config.ts
··· 31 31 DONATION_LINK: string; 32 32 DISCORD_LINK: string; 33 33 DMCA_EMAIL: string | null; 34 - TMDB_READ_API_KEY: string; 34 + TMDB_READ_API_KEY: string | null; 35 35 NORMAL_ROUTER: boolean; 36 36 PROXY_URLS: string[]; 37 - BACKEND_URL: string; 37 + BACKEND_URL: string | null; 38 38 DISALLOWED_IDS: string[]; 39 39 TURNSTILE_KEY: string | null; 40 40 CDN_REPLACEMENTS: Array<string[]>; ··· 66 66 HAS_ONBOARDING: import.meta.env.VITE_HAS_ONBOARDING, 67 67 }; 68 68 69 + function coerceUndefined(value: string | null | undefined): string | undefined { 70 + if (value == null) return undefined; 71 + if (value.length === 0) return undefined; 72 + return value; 73 + } 74 + 69 75 // loads from different locations, in order: environment (VITE_{KEY}), window (public/config.js) 70 76 function getKeyValue(key: keyof Config): string | undefined { 71 - let windowValue = (window as any)?.__CONFIG__?.[`VITE_${key}`]; 72 - if ( 73 - windowValue !== null && 74 - windowValue !== undefined && 75 - windowValue.length === 0 76 - ) 77 - windowValue = undefined; 78 - return env[key] ?? windowValue ?? undefined; 77 + const windowValue = (window as any)?.__CONFIG__?.[`VITE_${key}`]; 78 + 79 + return coerceUndefined(env[key]) ?? coerceUndefined(windowValue) ?? undefined; 79 80 } 80 81 81 - function getKey(key: keyof Config, defaultString?: string): string { 82 - return getKeyValue(key)?.toString() ?? defaultString ?? ""; 82 + function getKey(key: keyof Config): string | null; 83 + function getKey(key: keyof Config, defaultString: string): string; 84 + function getKey(key: keyof Config, defaultString?: string): string | null { 85 + return getKeyValue(key)?.toString() ?? defaultString ?? null; 83 86 } 84 87 85 88 export function conf(): RuntimeConfig { 86 - const dmcaEmail = getKey("DMCA_EMAIL"); 87 - const chromeExtension = getKey("ONBOARDING_CHROME_EXTENSION_INSTALL_LINK"); 88 - const firefoxExtension = getKey("ONBOARDING_FIREFOX_EXTENSION_INSTALL_LINK"); 89 - const proxyInstallLink = getKey("ONBOARDING_PROXY_INSTALL_LINK"); 90 - const turnstileKey = getKey("TURNSTILE_KEY"); 91 89 return { 92 90 APP_VERSION, 93 91 GITHUB_LINK, 94 92 DONATION_LINK, 95 93 DISCORD_LINK, 96 - DMCA_EMAIL: dmcaEmail.length > 0 ? dmcaEmail : null, 97 - ONBOARDING_CHROME_EXTENSION_INSTALL_LINK: 98 - chromeExtension.length > 0 ? chromeExtension : null, 99 - ONBOARDING_FIREFOX_EXTENSION_INSTALL_LINK: 100 - firefoxExtension.length > 0 ? firefoxExtension : null, 101 - ONBOARDING_PROXY_INSTALL_LINK: 102 - proxyInstallLink.length > 0 ? proxyInstallLink : null, 94 + DMCA_EMAIL: getKey("DMCA_EMAIL"), 95 + ONBOARDING_CHROME_EXTENSION_INSTALL_LINK: getKey( 96 + "ONBOARDING_CHROME_EXTENSION_INSTALL_LINK", 97 + ), 98 + ONBOARDING_FIREFOX_EXTENSION_INSTALL_LINK: getKey( 99 + "ONBOARDING_FIREFOX_EXTENSION_INSTALL_LINK", 100 + ), 101 + ONBOARDING_PROXY_INSTALL_LINK: getKey("ONBOARDING_PROXY_INSTALL_LINK"), 103 102 BACKEND_URL: getKey("BACKEND_URL", BACKEND_URL), 104 103 TMDB_READ_API_KEY: getKey("TMDB_READ_API_KEY"), 105 - PROXY_URLS: getKey("CORS_PROXY_URL") 104 + PROXY_URLS: getKey("CORS_PROXY_URL", "") 106 105 .split(",") 107 - .map((v) => v.trim()), 106 + .map((v) => v.trim()) 107 + .filter((v) => v.length > 0), 108 108 NORMAL_ROUTER: getKey("NORMAL_ROUTER", "false") === "true", 109 109 HAS_ONBOARDING: getKey("HAS_ONBOARDING", "false") === "true", 110 - TURNSTILE_KEY: turnstileKey.length > 0 ? turnstileKey : null, 110 + TURNSTILE_KEY: getKey("TURNSTILE_KEY"), 111 111 DISALLOWED_IDS: getKey("DISALLOWED_IDS", "") 112 112 .split(",") 113 113 .map((v) => v.trim())