/* eslint-disable no-console */ import { NextRequest, NextResponse } from 'next/server'; import { getConfig } from '@/lib/config'; import { CURRENT_VERSION } from '@/lib/version' export const runtime = 'nodejs'; export async function GET(request: NextRequest) { console.log('server-config called: ', request.url); const storageType = process.env.NEXT_PUBLIC_STORAGE_TYPE || 'localstorage'; // 观影室配置从环境变量读取 const watchRoomConfig = { enabled: process.env.WATCH_ROOM_ENABLED === 'true', serverType: (process.env.WATCH_ROOM_SERVER_TYPE as 'internal' | 'external') || 'internal', externalServerUrl: process.env.WATCH_ROOM_EXTERNAL_SERVER_URL, externalServerAuth: process.env.WATCH_ROOM_EXTERNAL_SERVER_AUTH, }; // 如果使用 localStorage,返回默认配置 if (storageType === 'localstorage') { return NextResponse.json({ SiteName: process.env.NEXT_PUBLIC_SITE_NAME || 'MoonTVPlus', StorageType: 'localstorage', Version: CURRENT_VERSION, WatchRoom: watchRoomConfig, EnableOfflineDownload: process.env.NEXT_PUBLIC_ENABLE_OFFLINE_DOWNLOAD === 'true', }); } // 非 localStorage 模式,从数据库读取配置 const config = await getConfig(); const result = { SiteName: config.SiteConfig.SiteName, StorageType: storageType, Version: CURRENT_VERSION, WatchRoom: watchRoomConfig, EnableOfflineDownload: process.env.NEXT_PUBLIC_ENABLE_OFFLINE_DOWNLOAD === 'true', EnableRegistration: config.SiteConfig.EnableRegistration || false, RegistrationRequireTurnstile: config.SiteConfig.RegistrationRequireTurnstile || false, LoginRequireTurnstile: config.SiteConfig.LoginRequireTurnstile || false, TurnstileSiteKey: config.SiteConfig.TurnstileSiteKey || '', EnableOIDCLogin: config.SiteConfig.EnableOIDCLogin || false, EnableOIDCRegistration: config.SiteConfig.EnableOIDCRegistration || false, OIDCButtonText: config.SiteConfig.OIDCButtonText || '', }; return NextResponse.json(result); }