fix(plugins): close R2 workspace gaps

This commit is contained in:
brother7 committed 2026-09-03 15:07:29 +08:00
1 parent c5020ae22c
commit 0bfabc0df2
10 files changed
+405 -15

No files matched your search

+18 -4
View File
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef, useState, type FormEvent } from 'react';
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { Loader2, RefreshCw } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
@@ -15,6 +15,7 @@ const LOGIN_ERROR_MESSAGE = '登录失败,请稍后重试。';
const CAPTCHA_ERROR_MESSAGE = '图形验证码加载失败,请重试。';
const SMS_ERROR_MESSAGE = '验证码发送失败,请稍后重试。';
const PHONE_PATTERN = /^1\d{10}$/;
const DEFAULT_LOGIN_RETURN_PATH = '/module-select';
type LoginMode = 'password' | 'mobile';
@@ -101,8 +102,21 @@ function getLoginErrorMessage(error: string | null): string | null {
return /[\u3400-\u9fff]/.test(message) ? message : LOGIN_ERROR_MESSAGE;
}
function getSafeLoginReturnPath(state: unknown): string {
if (!state || typeof state !== 'object') return DEFAULT_LOGIN_RETURN_PATH;
const value = Reflect.get(state, 'from');
return typeof value === 'string'
&& value.startsWith('/')
&& value[1] !== '/'
&& value[1] !== '\\'
? value
: DEFAULT_LOGIN_RETURN_PATH;
}
export function Login() {
const navigate = useNavigate();
const location = useLocation();
const returnPath = getSafeLoginReturnPath(location.state);
const loginWithPassword = useAuthStore((state) => state.loginWithPassword);
const loginWithMobile = useAuthStore((state) => state.loginWithMobile);
const loading = useAuthStore((state) => state.loading);
@@ -240,9 +254,9 @@ export function Login() {
useEffect(() => {
if (isAuthenticated() && !submitting) {
navigate('/module-select', { replace: true });
navigate(returnPath, { replace: true });
}
}, [isAuthenticated, navigate, submitting]);
}, [isAuthenticated, navigate, returnPath, submitting]);
const finishLogin = async (login: () => Promise<void>) => {
setSubmitError(null);
@@ -257,7 +271,7 @@ export function Login() {
await logout();
throw syncError;
}
navigate('/module-select', { replace: true });
navigate(returnPath, { replace: true });
} catch (loginError) {
setSubmitError(loginError instanceof Error ? loginError.message : String(loginError));
} finally {