0.2.1 onlyoffice修复
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useSessionContext } from "@supabase/auth-helpers-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { getMnoteRuntimeConfig } from "@/lib/runtime-config";
|
||||
@@ -18,56 +17,37 @@ interface Props {
|
||||
}
|
||||
|
||||
export function DocumentTaskPanel({ documentId }: Props) {
|
||||
const { session } = useSessionContext();
|
||||
const [task, setTask] = useState<TaskResponse | null>(null);
|
||||
const [pending, setPending] = useState(false);
|
||||
const backendUrl = useMemo(() => getMnoteRuntimeConfig().backendUrl, []);
|
||||
const runtime = useMemo(() => getMnoteRuntimeConfig(), []);
|
||||
const backendUrl = runtime.backendUrl;
|
||||
const useConvex = Boolean(runtime.useConvex);
|
||||
|
||||
const triggerTask = async () => {
|
||||
if (!backendUrl || !session?.access_token) return;
|
||||
// 说明:当前后端(FastAPI)仍使用 Supabase JWT 做鉴权;Convex 迁移阶段先不打通这一块。
|
||||
if (useConvex) return;
|
||||
if (!backendUrl) return;
|
||||
setPending(true);
|
||||
try {
|
||||
const response = await fetch(`${backendUrl}/api/v1/tasks/ocr`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${session.access_token}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
document_id: documentId,
|
||||
file_url: "https://example.com/sample.pdf",
|
||||
}),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (response.ok) {
|
||||
setTask(data);
|
||||
}
|
||||
// TODO:如需恢复该能力,请在接入真实鉴权后,将 access_token 从 AuthContext 注入到这里。
|
||||
// 这里暂时保持 UI 可渲染,不发起请求。
|
||||
void documentId;
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!backendUrl || !session?.access_token || !task?.task_id) {
|
||||
if (useConvex) return;
|
||||
if (!backendUrl || !task?.task_id) {
|
||||
return;
|
||||
}
|
||||
const timer = setInterval(async () => {
|
||||
const response = await fetch(`${backendUrl}/api/v1/tasks/${task.task_id}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${session.access_token}`,
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
return;
|
||||
}
|
||||
const data = (await response.json()) as TaskResponse;
|
||||
setTask(data);
|
||||
if (data.status === "completed") {
|
||||
clearInterval(timer);
|
||||
}
|
||||
// 说明:同上,暂不轮询。
|
||||
void timer;
|
||||
}, 2000);
|
||||
return () => clearInterval(timer);
|
||||
}, [backendUrl, session?.access_token, task?.task_id]);
|
||||
}, [backendUrl, task?.task_id, useConvex]);
|
||||
|
||||
return (
|
||||
<Card className="mt-4 bg-white shadow-sm">
|
||||
@@ -77,9 +57,14 @@ export function DocumentTaskPanel({ documentId }: Props) {
|
||||
<div className="text-xs text-gray-500">
|
||||
状态:{task ? task.status : "未开始"} · 进度:{task ? `${task.progress}%` : "0%"}
|
||||
</div>
|
||||
{useConvex && (
|
||||
<div className="text-xs text-gray-500">
|
||||
提示:Convex 迁移阶段暂未接入后端鉴权(Supabase JWT),该按钮仅用于占位。
|
||||
</div>
|
||||
)}
|
||||
{task?.message && <div className="text-xs text-gray-500">提示:{task.message}</div>}
|
||||
</div>
|
||||
<Button onClick={triggerTask} disabled={pending} variant="outline">
|
||||
<Button onClick={triggerTask} disabled={pending || useConvex} variant="outline">
|
||||
{pending ? "触发中..." : "触发 OCR"}
|
||||
</Button>
|
||||
</CardContent>
|
||||
|
||||
Reference in New Issue
Block a user