Skip to content

Commit 57adfac

Browse files
committed
create file fetch route
1 parent 9cd8e12 commit 57adfac

11 files changed

Lines changed: 273 additions & 151 deletions

File tree

src/app/api/agents/files/route.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
import { type NextRequest, NextResponse } from "next/server";
2-
import { db } from "@/lib/prisma";
3-
4-
export async function GET(req: NextRequest) {
5-
const { searchParams } = new URL(req.url);
6-
const agentId = searchParams.get("agentId");
7-
8-
if (!agentId) {
9-
return NextResponse.json({ error: "Missing AgentId" }, { status: 400 });
10-
}
11-
12-
try {
13-
const files = await db.docs.findMany({
14-
where: {
15-
agentId: agentId,
16-
},
17-
});
18-
19-
return NextResponse.json(files);
20-
} catch (error) {
21-
console.error(
22-
"Error fetching files :: In GET /api/agents/files :: ",
23-
error
24-
);
25-
return NextResponse.json(
26-
{ error: "Failed to fetch files" },
27-
{ status: 500 }
28-
);
29-
}
30-
}
1+
import { type NextRequest, NextResponse } from 'next/server'
2+
import type { Docs } from '@/generated/prisma'
3+
import { db } from '@/lib/prisma'
4+
5+
export async function GET(req: NextRequest): Promise<Docs[] | NextResponse> {
6+
const { searchParams } = new URL(req.url)
7+
const agentId = searchParams.get('agentId')
8+
9+
if (!agentId) {
10+
return NextResponse.json({ error: 'Missing AgentId' }, { status: 400 })
11+
}
12+
13+
try {
14+
const files = await db.docs.findMany({
15+
where: {
16+
agentId: agentId,
17+
},
18+
})
19+
20+
return NextResponse.json(files)
21+
} catch (error) {
22+
console.error('Error fetching files :: In GET /api/agents/files :: ', error)
23+
return NextResponse.json(
24+
{ error: 'Failed to fetch files' },
25+
{ status: 500 },
26+
)
27+
}
28+
}

src/app/api/agents/route.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import { NextResponse } from "next/server";
2-
import { db } from "@/lib/prisma";
1+
import { NextResponse } from 'next/server'
2+
import { db } from '@/lib/prisma'
33

44
export async function GET(request: Request) {
5-
const { searchParams } = new URL(request.url);
6-
const userId = searchParams.get("userId");
5+
const { searchParams } = new URL(request.url)
6+
const userId = searchParams.get('userId')
77

88
if (!userId) {
99
return NextResponse.json(
1010
{
11-
error: "Missing UserId",
11+
error: 'Missing UserId',
1212
},
13-
{ status: 400 }
14-
);
13+
{ status: 400 },
14+
)
1515
}
1616

1717
try {
1818
const agents = await db.agent.findMany({
1919
where: {
2020
userId: userId,
2121
},
22-
});
22+
})
2323

24-
return NextResponse.json(agents);
24+
return NextResponse.json(agents)
2525
} catch (error) {
26-
console.error("Error fetching agents :: In GET /api/agents :: ", error);
26+
console.error('Error fetching agents :: In GET /api/agents :: ', error)
2727
return NextResponse.json(
28-
{ error: "Failed to fetch agents" },
29-
{ status: 500 }
30-
);
28+
{ error: 'Failed to fetch agents' },
29+
{ status: 500 },
30+
)
3131
}
3232
}

src/app/api/auth/[...all]/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toNextJsHandler } from "better-auth/next-js";
2-
import { auth } from "@/lib/auth"; // path to your auth file
1+
import { toNextJsHandler } from 'better-auth/next-js'
2+
import { auth } from '@/lib/auth' // path to your auth file
33

4-
export const { POST, GET } = toNextJsHandler(auth);
4+
export const { POST, GET } = toNextJsHandler(auth)
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { initEdgeStore } from "@edgestore/server";
2-
import { createEdgeStoreNextHandler } from "@edgestore/server/adapters/next/app";
1+
import { initEdgeStore } from '@edgestore/server'
2+
import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/app'
33

4-
const es = initEdgeStore.create();
4+
const es = initEdgeStore.create()
55

