-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from FalkorDB/restyling
Restyling
- Loading branch information
Showing
33 changed files
with
3,205 additions
and
1,542 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { NextRequest, NextResponse } from "next/server" | ||
|
||
|
||
export async function POST(request: NextRequest, { params }: { params: { graph: string } }) { | ||
|
||
const graphName = params.graph | ||
const msg = request.nextUrl.searchParams.get('msg') | ||
|
||
try { | ||
const result = await fetch(`${process.env.BEAKEND_URL}/chat`, { | ||
method: 'POST', | ||
body: JSON.stringify({ repo: graphName, msg }), | ||
headers: { | ||
"Authorization": process.env.SECRET_TOKEN!, | ||
"Content-Type": 'application/json' | ||
} | ||
}) | ||
|
||
if (!result.ok) { | ||
throw new Error(await result.text()) | ||
} | ||
|
||
const json = await result.json() | ||
|
||
return NextResponse.json({ result: json }, { status: 200 }) | ||
} catch (err) { | ||
return NextResponse.json({ message: (err as Error).message }, { status: 400 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,55 @@ | ||
import { FalkorDB, Graph } from "falkordb"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function GET(request: NextRequest, { params }: { params: { graph: string, node: string } }) { | ||
|
||
const nodeId = parseInt(params.node); | ||
|
||
const nodeId = parseInt(params.node); | ||
const graphId = params.graph; | ||
try { | ||
|
||
const result = await fetch(`${process.env.BEAKEND_URL}/get_neighbors?repo=${graphId}&node_id=${nodeId}`, { | ||
method: 'GET', | ||
headers: { | ||
"Authorization": process.env.SECRET_TOKEN!, | ||
} | ||
}) | ||
|
||
const json = await result.json() | ||
|
||
return NextResponse.json({ result: json }, { status: 200 }) | ||
} catch (err) { | ||
return NextResponse.json({ massage: (err as Error).message }, { status: 400 }) | ||
} | ||
} | ||
|
||
export async function POST(request: NextRequest, { params }: { params: { graph: string, node: string } }) { | ||
|
||
const nodeId = params.node; | ||
const graphId = params.graph; | ||
const targetId = request.nextUrl.searchParams.get('targetId') | ||
|
||
try { | ||
|
||
const db = await FalkorDB.connect({url: process.env.FALKORDB_URL || 'falkor://localhost:6379',}); | ||
const graph = db.selectGraph(graphId); | ||
const result = await fetch(`${process.env.BEAKEND_URL}/find_paths`, { | ||
method: 'POST', | ||
headers: { | ||
"Authorization": process.env.SECRET_TOKEN!, | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
repo: graphId, | ||
src: Number(nodeId), | ||
dest: Number(targetId!) | ||
}) | ||
}) | ||
|
||
// Get node's neighbors | ||
const q_params = {nodeId: nodeId}; | ||
const query = `MATCH (src)-[e]-(n) | ||
WHERE ID(src) = $nodeId | ||
RETURN collect(distinct { label:labels(n)[0], id:ID(n), name: n.name } ) as nodes, | ||
collect( { src: ID(startNode(e)), id: ID(e), dest: ID(endNode(e)), type: type(e) } ) as edges`; | ||
if (!result.ok) { | ||
throw new Error(await result.text()) | ||
} | ||
|
||
let res: any = await graph.query(query, { params: q_params }); | ||
let nodes = res.data[0]['nodes']; | ||
let edges = res.data[0]['edges']; | ||
const json = await result.json() | ||
|
||
return NextResponse.json({ id: graphId, nodes: nodes, edges: edges }, { status: 200 }) | ||
return NextResponse.json({ result: json }, { status: 200 }) | ||
} catch (err) { | ||
return NextResponse.json({ massage: (err as Error).message }, { status: 200 }) | ||
} | ||
} |
Oops, something went wrong.