diff --git a/README.md b/README.md index 46bb711..e211892 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,6 @@ Pull Bot 会反复触发无效的 PR 和垃圾邮件,严重干扰项目维护 | NEXT_PUBLIC_ENABLE_BLOCKAD | 开启智能去广告功能(实验性) | true / false | false | | NEXT_PUBLIC_SEARCH_MAX_PAGE | 搜索接口可拉取的最大页数 | 1-50 | 5 | | NEXT_PUBLIC_AGGREGATE_SEARCH_RESULT | 搜索结果默认是否按标题和年份聚合 | true / false | true | -| NEXT_PUBLIC_SITE_NAME | 站点名称 | 任意 string | MoonTV | ## 配置说明 @@ -205,10 +204,6 @@ MoonTV 支持标准的苹果 CMS V10 API 格式。 - 如因公开分享导致的任何法律问题,用户需自行承担责任 - 项目开发者不对用户的使用行为承担任何法律责任 -## Star History - -[](https://www.star-history.com/#senshinya/MoonTV&Date) - ## License [MIT](LICENSE) © 2025 MoonTV & Contributors diff --git a/src/app/api/login/route.ts b/src/app/api/login/route.ts index 3b5d174..3974847 100644 --- a/src/app/api/login/route.ts +++ b/src/app/api/login/route.ts @@ -24,6 +24,41 @@ export async function POST(req: NextRequest) { ); } + // 登录成功:写入 HttpOnly Cookie + const res = NextResponse.json({ ok: true }); + res.cookies.set({ + name: 'password', + value: password, + httpOnly: true, + sameSite: 'lax', + secure: process.env.NODE_ENV === 'production', + maxAge: 60 * 60 * 24 * 30, // 30 天 + path: '/', + }); + + return res; + } catch (error) { + return NextResponse.json({ error: '服务器错误' }, { status: 500 }); + } +} + +// 使用 Cookie 校验登录状态 +export async function GET(req: NextRequest) { + try { + const result = process.env.PASSWORD; + + // 未设置 PASSWORD 则直接放行 + if (!result) { + return NextResponse.json({ ok: true }); + } + + const cookiePassword = req.cookies.get('password')?.value; + const matched = cookiePassword === result; + + if (!matched) { + return NextResponse.json({ ok: false }, { status: 401 }); + } + return NextResponse.json({ ok: true }); } catch (error) { return NextResponse.json({ error: '服务器错误' }, { status: 500 }); diff --git a/src/app/layout.tsx b/src/app/layout.tsx index abf3d25..04f7d3b 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -3,22 +3,15 @@ import { Inter } from 'next/font/google'; import './globals.css'; -import AuthProvider from '../components/AuthProvider'; -import { SiteNameProvider } from '../components/SiteNameContext'; import { ThemeProvider } from '../components/ThemeProvider'; const inter = Inter({ subsets: ['latin'] }); -export const dynamic = 'force-dynamic'; -export const runtime = 'edge'; - -export function generateMetadata(): Metadata { - return { - title: process.env.NEXT_PUBLIC_SITE_NAME || 'MoonTV', - description: '影视聚合', - manifest: '/manifest.json', - }; -} +export const metadata: Metadata = { + title: 'MoonTV', + description: '影视聚合', + manifest: '/manifest.json', +}; export const viewport: Viewport = { width: 'device-width', @@ -33,24 +26,19 @@ export default function RootLayout({ }: { children: React.ReactNode; }) { - const siteName = process.env.NEXT_PUBLIC_SITE_NAME || 'MoonTV'; - return (
-