Feat v0.4.7 note graph (#29)
All checks were successful
All checks were successful
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #29.
This commit is contained in:
@@ -133,6 +133,10 @@ def on_request(req):
|
||||
if method == "POST" and path == "/notes/move":
|
||||
return _move_note(req)
|
||||
|
||||
# GET /graph — full graph data for visualization
|
||||
if method == "GET" and path == "/graph":
|
||||
return _get_graph()
|
||||
|
||||
# ── Link routes ──────────────────────────
|
||||
# GET /links/:note_id — outgoing links
|
||||
if method == "GET" and path.startswith("/links/"):
|
||||
@@ -463,6 +467,44 @@ def _get_backlinks(note_id):
|
||||
return _resp(200, {"data": items})
|
||||
|
||||
|
||||
def _get_graph():
|
||||
"""Return all non-archived notes as nodes and resolved links as edges."""
|
||||
all_notes = db.query("notes", filters={"archived": 0}, limit=5000)
|
||||
notes = all_notes or []
|
||||
|
||||
# batch-fetch tags
|
||||
note_ids = [n.get("id", "") for n in notes]
|
||||
tags_map = _tags_for_notes(note_ids)
|
||||
|
||||
# build nodes + id set for edge filtering
|
||||
nodes = []
|
||||
note_id_set = {}
|
||||
for n in notes:
|
||||
nid = n.get("id", "")
|
||||
note_id_set[nid] = True
|
||||
nodes.append({
|
||||
"id": nid,
|
||||
"title": n.get("title", "Untitled"),
|
||||
"folder_id": _str(n.get("folder_id", "")),
|
||||
"tags": tags_map.get(nid, []),
|
||||
})
|
||||
|
||||
# fetch links, keep only resolved (both endpoints exist)
|
||||
all_links = db.query("links", limit=10000)
|
||||
edges = []
|
||||
for link in (all_links or []):
|
||||
src = _str(link.get("source_id", ""))
|
||||
tgt = _str(link.get("target_id", ""))
|
||||
if src and tgt and src in note_id_set and tgt in note_id_set:
|
||||
edges.append({
|
||||
"source": src,
|
||||
"target": tgt,
|
||||
"text": _str(link.get("link_text", "")),
|
||||
})
|
||||
|
||||
return _resp(200, {"nodes": nodes, "edges": edges})
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════
|
||||
# Folder CRUD
|
||||
# ═══════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user