2025-12-26 07:52:40 +08:00
|
|
|
import { NextResponse } from "next/server";
|
2026-01-17 10:12:53 +08:00
|
|
|
import { isConvexEnabled } from "@/lib/convex/enabled";
|
|
|
|
|
import { HttpError, requireAuthContext } from "@/lib/auth/authContext";
|
2025-12-26 07:52:40 +08:00
|
|
|
|
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
|
|
|
|
|
export async function GET(request: Request) {
|
2026-01-17 10:12:53 +08:00
|
|
|
if (isConvexEnabled()) {
|
|
|
|
|
try {
|
2026-01-18 05:13:53 +08:00
|
|
|
await requireAuthContext();
|
2026-01-17 10:12:53 +08:00
|
|
|
} catch (err) {
|
|
|
|
|
if (err instanceof HttpError) {
|
|
|
|
|
return NextResponse.json({ error: "未登录" }, { status: err.status });
|
|
|
|
|
}
|
|
|
|
|
return NextResponse.json({ error: "未登录" }, { status: 401 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
|
|
|
const fileUrl = searchParams.get("fileUrl");
|
|
|
|
|
if (!fileUrl) {
|
|
|
|
|
return NextResponse.json({ error: "缺少 fileUrl" }, { status: 400 });
|
|
|
|
|
}
|
2026-01-18 19:01:31 +08:00
|
|
|
|
|
|
|
|
// 说明:Convex + MinIO 模式下,这个接口目前主要用于“外链文件”走 ONLYOFFICE 的场景。
|
|
|
|
|
// 由于外链本身已经是可访问的 URL,这里只做最小透传。
|
2026-01-17 10:12:53 +08:00
|
|
|
return NextResponse.json({ signedUrl: fileUrl });
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-18 19:01:31 +08:00
|
|
|
return NextResponse.json({ error: "当前仅支持 Convex 模式" }, { status: 501 });
|
2025-12-26 07:52:40 +08:00
|
|
|
}
|
2026-01-18 19:01:31 +08:00
|
|
|
|