Simplified renaming code

This commit is contained in:
Brandon Rozek 2024-08-02 21:40:15 -07:00
parent e0d4722086
commit 43e24254b8
No known key found for this signature in database
GPG key ID: 26E457DA82C9F480

View file

@ -16,22 +16,15 @@ fn reformat_toot(x: &mut serde_json::Value) -> Result<(), String> {
.ok_or_else(|| "JSON not an object".to_string())?; .ok_or_else(|| "JSON not an object".to_string())?;
// URL -> Syndication // URL -> Syndication
let toot_url: serde_json::Value = toot
.get_mut("url")
.ok_or_else(|| "Missing URL".to_string())?
.to_owned();
toot.remove("uri"); toot.remove("uri");
toot.remove("url"); let toot_url = toot.remove("url")
toot.insert("syndication".to_string(), toot_url.to_owned()); .ok_or_else(|| "Missing URL".to_string())?;
toot.insert("syndication".to_string(), toot_url);
// Created At -> Date // Created At -> Date
let toot_date: serde_json::Value = toot let toot_date = toot.remove("created_at")
.get_mut("created_at") .ok_or_else(|| "Missing created_at".to_string())?;
.ok_or_else(|| "Missing created_at".to_string())? toot.insert("date".to_string(), toot_date);
.to_owned();
// Note: Already checked whether created_at exists
toot.remove("created_at");
toot.insert("date".to_string(), toot_date.to_owned());
// Strip out highly dynamic account information // Strip out highly dynamic account information
let account: &mut tera::Map<String, serde_json::Value> = toot let account: &mut tera::Map<String, serde_json::Value> = toot