Skip to main content

pagesift_api/jina/
mod.rs

1//! Jina Reader protocol adapter for PageSift.
2//! Implements `GET /r/{*url}` and `POST /r` for direct markdown and SSE event streaming.
3
4pub mod reader_route;
5pub mod stream_sse;
6
7use axum::Router;
8use axum::routing::{get, post};
9use std::sync::Arc;
10
11use crate::engine::Engine;
12pub use reader_route::{handle_jina_get, handle_jina_post};
13pub use stream_sse::stream_markdown_sse;
14
15/// Mount Jina Reader protocol routes onto the router.
16pub fn jina_router(engine: Arc<dyn Engine>) -> Router {
17    Router::new()
18        .route("/r/{*url}", get(handle_jina_get))
19        .route("/r", post(handle_jina_post))
20        .route("/r/", post(handle_jina_post))
21        .with_state(engine)
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn test_sse_event_formatting() {
30        let resp = stream_markdown_sse(
31            "https://example.com",
32            Some("Test Title"),
33            "# Hello\n\nWorld paragraph",
34        );
35        assert_eq!(resp.status(), axum::http::StatusCode::OK);
36        assert_eq!(
37            resp.headers().get("content-type").unwrap(),
38            "text/event-stream; charset=utf-8"
39        );
40    }
41}