fix: 优化整个项目内容
This commit is contained in:
File diff suppressed because one or more lines are too long
2
frontend/dist/index.html
vendored
2
frontend/dist/index.html
vendored
@@ -9,7 +9,7 @@
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<link rel="manifest" href="/manifest.webmanifest" />
|
||||
<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">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
client_max_body_size 64m;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://backend:8000/api/;
|
||||
|
||||
@@ -90,6 +90,9 @@ function formatWrongCountDisplay(n) {
|
||||
}
|
||||
|
||||
function getApiErrorMessage(error, fallback = "请求失败,请稍后重试") {
|
||||
if (error?.response?.status === 413) {
|
||||
return "图片体积过大(413),请重试;系统已自动压缩,建议拍照时靠近题目并避免整页超高清。";
|
||||
}
|
||||
return error?.response?.data?.detail || error?.message || fallback;
|
||||
}
|
||||
|
||||
@@ -735,9 +738,9 @@ function MistakeModule({ quickCaptureTask, onQuickCaptureHandled }) {
|
||||
const type = String(file.type || "").toLowerCase();
|
||||
const isAlreadySupported = ["image/jpeg", "image/png", "image/webp"].includes(type);
|
||||
const hasKnownExt = /\.(jpe?g|png|webp)$/i.test(file.name || "");
|
||||
if (isAlreadySupported && hasKnownExt) return file;
|
||||
|
||||
if (!type.startsWith("image/")) return file;
|
||||
const shouldProcessImage = type.startsWith("image/") || !type;
|
||||
if (!shouldProcessImage) return file;
|
||||
if (isAlreadySupported && hasKnownExt && file.size <= 3 * 1024 * 1024) return file;
|
||||
|
||||
try {
|
||||
const dataUrl = await new Promise((resolve, reject) => {
|
||||
@@ -755,22 +758,31 @@ function MistakeModule({ quickCaptureTask, onQuickCaptureHandled }) {
|
||||
});
|
||||
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
const MAX_SIDE = 2200;
|
||||
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");
|
||||
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) => {
|
||||
canvas.toBlob(
|
||||
(b) => {
|
||||
if (!b) reject(new Error("图片转换失败"));
|
||||
else resolve(b);
|
||||
},
|
||||
"image/jpeg",
|
||||
0.92
|
||||
);
|
||||
});
|
||||
const toBlobByQuality = (quality) =>
|
||||
new Promise((resolve, reject) => {
|
||||
canvas.toBlob(
|
||||
(b) => {
|
||||
if (!b) reject(new Error("图片转换失败"));
|
||||
else resolve(b);
|
||||
},
|
||||
"image/jpeg",
|
||||
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(/\.[^.]+$/, "");
|
||||
return new File([blob], `${baseName || "capture"}-${Date.now()}.jpg`, { type: "image/jpeg" });
|
||||
|
||||
Reference in New Issue
Block a user