diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index b99ad2a..18cbbce 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -35,6 +35,7 @@ import { FolderOpen, Globe, Mail, + Music, Palette, Settings, Tv, @@ -353,9 +354,6 @@ interface SiteConfig { OIDCClientId?: string; OIDCClientSecret?: string; OIDCButtonText?: string; - TuneHubEnabled?: boolean; - TuneHubBaseUrl?: string; - TuneHubApiKey?: string; } // 视频源数据类型 @@ -6745,6 +6743,312 @@ const ThemeConfigComponent = ({ ); }; +// 音乐配置组件 +const MusicConfigComponent = ({ + config, + refreshConfig, +}: { + config: AdminConfig | null; + refreshConfig: () => Promise; +}) => { + const { alertModal, showAlert, hideAlert } = useAlertModal(); + const { isLoading, withLoading } = useLoadingState(); + + const [musicSettings, setMusicSettings] = useState({ + TuneHubEnabled: false, + TuneHubBaseUrl: 'https://tunehub.sayqz.com/api', + TuneHubApiKey: '', + OpenListCacheEnabled: false, + OpenListCacheURL: '', + OpenListCacheUsername: '', + OpenListCachePassword: '', + OpenListCachePath: '/music-cache', + }); + + // 从配置加载音乐设置 + useEffect(() => { + if (config?.MusicConfig) { + setMusicSettings({ + TuneHubEnabled: config.MusicConfig.TuneHubEnabled ?? false, + TuneHubBaseUrl: config.MusicConfig.TuneHubBaseUrl ?? 'https://tunehub.sayqz.com/api', + TuneHubApiKey: config.MusicConfig.TuneHubApiKey ?? '', + OpenListCacheEnabled: config.MusicConfig.OpenListCacheEnabled ?? false, + OpenListCacheURL: config.MusicConfig.OpenListCacheURL ?? '', + OpenListCacheUsername: config.MusicConfig.OpenListCacheUsername ?? '', + OpenListCachePassword: config.MusicConfig.OpenListCachePassword ?? '', + OpenListCachePath: config.MusicConfig.OpenListCachePath ?? '/music-cache', + }); + } + }, [config]); + + const handleSave = async () => { + await withLoading('saveMusicConfig', async () => { + try { + const resp = await fetch('/api/admin/music', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ ...musicSettings }), + }); + + if (!resp.ok) { + const data = await resp.json().catch(() => ({})); + throw new Error(data.error || '保存失败'); + } + + showAlert({ type: 'success', title: '保存成功', message: '音乐配置已更新', timer: 2000 }); + await refreshConfig(); + } catch (error: any) { + showAlert({ type: 'error', title: '保存失败', message: error.message || '未知错误', showConfirm: true }); + } + }); + }; + + return ( +
+ {/* TuneHub 音乐配置 */} +
+

+ TuneHub 音乐配置 +

+ + {/* 开启音乐功能 */} +
+
+ + +
+

+ 开启后将在首页显示音乐视听入口,支持网易云、QQ音乐、酷我音乐 +

+
+ + {/* TuneHub Base URL */} +
+ + + setMusicSettings((prev) => ({ + ...prev, + TuneHubBaseUrl: e.target.value, + })) + } + className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 focus:border-transparent' + /> +

+ TuneHub API 的基础地址,默认为 https://tunehub.sayqz.com/api。也可以通过环境变量 TUNEHUB_BASE_URL 配置 +

+
+ + {/* TuneHub API Key */} +
+ + + setMusicSettings((prev) => ({ + ...prev, + TuneHubApiKey: e.target.value, + })) + } + className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 focus:border-transparent' + /> +

+ 用于解析歌曲播放链接的 API Key(消耗积分)。搜索、榜单、歌单等功能不需要 Key。也可以通过环境变量 TUNEHUB_API_KEY 配置 +

+
+
+ + {/* OpenList 缓存配置 */} +
+

+ OpenList 缓存配置 +

+ + {/* 开启 OpenList 缓存 */} +
+
+ + +
+

+ 开启后将音乐解析结果(播放链接、歌词、元信息)和音频文件缓存到 OpenList,减少 API 调用次数并支持离线播放 +

+
+ + {/* OpenList URL */} +
+ + + setMusicSettings((prev) => ({ + ...prev, + OpenListCacheURL: e.target.value, + })) + } + className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 focus:border-transparent' + /> +

+ OpenList 服务器的完整地址(例如:https://your-openlist-server.com) +

+
+ + {/* OpenList 用户名 */} +
+ + + setMusicSettings((prev) => ({ + ...prev, + OpenListCacheUsername: e.target.value, + })) + } + className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 focus:border-transparent' + /> +
+ + {/* OpenList 密码 */} +
+ + + setMusicSettings((prev) => ({ + ...prev, + OpenListCachePassword: e.target.value, + })) + } + className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 focus:border-transparent' + /> +

+ 用于登录 OpenList 并获取访问权限 +

+
+ + {/* OpenList 缓存目录 */} +
+ + + setMusicSettings((prev) => ({ + ...prev, + OpenListCachePath: e.target.value, + })) + } + className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 focus:border-transparent' + /> +

+ 音乐缓存在 OpenList 中的存储目录(例如:/music-cache) +

+
+
+ + {/* 操作按钮 */} +
+ +
+ + {/* 弹窗 */} + +
+ ); +}; + // 新增站点配置组件 const SiteConfigComponent = ({ config, @@ -6793,9 +7097,6 @@ const SiteConfigComponent = ({ OIDCClientId: '', OIDCClientSecret: '', OIDCButtonText: '', - TuneHubEnabled: false, - TuneHubBaseUrl: 'https://tunehub.sayqz.com/api', - TuneHubApiKey: '', }); // 豆瓣数据源相关状态 @@ -7672,93 +7973,6 @@ const SiteConfigComponent = ({ - {/* TuneHub 音乐配置 */} -
-

- TuneHub 音乐配置 -

- - {/* 开启 TuneHub */} -
-
- - -
-

- 开启后将在首页显示音乐视听入口,支持网易云、QQ音乐、酷我音乐 -

-
- - {/* TuneHub Base URL */} -
- - - setSiteSettings((prev) => ({ - ...prev, - TuneHubBaseUrl: e.target.value, - })) - } - className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 focus:border-transparent' - /> -

- TuneHub API 的基础地址,默认为 https://tunehub.sayqz.com/api。也可以通过环境变量 TUNEHUB_BASE_URL 配置 -

-
- - {/* TuneHub API Key */} -
- - - setSiteSettings((prev) => ({ - ...prev, - TuneHubApiKey: e.target.value, - })) - } - className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 focus:border-transparent' - /> -

- 用于解析歌曲播放链接的 API Key(消耗积分)。搜索、榜单、歌单等功能不需要 Key。也可以通过环境变量 TUNEHUB_API_KEY 配置 -

-
-
- {/* 操作按钮 */}