Skip to content

Commit

Permalink
Merge pull request #603 from FalkorDB/restyle-browser
Browse files Browse the repository at this point in the history
Fix #602 restyle browser
  • Loading branch information
AviAvni authored Jan 14, 2025
2 parents 0b42e9d + 34014d8 commit 68209fb
Show file tree
Hide file tree
Showing 88 changed files with 5,415 additions and 5,531 deletions.
1 change: 1 addition & 0 deletions app/api/graph/[graph]/[node]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
const result = await graph.query(query, { params: { nodeId } });
return NextResponse.json({ result }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
41 changes: 19 additions & 22 deletions app/api/graph/[graph]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function DELETE(request: NextRequest, { params }: { params: Promise
return NextResponse.json({ message: `${graphId} graph deleted` })
}
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
Expand All @@ -34,46 +35,39 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
return client
}

const { graph: graphId } = await params;
const { graph: name } = await params;
const sourceName = request.nextUrl.searchParams.get("sourceName")

try {
if (sourceName) {
const graph = client.selectGraph(sourceName);
const success = await graph.copy(graphId)
const success = await graph.copy(name)
if (!success) throw new Error("Failed to copy graph")
return NextResponse.json({ success }, { status: 200 })
}

const type = request.nextUrl.searchParams.get("type")
const key = request.nextUrl.searchParams.get("key")
const openaikey = request.nextUrl.searchParams.get("key")
const srcs = await request.json()

if (!key) console.error("Missing parameter 'key'")

if (!srcs) console.error("Missing parameter 'srcs'")

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const socket = (await client.connection).options?.socket as any

if (!socket) console.error("socket not found")

const data = {
host: socket.host,
port: socket.port,
name: graphId,
srcs,
openaikey: key,
}
const { host, port } = (await client.connection).options?.socket as any

if (!type) console.error("Missing parameter 'type'")
if (!openaikey || !srcs || !host || !port || !type) throw new Error("Missing parameters")

const res = await securedFetch(`http://localhost:5000/${prepareArg(type!)}`, {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
body: JSON.stringify({
host,
port,
name,
srcs,
openaikey,
})
})

const result = await res.json()
Expand All @@ -82,6 +76,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{

return NextResponse.json({ result }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
Expand All @@ -98,14 +93,15 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise<
const sourceName = request.nextUrl.searchParams.get("sourceName")

try {
if (!sourceName) throw (new Error("Missing parameter 'sourceName'"))
if (!sourceName) throw new Error("Missing parameter sourceName")

const data = await (await client.connection).renameNX(sourceName, graphId);

if (!data) throw new Error(`${graphId} already exists`)

return NextResponse.json({ data })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
Expand Down Expand Up @@ -135,7 +131,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
const create = request.nextUrl.searchParams.get("create")
const role = request.nextUrl.searchParams.get("role")

if (!query) throw new Error("Missing parameter 'query'")
if (!query) throw new Error("Missing parameter query")

if (create === "false" && !(await client.list()).some((g) => g === graphId))
return NextResponse.json({}, { status: 200 })
Expand All @@ -146,10 +142,11 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
? await graph.roQuery(query)
: await graph.query(query)

if (!result) throw new Error("something went wrong")
if (!result) throw new Error("Something went wrong")

return NextResponse.json({ result }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
Loading

0 comments on commit 68209fb

Please sign in to comment.