From 9998fb8649750c3f2ede3c513b47f422c550ae7d Mon Sep 17 00:00:00 2001 From: Cuishibing <643237029@qq.com> Date: Sun, 22 Mar 2026 23:04:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0URL=E5=92=8C=E6=88=BF=E4=B8=9C=E5=85=A5?= =?UTF-8?q?=E5=8F=A3=E7=99=BB=E5=BD=95=E6=A3=80=E6=9F=A5=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/upload/route.ts | 4 +++- app/owner/page.tsx | 48 ++++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/app/api/upload/route.ts b/app/api/upload/route.ts index e32c63c..ce62b1b 100644 --- a/app/api/upload/route.ts +++ b/app/api/upload/route.ts @@ -25,7 +25,9 @@ export async function POST(request: NextRequest) { const buffer = await file.arrayBuffer(); await fs.writeFile(filepath, Buffer.from(buffer)); - const url = `/uploads/${filename}`; + const host = request.headers.get('host') || 'localhost:3000'; + const protocol = request.headers.get('x-forwarded-proto') || 'http'; + const url = `${protocol}://${host}/uploads/${filename}`; return NextResponse.json({ url }); } catch (error) { console.error('Upload error:', error); diff --git a/app/owner/page.tsx b/app/owner/page.tsx index 83a3cd3..d8a271e 100644 --- a/app/owner/page.tsx +++ b/app/owner/page.tsx @@ -11,23 +11,45 @@ export default function OwnerPage() { const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); - const [user, setUser] = useState<{ username: string } | null>(null); + const [checking, setChecking] = useState(true); + const [ready, setReady] = useState(false); useEffect(() => { - checkAuth(); - }, []); - - async function checkAuth() { - try { - const res = await fetch("/api/auth/me"); - const data = await res.json(); - if (data.user) { - setUser(data.user); - router.push("/owner/dashboard"); + let cancelled = false; + + async function checkAuth() { + try { + const res = await fetch("/api/auth/me"); + const data = await res.json(); + if (!cancelled && data.user) { + router.replace("/owner/dashboard"); + return; + } + } catch (error) { + console.error("检查登录状态失败", error); + } + if (!cancelled) { + setChecking(false); + setReady(true); } - } catch (error) { - console.error("检查登录状态失败", error); } + + checkAuth(); + + return () => { + cancelled = true; + }; + }, [router]); + + if (!ready) { + return ( +
+
+
🏗️
+

检查登录状态...

+
+
+ ); } async function handleSubmit(e: React.FormEvent) {