mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-12 23:33:43 +08:00
refactor: remove runtime fetching of environment subscriptions and envSubscriptionsSet state.
This commit is contained in:
+15
-24
@@ -44,14 +44,17 @@ export const getDefaultAdultSources = (): VideoSource[] => ADULT_SOURCES;
|
||||
|
||||
|
||||
|
||||
export function parseEnvSubscriptions(envValue: string | undefined): SourceSubscription[] {
|
||||
function getEnvSubscriptions(): SourceSubscription[] {
|
||||
if (typeof process === 'undefined' || !process.env.NEXT_PUBLIC_SUBSCRIPTION_SOURCES) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const envValue = process.env.NEXT_PUBLIC_SUBSCRIPTION_SOURCES.trim();
|
||||
if (!envValue) return [];
|
||||
const trimmed = envValue.trim();
|
||||
if (!trimmed) return [];
|
||||
|
||||
// 1. Try JSON
|
||||
try {
|
||||
const raw = JSON.parse(trimmed);
|
||||
const raw = JSON.parse(envValue);
|
||||
if (Array.isArray(raw)) {
|
||||
return raw
|
||||
.filter((item: any) => item && typeof item.name === 'string' && typeof item.url === 'string')
|
||||
@@ -62,9 +65,11 @@ export function parseEnvSubscriptions(envValue: string | undefined): SourceSubsc
|
||||
}
|
||||
|
||||
// 2. Try Simple URL (or comma separated)
|
||||
if (trimmed.includes('http')) {
|
||||
const urls = trimmed.split(',').map(u => u.trim()).filter(u => u.length > 0);
|
||||
// Check if it looks like a URL (basic check)
|
||||
if (envValue.includes('http')) {
|
||||
const urls = envValue.split(',').map(u => u.trim()).filter(u => u.length > 0);
|
||||
return urls.map((url, index) => {
|
||||
// Basic URL validation
|
||||
if (!url.startsWith('http')) return null;
|
||||
|
||||
const name = urls.length > 1
|
||||
@@ -77,14 +82,6 @@ export function parseEnvSubscriptions(envValue: string | undefined): SourceSubsc
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
function getEnvSubscriptions(): SourceSubscription[] {
|
||||
if (typeof process === 'undefined' || !process.env.NEXT_PUBLIC_SUBSCRIPTION_SOURCES) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return parseEnvSubscriptions(process.env.NEXT_PUBLIC_SUBSCRIPTION_SOURCES);
|
||||
}
|
||||
// Debugging helper
|
||||
// console.log("Environment Subscriptions:", getEnvSubscriptions());
|
||||
|
||||
@@ -160,17 +157,11 @@ export const settingsStore = {
|
||||
});
|
||||
|
||||
// Filter out invalid sources (missing baseUrl etc)
|
||||
const parsedSources = Array.isArray(parsed.sources) && parsed.sources.length > 0
|
||||
? parsed.sources
|
||||
: getDefaultSources();
|
||||
const validSources = (Array.isArray(parsed.sources) ? parsed.sources : getDefaultSources())
|
||||
.filter((s: any) => s && s.id && s.name && s.baseUrl);
|
||||
|
||||
const validSources = parsedSources.filter((s: any) => s && s.id && s.name && s.baseUrl);
|
||||
|
||||
const parsedAdultSources = Array.isArray(parsed.adultSources) && parsed.adultSources.length > 0
|
||||
? parsed.adultSources
|
||||
: getDefaultAdultSources();
|
||||
|
||||
const validAdultSources = parsedAdultSources.filter((s: any) => s && s.id && s.name && s.baseUrl);
|
||||
const validAdultSources = (Array.isArray(parsed.adultSources) ? parsed.adultSources : getDefaultAdultSources())
|
||||
.filter((s: any) => s && s.id && s.name && s.baseUrl);
|
||||
|
||||
// Validate that parsed data has all required properties
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user