!12047 图片识别

Merge pull request !12047 from 李鹏宇/dev
This commit is contained in:
李鹏宇
2026-06-12 07:30:36 +00:00
committed by Gitee
3 changed files with 31 additions and 3 deletions
-1
View File
@@ -212,7 +212,6 @@ class AiChatController(http.Controller):
'name': filename,
'mimetype': mimetype,
'raw': raw_bytes,
'folder_id': False,
})
# OCR 提取文字
@@ -93,7 +93,21 @@ export class AiChatAction extends Component {
const resp = await fetch("/ai/attachment/upload", {
method: "POST",
body: formData,
credentials: "same-origin",
});
if (!resp.ok) {
let detail = "";
try {
const errData = await resp.json();
detail = errData.error || JSON.stringify(errData);
} catch (_) {
const text = await resp.text();
detail = text.substring(0, 500);
}
console.error("[AI] Upload HTTP", resp.status, detail);
alert("上传失败 (HTTP " + resp.status + ")\n" + (detail || "未知错误"));
return;
}
const data = await resp.json();
if (data.success) {
this.state.attachments = [
@@ -109,7 +123,7 @@ export class AiChatAction extends Component {
}
} catch (e) {
console.error("[AI] Upload failed:", e);
alert("上传失败,请检查网络");
alert("上传失败,请检查网络\n" + e.message);
}
}
+16 -1
View File
@@ -93,7 +93,22 @@ async function uploadFile(file) {
const resp = await fetch("/ai/attachment/upload", {
method: "POST",
body: formData,
credentials: "same-origin",
});
if (!resp.ok) {
// 服务器返回错误状态码,尝试读取错误详情
let detail = "";
try {
const errData = await resp.json();
detail = errData.error || JSON.stringify(errData);
} catch (_) {
const text = await resp.text();
detail = text.substring(0, 500);
}
console.error("[AI] Upload HTTP", resp.status, detail);
alert("上传失败 (HTTP " + resp.status + ")\n" + (detail || "未知错误"));
return;
}
const data = await resp.json();
if (data.success) {
pendingAttachments.push({
@@ -108,7 +123,7 @@ async function uploadFile(file) {
}
} catch (e) {
console.error("[AI] Upload failed:", e);
alert("上传失败,请检查网络");
alert("上传失败,请检查网络\n" + e.message);
}
}