0.3.2.1 UI修复3

This commit is contained in:
liaibo
2026-01-20 07:24:12 +08:00
parent fa7235b1a7
commit f13de35321
16 changed files with 741 additions and 108 deletions
@@ -0,0 +1,42 @@
import { NextResponse } from "next/server";
import type { MediaAsset } from "@/types/media";
import { isConvexEnabled } from "@/lib/convex/enabled";
import { HttpError, requireAuthContext } from "@/lib/auth/authContext";
import { api } from "@/lib/convex/api";
import { getConvexAuthedHttpClient } from "@/lib/convex/server";
export const dynamic = "force-dynamic";
export async function GET(request: Request) {
if (isConvexEnabled()) {
let auth;
try {
auth = await requireAuthContext();
} 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 documentId = searchParams.get("documentId") ?? "";
const limit = Number.parseInt(searchParams.get("limit") ?? "200", 10);
if (!documentId) {
return NextResponse.json({ error: "缺少 documentId" }, { status: 400 });
}
const client = await getConvexAuthedHttpClient();
const items = await client.query(api.mediaAssets.listByDocument, {
userId: auth.userId,
documentId,
limit: Number.isNaN(limit) ? 200 : limit,
});
return NextResponse.json({ items: (items ?? []) as MediaAsset[] });
}
return NextResponse.json({ error: "当前仅支持 Convex 模式" }, { status: 501 });
}