MCPcopy
hub / github.com/vercel/chatbot / GET

Function GET

app/(chat)/api/document/route.ts:10–40  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

8import { ChatSDKError } from '@/lib/errors';
9
10export async function GET(request: Request) {
11 const { searchParams } = new URL(request.url);
12 const id = searchParams.get('id');
13
14 if (!id) {
15 return new ChatSDKError(
16 'bad_request:api',
17 'Parameter id is missing',
18 ).toResponse();
19 }
20
21 const session = await auth();
22
23 if (!session?.user) {
24 return new ChatSDKError('unauthorized:document').toResponse();
25 }
26
27 const documents = await getDocumentsById({ id });
28
29 const [document] = documents;
30
31 if (!document) {
32 return new ChatSDKError('not_found:document').toResponse();
33 }
34
35 if (document.userId !== session.user.id) {
36 return new ChatSDKError('forbidden:document').toResponse();
37 }
38
39 return Response.json(documents, { status: 200 });
40}
41
42export async function POST(request: Request) {
43 const { searchParams } = new URL(request.url);

Callers

nothing calls this directly

Calls 2

getDocumentsByIdFunction · 0.90
toResponseMethod · 0.80

Tested by

no test coverage detected