From 37d2c4abd9b5beb98c4e1fa0ad0d9c7b969f07ca Mon Sep 17 00:00:00 2001 From: kuekhaoyang Date: Thu, 2 Apr 2026 19:36:20 +0800 Subject: [PATCH] Respect persisted danmaku API setting --- components/PasswordGate.tsx | 8 +++----- lib/store/settings-store.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/components/PasswordGate.tsx b/components/PasswordGate.tsx index ddb476e..e5dcf84 100644 --- a/components/PasswordGate.tsx +++ b/components/PasswordGate.tsx @@ -3,7 +3,7 @@ import { useState, useEffect } from 'react'; import { getSession, setSession } from '@/lib/store/auth-store'; import { useSubscriptionSync } from '@/lib/hooks/useSubscriptionSync'; -import { settingsStore } from '@/lib/store/settings-store'; +import { hasStoredAppSetting, settingsStore } from '@/lib/store/settings-store'; import { useIPTVStore } from '@/lib/store/iptv-store'; import { Lock } from 'lucide-react'; @@ -54,12 +54,10 @@ function syncMergeSources(rawValue: string) { } function syncDanmakuApiUrl(rawValue: string) { - if (!rawValue) return; - - const buildTimeValue = process.env.NEXT_PUBLIC_DANMAKU_API_URL || ''; + if (!rawValue || hasStoredAppSetting('danmakuApiUrl')) return; const settings = settingsStore.getSettings(); - if (!settings.danmakuApiUrl || settings.danmakuApiUrl === buildTimeValue) { + if (settings.danmakuApiUrl !== rawValue) { settingsStore.saveSettings({ ...settings, danmakuApiUrl: rawValue, diff --git a/lib/store/settings-store.ts b/lib/store/settings-store.ts index 3c5a9b0..c6f24c7 100644 --- a/lib/store/settings-store.ts +++ b/lib/store/settings-store.ts @@ -139,6 +139,24 @@ function getDefaultAppSettings(): AppSettings { }; } +export function hasStoredAppSetting(key: keyof AppSettings): boolean { + if (typeof window === 'undefined') { + return false; + } + + const stored = localStorage.getItem(SETTINGS_KEY); + if (!stored) { + return false; + } + + try { + const parsed = JSON.parse(stored); + return Object.prototype.hasOwnProperty.call(parsed, key); + } catch { + return false; + } +} + export const settingsStore = { getSettings(): AppSettings { // SSR: Return defaults