File tree Expand file tree Collapse file tree 5 files changed +25
-24
lines changed
Expand file tree Collapse file tree 5 files changed +25
-24
lines changed Original file line number Diff line number Diff line change 11//! TOML format support for document conversion
22
3- use anyhow:: Result ;
3+ use anyhow:: { Result , Context } ;
44use serde_json:: Value ;
55
66/// Convert TOML to JSON
7- pub fn toml_to_json ( toml : & str ) -> Result < String > {
8- // Placeholder: use toml crate in production
9- let value: Value = serde_json:: json!( {
10- "toml_content" : toml
11- } ) ;
7+ pub fn toml_to_json ( toml_str : & str ) -> Result < String > {
8+ let value: Value = toml:: from_str ( toml_str)
9+ . context ( "Failed to parse TOML" ) ?;
1210 Ok ( serde_json:: to_string_pretty ( & value) ?)
1311}
1412
1513/// Convert JSON to TOML
1614pub fn json_to_toml ( json : & str ) -> Result < String > {
1715 let value: Value = serde_json:: from_str ( json) ?;
18- // Placeholder: use toml crate for proper serialization
19- Ok ( format ! ( "# TOML \n [data] \n content = '''{}'''" , value ) )
16+ toml:: to_string_pretty ( & value )
17+ . context ( "Failed to serialize to TOML" )
2018}
2119
2220/// Validate TOML syntax
Original file line number Diff line number Diff line change 11//! XML format support for document conversion
22
3- use anyhow:: Result ;
3+ use anyhow:: { Result , Context } ;
44use serde_json:: Value ;
5+ use quick_xml:: de:: from_str as xml_from_str;
6+ use quick_xml:: se:: to_string as xml_to_string;
57
68/// Convert XML to JSON
79pub fn xml_to_json ( xml : & str ) -> Result < String > {
8- // Placeholder: use quick-xml or serde-xml-rs in production
9- let value: Value = serde_json:: json!( {
10- "xml_root" : {
11- "content" : xml
12- }
13- } ) ;
10+ let value: Value = xml_from_str ( xml)
11+ . context ( "Failed to parse XML" ) ?;
1412 Ok ( serde_json:: to_string_pretty ( & value) ?)
1513}
1614
1715/// Convert JSON to XML
1816pub fn json_to_xml ( json : & str ) -> Result < String > {
1917 let value: Value = serde_json:: from_str ( json) ?;
20- Ok ( format ! ( "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n <root>\n {}\n </root>" ,
21- serde_json:: to_string_pretty( & value) ?) )
18+ let xml = xml_to_string ( & value)
19+ . context ( "Failed to serialize to XML" ) ?;
20+ Ok ( format ! ( "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n {}" , xml) )
2221}
2322
2423/// Validate XML syntax
Original file line number Diff line number Diff line change @@ -7,18 +7,14 @@ use serde_json::Value;
77
88/// Convert YAML to JSON
99pub fn yaml_to_json ( yaml : & str ) -> Result < String > {
10- // In production, use serde_yaml crate
11- // Placeholder implementation
12- let value: Value = serde_json:: from_str ( & format ! ( r#"{{"yaml_content": "{}"}}"# , yaml. escape_default( ) ) ) ?;
10+ let value: Value = serde_yaml:: from_str ( yaml) ?;
1311 Ok ( serde_json:: to_string_pretty ( & value) ?)
1412}
1513
1614/// Convert JSON to YAML
1715pub fn json_to_yaml ( json : & str ) -> Result < String > {
18- // In production, use serde_yaml crate
19- // Placeholder implementation
2016 let value: Value = serde_json:: from_str ( json) ?;
21- Ok ( format ! ( "# YAML representation \n {}" , serde_json :: to_string_pretty ( & value) ?) )
17+ Ok ( serde_yaml :: to_string ( & value) ?)
2218}
2319
2420/// Convert YAML to Markdown
Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ async fn validate_document(
177177async fn get_stats ( State ( state) : State < Arc < ServerState > > ) -> Json < ServerStats > {
178178 Json ( ServerStats {
179179 document_count : state. documents . count ( ) ,
180- uptime_seconds : 0 , // TODO: Track actual uptime
180+ uptime_seconds : state . health_checker . uptime_seconds ( ) ,
181181 version : env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ,
182182 } )
183183}
Original file line number Diff line number Diff line change @@ -255,6 +255,14 @@ impl HealthChecker {
255255 }
256256 }
257257
258+ /// Get uptime in seconds
259+ pub fn uptime_seconds ( & self ) -> u64 {
260+ Utc :: now ( )
261+ . signed_duration_since ( self . start_time )
262+ . num_seconds ( )
263+ . max ( 0 ) as u64
264+ }
265+
258266 /// Perform health check
259267 pub async fn check ( & self , metrics : & Metrics ) -> HealthStatus {
260268 let mut checks = HashMap :: new ( ) ;
You can’t perform that action at this time.
0 commit comments