fix: 优化整个项目内容

This commit is contained in:
Daniel
2026-04-19 15:22:57 +08:00
parent 06af48f560
commit fd8e31adb4
4 changed files with 90 additions and 77 deletions

File diff suppressed because one or more lines are too long

View File

@@ -9,7 +9,7 @@
<meta name="mobile-web-app-capable" content="yes" /> <meta name="mobile-web-app-capable" content="yes" />
<link rel="manifest" href="/manifest.webmanifest" /> <link rel="manifest" href="/manifest.webmanifest" />
<title>学习伙伴</title> <title>学习伙伴</title>
<script type="module" crossorigin src="/assets/index-DyP_J9zM.js"></script> <script type="module" crossorigin src="/assets/index-9iYNjrsg.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-C-dSv0ph.css"> <link rel="stylesheet" crossorigin href="/assets/index-C-dSv0ph.css">
</head> </head>
<body> <body>

View File

@@ -1,6 +1,7 @@
server { server {
listen 80; listen 80;
server_name _; server_name _;
client_max_body_size 64m;
location /api/ { location /api/ {
proxy_pass http://backend:8000/api/; proxy_pass http://backend:8000/api/;

View File

@@ -90,6 +90,9 @@ function formatWrongCountDisplay(n) {
} }
function getApiErrorMessage(error, fallback = "请求失败,请稍后重试") { function getApiErrorMessage(error, fallback = "请求失败,请稍后重试") {
if (error?.response?.status === 413) {
return "图片体积过大413请重试系统已自动压缩建议拍照时靠近题目并避免整页超高清。";
}
return error?.response?.data?.detail || error?.message || fallback; return error?.response?.data?.detail || error?.message || fallback;
} }
@@ -735,9 +738,9 @@ function MistakeModule({ quickCaptureTask, onQuickCaptureHandled }) {
const type = String(file.type || "").toLowerCase(); const type = String(file.type || "").toLowerCase();
const isAlreadySupported = ["image/jpeg", "image/png", "image/webp"].includes(type); const isAlreadySupported = ["image/jpeg", "image/png", "image/webp"].includes(type);
const hasKnownExt = /\.(jpe?g|png|webp)$/i.test(file.name || ""); const hasKnownExt = /\.(jpe?g|png|webp)$/i.test(file.name || "");
if (isAlreadySupported && hasKnownExt) return file; const shouldProcessImage = type.startsWith("image/") || !type;
if (!shouldProcessImage) return file;
if (!type.startsWith("image/")) return file; if (isAlreadySupported && hasKnownExt && file.size <= 3 * 1024 * 1024) return file;
try { try {
const dataUrl = await new Promise((resolve, reject) => { const dataUrl = await new Promise((resolve, reject) => {
@@ -755,23 +758,32 @@ function MistakeModule({ quickCaptureTask, onQuickCaptureHandled }) {
}); });
const canvas = document.createElement("canvas"); const canvas = document.createElement("canvas");
canvas.width = img.width; const MAX_SIDE = 2200;
canvas.height = img.height; const scale = Math.min(1, MAX_SIDE / Math.max(img.width, img.height));
canvas.width = Math.max(1, Math.round(img.width * scale));
canvas.height = Math.max(1, Math.round(img.height * scale));
const ctx = canvas.getContext("2d"); const ctx = canvas.getContext("2d");
if (!ctx) return file; if (!ctx) return file;
ctx.drawImage(img, 0, 0); ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
const blob = await new Promise((resolve, reject) => { const toBlobByQuality = (quality) =>
new Promise((resolve, reject) => {
canvas.toBlob( canvas.toBlob(
(b) => { (b) => {
if (!b) reject(new Error("图片转换失败")); if (!b) reject(new Error("图片转换失败"));
else resolve(b); else resolve(b);
}, },
"image/jpeg", "image/jpeg",
0.92 quality
); );
}); });
let blob = await toBlobByQuality(0.9);
const maxBytes = 2 * 1024 * 1024;
if (blob.size > maxBytes) blob = await toBlobByQuality(0.8);
if (blob.size > maxBytes) blob = await toBlobByQuality(0.72);
if (blob.size > maxBytes) blob = await toBlobByQuality(0.64);
const baseName = String(file.name || "capture").replace(/\.[^.]+$/, ""); const baseName = String(file.name || "capture").replace(/\.[^.]+$/, "");
return new File([blob], `${baseName || "capture"}-${Date.now()}.jpg`, { type: "image/jpeg" }); return new File([blob], `${baseName || "capture"}-${Date.now()}.jpg`, { type: "image/jpeg" });
} catch { } catch {