pinakes-server: add notes API endpoints for backlinks

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6345960fca2afb4e080939b5fd73ea346a6a6964
This commit is contained in:
raf 2026-02-09 13:14:31 +03:00
commit 2c69691060
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 19 additions and 11 deletions

View file

@ -233,10 +233,7 @@ pub fn create_router_with_tls(
get(routes::shares::get_notifications), get(routes::shares::get_notifications),
) )
// Markdown notes/links (read) // Markdown notes/links (read)
.route( .route("/media/{id}/backlinks", get(routes::notes::get_backlinks))
"/media/{id}/backlinks",
get(routes::notes::get_backlinks),
)
.route( .route(
"/media/{id}/outgoing-links", "/media/{id}/outgoing-links",
get(routes::notes::get_outgoing_links), get(routes::notes::get_outgoing_links),

View file

@ -7,9 +7,9 @@
//! - Link reindexing //! - Link reindexing
use axum::{ use axum::{
Json, Router,
extract::{Path, Query, State}, extract::{Path, Query, State},
routing::{get, post}, routing::{get, post},
Json, Router,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
@ -144,8 +144,16 @@ impl From<GraphData> for GraphResponse {
let node_count = data.nodes.len(); let node_count = data.nodes.len();
let edge_count = data.edges.len(); let edge_count = data.edges.len();
Self { Self {
nodes: data.nodes.into_iter().map(GraphNodeResponse::from).collect(), nodes: data
edges: data.edges.into_iter().map(GraphEdgeResponse::from).collect(), .nodes
.into_iter()
.map(GraphNodeResponse::from)
.collect(),
edges: data
.edges
.into_iter()
.map(GraphEdgeResponse::from)
.collect(),
node_count, node_count,
edge_count, edge_count,
} }
@ -219,7 +227,10 @@ pub async fn get_outgoing_links(
let items: Vec<OutgoingLinkItem> = links.into_iter().map(OutgoingLinkItem::from).collect(); let items: Vec<OutgoingLinkItem> = links.into_iter().map(OutgoingLinkItem::from).collect();
let count = items.len(); let count = items.len();
Ok(Json(OutgoingLinksResponse { links: items, count })) Ok(Json(OutgoingLinksResponse {
links: items,
count,
}))
} }
/// Get graph data for visualization. /// Get graph data for visualization.
@ -262,9 +273,9 @@ pub async fn reindex_links(
} }
// Read the file content // Read the file content
let content = tokio::fs::read_to_string(&media.path).await.map_err(|e| { let content = tokio::fs::read_to_string(&media.path)
ApiError::internal(format!("Failed to read file: {}", e)) .await
})?; .map_err(|e| ApiError::internal(format!("Failed to read file: {}", e)))?;
// Extract links // Extract links
let links = pinakes_core::links::extract_links(media_id, &content); let links = pinakes_core::links::extract_links(media_id, &content);