mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-03-06 20:17:32 +08:00
feat: middleware
This commit is contained in:
@@ -23,7 +23,7 @@ import {
|
|||||||
import { CSS } from '@dnd-kit/utilities';
|
import { CSS } from '@dnd-kit/utilities';
|
||||||
import { ChevronDown, ChevronUp, Settings, Users, Video } from 'lucide-react';
|
import { ChevronDown, ChevronUp, Settings, Users, Video } from 'lucide-react';
|
||||||
import { GripVertical } from 'lucide-react';
|
import { GripVertical } from 'lucide-react';
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { Suspense, useCallback, useEffect, useState } from 'react';
|
||||||
import Swal from 'sweetalert2';
|
import Swal from 'sweetalert2';
|
||||||
|
|
||||||
import { AdminConfig, AdminConfigResult } from '@/lib/admin.types';
|
import { AdminConfig, AdminConfigResult } from '@/lib/admin.types';
|
||||||
@@ -1005,7 +1005,7 @@ const SiteConfigComponent = ({ config }: { config: AdminConfig | null }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function AdminPage() {
|
function AdminPageClient() {
|
||||||
const [config, setConfig] = useState<AdminConfig | null>(null);
|
const [config, setConfig] = useState<AdminConfig | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@@ -1200,3 +1200,11 @@ export default function AdminPage() {
|
|||||||
</PageLayout>
|
</PageLayout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default function AdminPage() {
|
||||||
|
return (
|
||||||
|
<Suspense>
|
||||||
|
<AdminPageClient />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,9 +41,15 @@ async function generateSignature(
|
|||||||
// 生成认证Cookie(带签名)
|
// 生成认证Cookie(带签名)
|
||||||
async function generateAuthCookie(
|
async function generateAuthCookie(
|
||||||
username?: string,
|
username?: string,
|
||||||
password?: string
|
password?: string,
|
||||||
|
includePassword = false
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const authData: any = { password };
|
const authData: any = {};
|
||||||
|
|
||||||
|
// 只在需要时包含 password
|
||||||
|
if (includePassword && password) {
|
||||||
|
authData.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
if (username && process.env.PASSWORD) {
|
if (username && process.env.PASSWORD) {
|
||||||
authData.username = username;
|
authData.username = username;
|
||||||
@@ -90,7 +96,7 @@ export async function POST(req: NextRequest) {
|
|||||||
|
|
||||||
// 验证成功,设置认证cookie
|
// 验证成功,设置认证cookie
|
||||||
const response = NextResponse.json({ ok: true });
|
const response = NextResponse.json({ ok: true });
|
||||||
const cookieValue = await generateAuthCookie(undefined, password);
|
const cookieValue = await generateAuthCookie(undefined, password, true); // localstorage 模式包含 password
|
||||||
const expires = new Date();
|
const expires = new Date();
|
||||||
expires.setDate(expires.getDate() + 7); // 7天过期
|
expires.setDate(expires.getDate() + 7); // 7天过期
|
||||||
|
|
||||||
@@ -120,7 +126,7 @@ export async function POST(req: NextRequest) {
|
|||||||
) {
|
) {
|
||||||
// 验证成功,设置认证cookie
|
// 验证成功,设置认证cookie
|
||||||
const response = NextResponse.json({ ok: true });
|
const response = NextResponse.json({ ok: true });
|
||||||
const cookieValue = await generateAuthCookie(username, password);
|
const cookieValue = await generateAuthCookie(username, password, false); // 数据库模式不包含 password
|
||||||
const expires = new Date();
|
const expires = new Date();
|
||||||
expires.setDate(expires.getDate() + 7); // 7天过期
|
expires.setDate(expires.getDate() + 7); // 7天过期
|
||||||
|
|
||||||
@@ -153,7 +159,7 @@ export async function POST(req: NextRequest) {
|
|||||||
|
|
||||||
// 验证成功,设置认证cookie
|
// 验证成功,设置认证cookie
|
||||||
const response = NextResponse.json({ ok: true });
|
const response = NextResponse.json({ ok: true });
|
||||||
const cookieValue = await generateAuthCookie(username, password);
|
const cookieValue = await generateAuthCookie(username, password, false); // 数据库模式不包含 password
|
||||||
const expires = new Date();
|
const expires = new Date();
|
||||||
expires.setDate(expires.getDate() + 7); // 7天过期
|
expires.setDate(expires.getDate() + 7); // 7天过期
|
||||||
|
|
||||||
|
|||||||
@@ -39,12 +39,8 @@ async function generateSignature(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 生成认证Cookie(带签名)
|
// 生成认证Cookie(带签名)
|
||||||
async function generateAuthCookie(
|
async function generateAuthCookie(username: string): Promise<string> {
|
||||||
username: string,
|
|
||||||
password: string
|
|
||||||
): Promise<string> {
|
|
||||||
const authData: any = {
|
const authData: any = {
|
||||||
password,
|
|
||||||
username,
|
username,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
};
|
};
|
||||||
@@ -105,7 +101,7 @@ export async function POST(req: NextRequest) {
|
|||||||
|
|
||||||
// 注册成功,设置认证cookie
|
// 注册成功,设置认证cookie
|
||||||
const response = NextResponse.json({ ok: true });
|
const response = NextResponse.json({ ok: true });
|
||||||
const cookieValue = await generateAuthCookie(username, password);
|
const cookieValue = await generateAuthCookie(username);
|
||||||
const expires = new Date();
|
const expires = new Date();
|
||||||
expires.setDate(expires.getDate() + 7); // 7天过期
|
expires.setDate(expires.getDate() + 7); // 7天过期
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
export const config = {
|
export const config = {
|
||||||
cache_time: 7200,
|
cache_time: 7200,
|
||||||
api_site: {
|
api_site: {
|
||||||
|
dyttzy: {
|
||||||
|
api: 'http://caiji.dyttzyapi.com/api.php/provide/vod',
|
||||||
|
name: '电影天堂资源',
|
||||||
|
detail: 'http://caiji.dyttzyapi.com',
|
||||||
|
},
|
||||||
heimuer: {
|
heimuer: {
|
||||||
api: 'https://json.heimuer.xyz/api.php/provide/vod',
|
api: 'https://json.heimuer.xyz/api.php/provide/vod',
|
||||||
name: '黑木耳',
|
name: '黑木耳',
|
||||||
@@ -13,11 +18,6 @@ export const config = {
|
|||||||
api: 'https://cj.rycjapi.com/api.php/provide/vod',
|
api: 'https://cj.rycjapi.com/api.php/provide/vod',
|
||||||
name: '如意资源',
|
name: '如意资源',
|
||||||
},
|
},
|
||||||
dyttzy: {
|
|
||||||
api: 'http://caiji.dyttzyapi.com/api.php/provide/vod',
|
|
||||||
name: '电影天堂资源',
|
|
||||||
detail: 'http://caiji.dyttzyapi.com',
|
|
||||||
},
|
|
||||||
bfzy: {
|
bfzy: {
|
||||||
api: 'https://bfzyapi.com/api.php/provide/vod',
|
api: 'https://bfzyapi.com/api.php/provide/vod',
|
||||||
name: '暴风资源',
|
name: '暴风资源',
|
||||||
|
|||||||
@@ -146,10 +146,5 @@ function shouldSkipAuth(pathname: string): boolean {
|
|||||||
|
|
||||||
// 配置middleware匹配规则
|
// 配置middleware匹配规则
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: [
|
matcher: ['/((?!_next/static|_next/image|favicon.ico|api).*)'],
|
||||||
/*
|
|
||||||
* 匹配所有请求路径,除了静态文件
|
|
||||||
*/
|
|
||||||
'/((?!_next/static|_next/image|favicon.ico).*)',
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user