mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-06-20 19:26:20 +08:00
Respect persisted danmaku API setting
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user