diff options
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/kittybox_database_converter.rs | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/bin/kittybox_database_converter.rs b/src/bin/kittybox_database_converter.rs index ff28d49..900a5c6 100644 --- a/src/bin/kittybox_database_converter.rs +++ b/src/bin/kittybox_database_converter.rs @@ -1,6 +1,5 @@ use anyhow::{anyhow, Context}; use redis::{self, AsyncCommands}; -use futures_util::StreamExt; use kittybox::database::Storage; use kittybox::database::FileStorage; use std::collections::HashMap; @@ -14,26 +13,33 @@ async fn convert_from_redis<S: Storage>(from: String, new_storage: S) -> anyhow: // Rebinding to convince the borrow checker we're not smuggling stuff outta scope let storage = &new_storage; - conn.hscan::<_, String>("posts").await?.map(|it| async move { - let json = serde_json::from_str(&it); - (it, json) - }).for_each_concurrent(8, |it| async move { - let (orig, res): (String, serde_json::Result<serde_json::Value>) = it.await; - match res { - Ok(json) => { - // XXX this assumes a trusted database that was created with Kittybox that checks for UID matching user token's prefix - let user = &(url::Url::parse(json["properties"]["uid"][0].as_str().unwrap()).unwrap().origin().ascii_serialization().clone() + "/"); - if let Err(err) = storage.clone().put_post(&json, user).await { - eprintln!("Error saving post: {}", err); - } - }, - Err(err) => { - eprintln!("Error: {} (rejected JSON follows below on stderr)", err); - eprintln!("{}", orig); - } + let mut stream = conn.hscan::<_, String>("posts").await?; + + while let Some(key) = stream.next_item().await { + let value = serde_json::from_str::<serde_json::Value>( + &stream.next_item().await + .ok_or(anyhow!("Failed to find a corresponding value for the key"))? + )?; + + println!("{}, {:?}", key, value); + + if value["see_other"].is_string() { + continue } - }).await; + let user = &( + url::Url::parse( + value["properties"]["uid"][0] + .as_str().unwrap() + ).unwrap().origin().ascii_serialization().clone() + + "/" + ); + if let Err(err) = storage.clone().put_post(&value, user).await { + eprintln!("Error saving post: {}", err); + } + + } + let mut stream: redis::AsyncIter<String> = conn.scan_match("settings_*").await?; while let Some(key) = stream.next_item().await { let mut conn = db.get_async_std_connection().await.context("Failed to connect to Redis")?; |