@@ -4,7 +4,12 @@ use std::time::Instant;
44
55use axum:: extract:: { Path , Query , State } ;
66use axum:: http:: { HeaderMap , HeaderValue , Method } ;
7- use axum:: { Json , Router , http:: StatusCode , response:: IntoResponse , routing:: { get, post} } ;
7+ use axum:: {
8+ Json , Router ,
9+ http:: StatusCode ,
10+ response:: IntoResponse ,
11+ routing:: { get, post} ,
12+ } ;
813use serde:: Deserialize ;
914use tokio:: sync:: Mutex ;
1015use tower_http:: cors:: { Any , CorsLayer } ;
@@ -334,10 +339,7 @@ fn cors_layer(origins: &[String]) -> CorsLayer {
334339 . allow_methods ( Any )
335340 . allow_headers ( Any ) ;
336341 }
337- let origins: Vec < HeaderValue > = origins
338- . iter ( )
339- . filter_map ( |o| o. parse ( ) . ok ( ) )
340- . collect ( ) ;
342+ let origins: Vec < HeaderValue > = origins. iter ( ) . filter_map ( |o| o. parse ( ) . ok ( ) ) . collect ( ) ;
341343 CorsLayer :: new ( )
342344 . allow_origin ( origins)
343345 . allow_methods ( [ Method :: GET , Method :: POST , Method :: OPTIONS ] )
@@ -433,8 +435,8 @@ async fn handle_read(
433435 vault_path : & state. vault_path ,
434436 profile : state. profile . as_ref ( ) . as_ref ( ) ,
435437 } ;
436- let note = context :: context_read ( & ctx , & file )
437- . map_err ( |e| ApiError :: internal ( & format ! ( "{e:#}" ) ) ) ?;
438+ let note =
439+ context :: context_read ( & ctx , & file ) . map_err ( |e| ApiError :: internal ( & format ! ( "{e:#}" ) ) ) ?;
438440 Ok ( Json ( serde_json:: json!( note) ) )
439441}
440442
@@ -485,8 +487,7 @@ async fn handle_vault_map(
485487 vault_path : & state. vault_path ,
486488 profile : state. profile . as_ref ( ) . as_ref ( ) ,
487489 } ;
488- let map = context:: vault_map ( & ctx)
489- . map_err ( |e| ApiError :: internal ( & format ! ( "{e:#}" ) ) ) ?;
490+ let map = context:: vault_map ( & ctx) . map_err ( |e| ApiError :: internal ( & format ! ( "{e:#}" ) ) ) ?;
490491 Ok ( Json ( serde_json:: json!( map) ) )
491492}
492493
@@ -502,8 +503,8 @@ async fn handle_who(
502503 vault_path : & state. vault_path ,
503504 profile : state. profile . as_ref ( ) . as_ref ( ) ,
504505 } ;
505- let person = context :: context_who ( & ctx , & name )
506- . map_err ( |e| ApiError :: internal ( & format ! ( "{e:#}" ) ) ) ?;
506+ let person =
507+ context :: context_who ( & ctx , & name ) . map_err ( |e| ApiError :: internal ( & format ! ( "{e:#}" ) ) ) ?;
507508 Ok ( Json ( serde_json:: json!( person) ) )
508509}
509510
@@ -519,8 +520,8 @@ async fn handle_project(
519520 vault_path : & state. vault_path ,
520521 profile : state. profile . as_ref ( ) . as_ref ( ) ,
521522 } ;
522- let proj = context :: context_project ( & ctx , & name )
523- . map_err ( |e| ApiError :: internal ( & format ! ( "{e:#}" ) ) ) ?;
523+ let proj =
524+ context :: context_project ( & ctx , & name ) . map_err ( |e| ApiError :: internal ( & format ! ( "{e:#}" ) ) ) ?;
524525 Ok ( Json ( serde_json:: json!( proj) ) )
525526}
526527
@@ -576,55 +577,64 @@ async fn record_write(recent_writes: &RecentWrites, path: &std::path::Path) {
576577fn parse_frontmatter_ops ( operations : & [ serde_json:: Value ] ) -> Result < Vec < FrontmatterOp > , ApiError > {
577578 let mut ops = Vec :: with_capacity ( operations. len ( ) ) ;
578579 for op_val in operations {
579- let op_str = op_val
580- . get ( "op" )
581- . and_then ( |v| v. as_str ( ) )
582- . ok_or_else ( || ApiError :: bad_request ( "each operation must have an \" op\" string field" ) ) ?;
580+ let op_str = op_val. get ( "op" ) . and_then ( |v| v. as_str ( ) ) . ok_or_else ( || {
581+ ApiError :: bad_request ( "each operation must have an \" op\" string field" )
582+ } ) ?;
583583 match op_str {
584584 "set" => {
585- let key = op_val
586- . get ( "key" )
587- . and_then ( |v| v. as_str ( ) )
588- . ok_or_else ( || ApiError :: bad_request ( "\" set\" operation requires a \" key\" field" ) ) ?;
585+ let key = op_val. get ( "key" ) . and_then ( |v| v. as_str ( ) ) . ok_or_else ( || {
586+ ApiError :: bad_request ( "\" set\" operation requires a \" key\" field" )
587+ } ) ?;
589588 let value = op_val
590589 . get ( "value" )
591590 . and_then ( |v| v. as_str ( ) )
592- . ok_or_else ( || ApiError :: bad_request ( "\" set\" operation requires a \" value\" field" ) ) ?;
591+ . ok_or_else ( || {
592+ ApiError :: bad_request ( "\" set\" operation requires a \" value\" field" )
593+ } ) ?;
593594 ops. push ( FrontmatterOp :: Set ( key. to_string ( ) , value. to_string ( ) ) ) ;
594595 }
595596 "remove" => {
596- let key = op_val
597- . get ( "key" )
598- . and_then ( |v| v. as_str ( ) )
599- . ok_or_else ( || ApiError :: bad_request ( "\" remove\" operation requires a \" key\" field" ) ) ?;
597+ let key = op_val. get ( "key" ) . and_then ( |v| v. as_str ( ) ) . ok_or_else ( || {
598+ ApiError :: bad_request ( "\" remove\" operation requires a \" key\" field" )
599+ } ) ?;
600600 ops. push ( FrontmatterOp :: Remove ( key. to_string ( ) ) ) ;
601601 }
602602 "add_tag" => {
603603 let value = op_val
604604 . get ( "value" )
605605 . and_then ( |v| v. as_str ( ) )
606- . ok_or_else ( || ApiError :: bad_request ( "\" add_tag\" operation requires a \" value\" field" ) ) ?;
606+ . ok_or_else ( || {
607+ ApiError :: bad_request ( "\" add_tag\" operation requires a \" value\" field" )
608+ } ) ?;
607609 ops. push ( FrontmatterOp :: AddTag ( value. to_string ( ) ) ) ;
608610 }
609611 "remove_tag" => {
610612 let value = op_val
611613 . get ( "value" )
612614 . and_then ( |v| v. as_str ( ) )
613- . ok_or_else ( || ApiError :: bad_request ( "\" remove_tag\" operation requires a \" value\" field" ) ) ?;
615+ . ok_or_else ( || {
616+ ApiError :: bad_request ( "\" remove_tag\" operation requires a \" value\" field" )
617+ } ) ?;
614618 ops. push ( FrontmatterOp :: RemoveTag ( value. to_string ( ) ) ) ;
615619 }
616620 "add_alias" => {
617621 let value = op_val
618622 . get ( "value" )
619623 . and_then ( |v| v. as_str ( ) )
620- . ok_or_else ( || ApiError :: bad_request ( "\" add_alias\" operation requires a \" value\" field" ) ) ?;
624+ . ok_or_else ( || {
625+ ApiError :: bad_request ( "\" add_alias\" operation requires a \" value\" field" )
626+ } ) ?;
621627 ops. push ( FrontmatterOp :: AddAlias ( value. to_string ( ) ) ) ;
622628 }
623629 "remove_alias" => {
624630 let value = op_val
625631 . get ( "value" )
626632 . and_then ( |v| v. as_str ( ) )
627- . ok_or_else ( || ApiError :: bad_request ( "\" remove_alias\" operation requires a \" value\" field" ) ) ?;
633+ . ok_or_else ( || {
634+ ApiError :: bad_request (
635+ "\" remove_alias\" operation requires a \" value\" field" ,
636+ )
637+ } ) ?;
628638 ops. push ( FrontmatterOp :: RemoveAlias ( value. to_string ( ) ) ) ;
629639 }
630640 unknown => {
@@ -905,7 +915,9 @@ mod tests {
905915 let rate_limiter = Arc :: new ( RateLimiter :: new ( config. rate_limit ) ) ;
906916 ApiState {
907917 store : Arc :: new ( Mutex :: new ( store) ) ,
908- embedder : Arc :: new ( Mutex :: new ( Box :: new ( DummyEmbedder ) as Box < dyn EmbedModel + Send > ) ) ,
918+ embedder : Arc :: new ( Mutex :: new (
919+ Box :: new ( DummyEmbedder ) as Box < dyn EmbedModel + Send >
920+ ) ) ,
909921 vault_path : Arc :: new ( PathBuf :: from ( "/tmp/test-vault" ) ) ,
910922 profile : Arc :: new ( None ) ,
911923 orchestrator : None ,
0 commit comments