观影室改为仅环境变量配置
This commit is contained in:
@@ -5852,204 +5852,6 @@ const LiveSourceConfig = ({
|
||||
);
|
||||
};
|
||||
|
||||
// 观影室配置组件
|
||||
const WatchRoomConfig = ({
|
||||
config,
|
||||
refreshConfig,
|
||||
}: {
|
||||
config: AdminConfig | null;
|
||||
refreshConfig: () => Promise<void>;
|
||||
}) => {
|
||||
const { alertModal, showAlert, hideAlert } = useAlertModal();
|
||||
const { isLoading, withLoading } = useLoadingState();
|
||||
const [settings, setSettings] = useState({
|
||||
enabled: false,
|
||||
serverType: 'internal' as 'internal' | 'external',
|
||||
externalServerUrl: '',
|
||||
externalServerAuth: '',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (config?.WatchRoomConfig) {
|
||||
setSettings({
|
||||
enabled: config.WatchRoomConfig.enabled || false,
|
||||
serverType: config.WatchRoomConfig.serverType || 'internal',
|
||||
externalServerUrl: config.WatchRoomConfig.externalServerUrl || '',
|
||||
externalServerAuth: config.WatchRoomConfig.externalServerAuth || '',
|
||||
});
|
||||
}
|
||||
}, [config]);
|
||||
|
||||
const handleSave = async () => {
|
||||
await withLoading('saveWatchRoomConfig', async () => {
|
||||
try {
|
||||
// 验证外部服务器配置
|
||||
if (settings.serverType === 'external' && !settings.externalServerUrl.trim()) {
|
||||
showError('外部服务器地址不能为空', showAlert);
|
||||
return;
|
||||
}
|
||||
|
||||
const resp = await fetch('/api/admin/watch-room', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(settings),
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
const data = await resp.json().catch(() => ({}));
|
||||
throw new Error(data.error || `保存失败: ${resp.status}`);
|
||||
}
|
||||
|
||||
showSuccess('保存成功,刷新页面后生效', showAlert);
|
||||
await refreshConfig();
|
||||
} catch (err) {
|
||||
showError(err instanceof Error ? err.message : '保存失败', showAlert);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (!config) {
|
||||
return (
|
||||
<div className='text-center text-gray-500 dark:text-gray-400'>
|
||||
加载中...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='space-y-6'>
|
||||
{/* 功能开关 */}
|
||||
<div className='flex items-center justify-between p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg border border-blue-200 dark:border-blue-800'>
|
||||
<div>
|
||||
<h4 className='text-sm font-medium text-gray-900 dark:text-gray-100'>
|
||||
启用观影室功能
|
||||
</h4>
|
||||
<p className='text-xs text-gray-600 dark:text-gray-400 mt-1'>
|
||||
开启后,用户可以创建和加入观影室,实现多人同步观看
|
||||
</p>
|
||||
</div>
|
||||
<label className='relative inline-flex items-center cursor-pointer'>
|
||||
<input
|
||||
type='checkbox'
|
||||
className='sr-only peer'
|
||||
checked={settings.enabled}
|
||||
onChange={(e) =>
|
||||
setSettings({ ...settings, enabled: e.target.checked })
|
||||
}
|
||||
/>
|
||||
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{/* 服务器类型选择 */}
|
||||
<div>
|
||||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2'>
|
||||
服务器类型
|
||||
</label>
|
||||
<select
|
||||
value={settings.serverType}
|
||||
onChange={(e) =>
|
||||
setSettings({
|
||||
...settings,
|
||||
serverType: e.target.value as 'internal' | 'external',
|
||||
})
|
||||
}
|
||||
className='w-full px-3 py-2 text-sm text-gray-900 dark:text-gray-100 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent'
|
||||
>
|
||||
<option value='internal'>内部服务器(与网站集成)</option>
|
||||
<option value='external'>外部服务器(独立部署)</option>
|
||||
</select>
|
||||
<p className='text-xs text-gray-500 dark:text-gray-400 mt-1'>
|
||||
{settings.serverType === 'internal'
|
||||
? '使用内置的 Socket.IO 服务器,无需额外配置'
|
||||
: '使用独立部署的 Socket.IO 服务器,适合高并发场景'}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* 外部服务器配置 */}
|
||||
{settings.serverType === 'external' && (
|
||||
<div className='space-y-4 p-4 bg-gray-50 dark:bg-gray-800/50 rounded-lg border border-gray-200 dark:border-gray-700'>
|
||||
<div>
|
||||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2'>
|
||||
服务器地址 *
|
||||
</label>
|
||||
<input
|
||||
type='text'
|
||||
value={settings.externalServerUrl}
|
||||
onChange={(e) =>
|
||||
setSettings({ ...settings, externalServerUrl: e.target.value })
|
||||
}
|
||||
placeholder='http://your-server:3001'
|
||||
className='w-full px-3 py-2 text-sm text-gray-900 dark:text-gray-100 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent'
|
||||
/>
|
||||
<p className='text-xs text-gray-500 dark:text-gray-400 mt-1'>
|
||||
外部 Socket.IO 服务器的完整地址(包含协议和端口)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2'>
|
||||
鉴权密钥
|
||||
</label>
|
||||
<input
|
||||
type='password'
|
||||
value={settings.externalServerAuth}
|
||||
onChange={(e) =>
|
||||
setSettings({ ...settings, externalServerAuth: e.target.value })
|
||||
}
|
||||
placeholder='可选:服务器鉴权密钥'
|
||||
className='w-full px-3 py-2 text-sm text-gray-900 dark:text-gray-100 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent'
|
||||
/>
|
||||
<p className='text-xs text-gray-500 dark:text-gray-400 mt-1'>
|
||||
如果外部服务器需要鉴权,请填写密钥
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 使用说明 */}
|
||||
<div className='p-4 bg-yellow-50 dark:bg-yellow-900/20 rounded-lg border border-yellow-200 dark:border-yellow-800'>
|
||||
<h5 className='text-sm font-medium text-yellow-800 dark:text-yellow-300 mb-2'>
|
||||
使用说明
|
||||
</h5>
|
||||
<ul className='text-xs text-yellow-700 dark:text-yellow-400 space-y-1 list-disc list-inside'>
|
||||
<li>观影室功能允许多人同步观看视频,支持播放控制同步和聊天</li>
|
||||
<li>内部服务器模式无需额外配置,适合中小型部署</li>
|
||||
<li>外部服务器模式需要单独部署 Socket.IO 服务器(参考 server/watch-room-standalone-server.js)</li>
|
||||
<li>更改配置后需要重启服务器才能生效</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* 保存按钮 */}
|
||||
<div className='flex justify-end'>
|
||||
<button
|
||||
onClick={handleSave}
|
||||
disabled={isLoading('saveWatchRoomConfig')}
|
||||
className={`px-4 py-2 ${
|
||||
isLoading('saveWatchRoomConfig')
|
||||
? buttonStyles.disabled
|
||||
: buttonStyles.success
|
||||
} rounded-lg transition-colors`}
|
||||
>
|
||||
{isLoading('saveWatchRoomConfig') ? '保存中…' : '保存'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* 通用弹窗组件 */}
|
||||
<AlertModal
|
||||
isOpen={alertModal.isOpen}
|
||||
onClose={hideAlert}
|
||||
type={alertModal.type}
|
||||
title={alertModal.title}
|
||||
message={alertModal.message}
|
||||
timer={alertModal.timer}
|
||||
showConfirm={alertModal.showConfirm}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
function AdminPageClient() {
|
||||
const { alertModal, showAlert, hideAlert } = useAlertModal();
|
||||
const { isLoading, withLoading } = useLoadingState();
|
||||
@@ -6067,7 +5869,6 @@ function AdminPageClient() {
|
||||
configFile: false,
|
||||
dataMigration: false,
|
||||
customAdFilter: false,
|
||||
watchRoomConfig: false,
|
||||
});
|
||||
|
||||
// 获取管理员配置
|
||||
@@ -6256,18 +6057,6 @@ function AdminPageClient() {
|
||||
<LiveSourceConfig config={config} refreshConfig={fetchConfig} />
|
||||
</CollapsibleTab>
|
||||
|
||||
{/* 观影室配置标签 */}
|
||||
<CollapsibleTab
|
||||
title='观影室配置'
|
||||
icon={
|
||||
<Users size={20} className='text-gray-600 dark:text-gray-400' />
|
||||
}
|
||||
isExpanded={expandedTabs.watchRoomConfig}
|
||||
onToggle={() => toggleTab('watchRoomConfig')}
|
||||
>
|
||||
<WatchRoomConfig config={config} refreshConfig={fetchConfig} />
|
||||
</CollapsibleTab>
|
||||
|
||||
{/* 分类配置标签 */}
|
||||
<CollapsibleTab
|
||||
title='分类配置'
|
||||
|
||||
Reference in New Issue
Block a user