66
/**
77
* This is the main router for the EdgeStore buckets.
88
*/
99
const edgeStoreRouter = es.router({
1010
publicFiles: es.fileBucket(),
11-
});
11+
})
1212

1313
const handler = createEdgeStoreNextHandler({
1414
router: edgeStoreRouter,
15-
});
15+
})
1616

17-
export { handler as GET, handler as POST };
17+
export { handler as GET, handler as POST }
1818

1919
/**
2020
* This type is used to create the type-safe client for the frontend.
2121
*/
22-
export type EdgeStoreRouter = typeof edgeStoreRouter;
22+
export type EdgeStoreRouter = typeof edgeStoreRouter

src/app/api/saveFiles/route.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { type NextRequest, NextResponse } from "next/server";
2-
import { db } from "@/lib/prisma";
3-
4-
export async function POST(req: NextRequest) {
5-
const body = await req.json();
6-
const { agentId, name, size, type, url } = body;
7-
8-
if (!agentId || !name || !size || !type || !url) {
9-
return NextResponse.json(
10-
{ error: "Missing required fields" },
11-
{ status: 400 }
12-
);
13-
}
14-
15-
try {
16-
await db.docs.create({
17-
data: { agentId, name, size, type, url },
18-
});
19-
return NextResponse.json({ success: true });
20-
} catch (error) {
21-
console.error("Error saving file:", error);
22-
return NextResponse.json({ error: "Failed to save file" }, { status: 500 });
23-
}
24-
}
1+
import { type NextRequest, NextResponse } from 'next/server'
2+
import { db } from '@/lib/prisma'
3+
4+
export async function POST(req: NextRequest): Promise<NextResponse> {
5+
const body = await req.json()
6+
const { agentId, name, size, type, url } = body
7+
8+
if (!agentId || !name || !size || !type || !url) {
9+
return NextResponse.json(
10+
{ error: 'Missing required fields' },
11+
{ status: 400 },
12+
)
13+
}
14+
15+
try {
16+
const file = await db.docs.create({
17+
data: { agentId, name, size, type, url },
18+
})
19+
return NextResponse.json(file, { status: 201 })
20+
} catch (error) {
21+
console.error('Error saving file:', error)
22+
return NextResponse.json({ error: 'Failed to save file' }, { status: 500 })
23+
}
24+
}

src/app/dashboard/agents/AgentList.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ const AgentList = ({ userId }: Props) => {
7171
key={agent.id}
7272
variant={'outline'}
7373
onClick={() => handleAgentClick(agent.id)}
74-
className="p-4 cursor-pointer"
74+
className="cursor-pointer p-4"
7575
>
76-
<div className="flex h-40 w-1/3 flex-col items-start justify-start rounded-2xl border-[1px] gap-3 border-gray-200 bg-light-gray ">
77-
<Bot className="text-zinc-800 size-10" />
76+
<div className="flex h-40 w-1/3 flex-col items-start justify-start gap-3 rounded-2xl border-[1px] border-gray-200 bg-light-gray ">
77+
<Bot className="size-10 text-zinc-800" />
7878

79-
<div className="flex-1 w-full">
80-
<h2 className="text-xl font-semibold text-zinc-700 capitalize">
79+
<div className="w-full flex-1">
80+
<h2 className="font-semibold text-xl text-zinc-700 capitalize">
8181
{agent.name}
8282
</h2>
83-
<p className="text-sm font-medium text-muted-foreground">
83+
<p className="font-medium text-muted-foreground text-sm">
8484
{agent.description}
8585
</p>
8686
</div>

src/app/dashboard/agents/AgentSkeleton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Skeleton } from '@/components/ui/skeleton'
33
const AgentSkeleton = () => {
44
return (
55
<div className="flex h-full w-full gap-4">
6-
<Skeleton className="mb-4 h-40 w-1/3" />
7-
<Skeleton className="mb-4 h-40 w-1/3" />
8-
<Skeleton className="mb-4 h-40 w-1/3" />
6+
<Skeleton className="mb-4 h-40 w-1/3 bg-zinc-300" />
7+
<Skeleton className="mb-4 h-40 w-1/3 bg-zinc-300" />
8+
<Skeleton className="mb-4 h-40 w-1/3 bg-zinc-300" />
99
</div>
1010
)
1111
}

0 commit comments

Comments
 (0)