From 217ed2466caf00c2372a14bb435d27a87cff1ba0 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 12 Jul 2025 10:11:18 -0400 Subject: [PATCH] Fix the API for support desk headlines --- Cargo.lock | 13 +++++++ Cargo.toml | 1 + resources/Caddyfile | 1 + src/bin/kawari-frontier.rs | 80 +++++++++++++++++++++++++++++++------- 4 files changed, 81 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 149cd18..19fec6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2579,6 +2579,7 @@ dependencies = [ "rkon", "rusqlite", "serde", + "serde-xml-rs", "serde_json", "serde_yaml_ng", "sha1_smol", @@ -3883,6 +3884,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde-xml-rs" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53630160a98edebde0123eb4dfd0fce6adff091b2305db3154a9e920206eb510" +dependencies = [ + "log", + "serde", + "thiserror 1.0.69", + "xml-rs", +] + [[package]] name = "serde_derive" version = "1.0.219" diff --git a/Cargo.toml b/Cargo.toml index bb0437c..de42878 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ serde_json = { version = "1.0", features = ["std"], default-features = false } serde = { version = "1.0", features = ["derive"], default-features = false } serde_json = { version = "1.0", features = ["std"], default-features = false } serde_yaml_ng = { version = "0.10", default-features = false } +serde-xml-rs = { version = "0.8", default-features = false } # Logging tracing = { version = "0.1", default-features = false } diff --git a/resources/Caddyfile b/resources/Caddyfile index 8923009..d7d722c 100644 --- a/resources/Caddyfile +++ b/resources/Caddyfile @@ -33,6 +33,7 @@ frontier.ffxiv.localhost:80 { header { Server nginx -Via + Connection keep-alive } } diff --git a/src/bin/kawari-frontier.rs b/src/bin/kawari-frontier.rs index 67fa78c..a6d023d 100644 --- a/src/bin/kawari-frontier.rs +++ b/src/bin/kawari-frontier.rs @@ -87,7 +87,10 @@ where { fn into_response(self) -> Response { ( - [(header::CONTENT_TYPE, HeaderValue::from_static("text/xml"))], + [( + header::CONTENT_TYPE, + HeaderValue::from_static("application/xml"), + )], self.0, ) .into_response() @@ -100,36 +103,85 @@ impl From for Xml { } } -async fn session_get_init() -> Xml { +async fn session_get_init(body: String) -> Xml> { + dbg!(body); // TODO: just a guess - Xml(" + Xml( + " OK " - .to_string()) + .as_bytes() + .to_vec(), + ) } -async fn view_get_init() -> Xml { - Xml(" +async fn view_get_init() -> Xml> { + Xml( + " OK " - .to_string()) + .as_bytes() + .to_vec(), + ) } -async fn get_headline_all() -> Xml { - Xml(" -OK - - -" - .to_string()) +#[derive(Serialize)] +#[serde(rename = "item")] +struct Item { + title: String, + published: i64, + updated: i64, + lsb_id: String, + lsb_parentid: Option, + lsb_tag: Option, + #[serde(rename = "catId")] + cat_id: i32, + content: String, +} + +#[derive(Serialize)] +#[serde(rename = "information")] +struct Information { + #[serde(rename = "#content")] + items: Vec, +} + +#[derive(Serialize)] +#[serde(rename = "result")] +struct Result { + return_code: String, + information: Information, +} + +async fn get_headline_all() -> Xml> { + let result = Result { + return_code: "OK".to_string(), + information: Information { + items: vec![Item { + title: "Test".to_string(), + published: 1752130800, + updated: 1752130800, + lsb_id: "c8819ec6f93f6c56d760b42c2ba2f43fe6598fc8".to_string(), + lsb_parentid: None, + lsb_tag: None, + cat_id: 1, + content: "Hello, world!".to_string(), + }], + }, + }; + + Xml(serde_xml_rs::to_string(&result) + .unwrap() + .as_bytes() + .to_vec()) } #[tokio::main]