aboutsummaryrefslogtreecommitdiff
path: root/apps/memory-graph-playground/src/app/api/graph/route.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/memory-graph-playground/src/app/api/graph/route.ts')
-rw-r--r--apps/memory-graph-playground/src/app/api/graph/route.ts87
1 files changed, 48 insertions, 39 deletions
diff --git a/apps/memory-graph-playground/src/app/api/graph/route.ts b/apps/memory-graph-playground/src/app/api/graph/route.ts
index b7901966..c722c625 100644
--- a/apps/memory-graph-playground/src/app/api/graph/route.ts
+++ b/apps/memory-graph-playground/src/app/api/graph/route.ts
@@ -1,46 +1,55 @@
-import { NextResponse } from 'next/server'
+import { NextResponse } from "next/server"
export async function POST(request: Request) {
- try {
- const body = await request.json()
- const { apiKey, page = 1, limit = 500, sort = 'createdAt', order = 'desc' } = body
+ try {
+ const body = await request.json()
+ const {
+ apiKey,
+ page = 1,
+ limit = 500,
+ sort = "createdAt",
+ order = "desc",
+ } = body
- if (!apiKey) {
- return NextResponse.json(
- { error: 'API key is required' },
- { status: 400 }
- )
- }
+ if (!apiKey) {
+ return NextResponse.json(
+ { error: "API key is required" },
+ { status: 400 },
+ )
+ }
- const response = await fetch('https://api.supermemory.ai/v3/documents/documents', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${apiKey}`,
- },
- body: JSON.stringify({
- page,
- limit,
- sort,
- order,
- }),
- })
+ const response = await fetch(
+ "https://api.supermemory.ai/v3/documents/documents",
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${apiKey}`,
+ },
+ body: JSON.stringify({
+ page,
+ limit,
+ sort,
+ order,
+ }),
+ },
+ )
- if (!response.ok) {
- const errorData = await response.json().catch(() => ({}))
- return NextResponse.json(
- { error: errorData.message || `API error: ${response.status}` },
- { status: response.status }
- )
- }
+ if (!response.ok) {
+ const errorData = await response.json().catch(() => ({}))
+ return NextResponse.json(
+ { error: errorData.message || `API error: ${response.status}` },
+ { status: response.status },
+ )
+ }
- const data = await response.json()
- return NextResponse.json(data)
- } catch (error) {
- console.error('Graph API error:', error)
- return NextResponse.json(
- { error: 'Failed to fetch documents' },
- { status: 500 }
- )
- }
+ const data = await response.json()
+ return NextResponse.json(data)
+ } catch (error) {
+ console.error("Graph API error:", error)
+ return NextResponse.json(
+ { error: "Failed to fetch documents" },
+ { status: 500 },
+ )
+ }
}