diff --git a/Cargo.lock b/Cargo.lock index 2f77637..75e4888 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -98,6 +98,7 @@ dependencies = [ "hex", "regex", "rusqlite", + "serde_json", "sha3", "uuid", ] @@ -339,6 +340,12 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + [[package]] name = "js-sys" version = "0.3.81" @@ -487,6 +494,48 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + [[package]] name = "sha3" version = "0.10.8" @@ -802,3 +851,9 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index b3ed74d..5b0d0aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,5 +10,6 @@ clap = { version = "4.5.48", features = ["derive"] } hex = "0.4.3" regex = "1.12.2" rusqlite = { version = "0.32.1", features = ["bundled"] } +serde_json = "1.0.132" sha3 = "0.10.8" uuid = { version = "1.18.1", features = ["v4"] } diff --git a/src/main.rs b/src/main.rs index 833bb59..7923c74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use anyhow::{Context, Result}; use chrono::Local; use clap::{Parser, Subcommand}; +use serde_json::json; use std::{ collections::HashSet, env, fs, @@ -495,11 +496,11 @@ fn record_media_entry( title: None, visibility: "private".to_string(), representation_kind: representation_kind.to_string(), - source_metadata_json: format!( - r#"{{"requested_locator":"{}","canonical_locator":"{}"}}"#, - json_escape(requested_locator), - json_escape(canonical_locator) - ), + source_metadata_json: json!({ + "requested_locator": requested_locator, + "canonical_locator": canonical_locator + }) + .to_string(), display_metadata_json: None, }, )?; @@ -557,11 +558,11 @@ fn record_tweet_entry( title: None, visibility: "private".to_string(), representation_kind: representation_kind.to_string(), - source_metadata_json: format!( - r#"{{"tweet_id":"{}","requested_locator":"{}"}}"#, - json_escape(tweet_id), - json_escape(requested_locator) - ), + source_metadata_json: json!({ + "tweet_id": tweet_id, + "requested_locator": requested_locator + }) + .to_string(), display_metadata_json: None, }, )?; @@ -627,10 +628,6 @@ fn tweet_raw_artifacts(tweet_json: &str) -> Vec<(String, String)> { artifacts } -fn json_escape(input: &str) -> String { - input.replace('\\', "\\\\").replace('"', "\\\"") -} - fn fail_archive_and_exit( conn: &rusqlite::Connection, run: &database::ArchiveRun,