diff --git a/crates/core/src/app.rs b/crates/core/src/app.rs index fa2e853..9f2263c 100644 --- a/crates/core/src/app.rs +++ b/crates/core/src/app.rs @@ -65,6 +65,7 @@ impl CoreApp { ("api_port", "1234".to_string()), ("api_key", String::new()), ("api_enabled", "false".to_string()), + ("upload_max_mb", "10".to_string()), ]; for (key, value) in defaults { let _ = settings::set(&db, key, &value); diff --git a/ui/src/pages/ChatPage.tsx b/ui/src/pages/ChatPage.tsx index db7aed2..e2e4d1b 100644 --- a/ui/src/pages/ChatPage.tsx +++ b/ui/src/pages/ChatPage.tsx @@ -50,9 +50,6 @@ const TEXT_EXTENSIONS = new Set([ "yml", "toml", "ini", "sh", "ps1", "bat", "sql", "env", "gitignore", ]); -const MAX_IMAGE_SIZE = 3 * 1024 * 1024; -const MAX_TEXT_SIZE = 100 * 1024; - export default function ChatPage() { const models = useStore((s) => s.models); const conversations = useStore((s) => s.conversations); @@ -75,6 +72,7 @@ export default function ChatPage() { const [editingDraft, setEditingDraft] = useState(""); const [versionsFor, setVersionsFor] = useState>({}); const [attachments, setAttachments] = useState([]); + const [uploadLimitMb, setUploadLimitMb] = useState(10); const bottomRef = useRef(null); const fileInputRef = useRef(null); @@ -104,6 +102,13 @@ export default function ChatPage() { } }, [models, selectedModelId]); + useEffect(() => { + api.settingsGet().then((s) => { + const v = Number(s.upload_max_mb); + if (v > 0) setUploadLimitMb(v); + }); + }, []); + useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages]); @@ -302,11 +307,12 @@ export default function ChatPage() { } async function handleFiles(files: FileList | File[]) { + const maxBytes = uploadLimitMb * 1024 * 1024; for (const file of Array.from(files)) { const ext = file.name.split(".").pop()?.toLowerCase() ?? ""; if (file.type.startsWith("image/") || ["png", "jpg", "jpeg", "webp", "gif", "bmp"].includes(ext)) { - if (file.size > MAX_IMAGE_SIZE) { - setError(`图片 ${file.name} 超过 3MB,已跳过`); + if (file.size > maxBytes) { + setError(`图片 ${file.name} 超过上限 ${uploadLimitMb}MB,已跳过`); continue; } const dataUrl = await readAsDataUrl(file); @@ -315,8 +321,8 @@ export default function ChatPage() { { id: crypto.randomUUID(), kind: "image", name: file.name, size: file.size, dataUrl }, ]); } else if (file.type.startsWith("text/") || TEXT_EXTENSIONS.has(ext)) { - if (file.size > MAX_TEXT_SIZE) { - setError(`文件 ${file.name} 超过 100KB,已跳过`); + if (file.size > maxBytes) { + setError(`文件 ${file.name} 超过上限 ${uploadLimitMb}MB,已跳过`); continue; } const text = await file.text(); @@ -468,7 +474,7 @@ export default function ChatPage() { diff --git a/ui/src/pages/SettingsPage.tsx b/ui/src/pages/SettingsPage.tsx index fe466fc..9e5c1bd 100644 --- a/ui/src/pages/SettingsPage.tsx +++ b/ui/src/pages/SettingsPage.tsx @@ -77,6 +77,11 @@ export default function SettingsPage() { value={settings.backend ?? ""} onSave={(v) => handleSave("backend", v)} /> + handleSave("upload_max_mb", v)} + />