feat: forced migrate report
Forced migrate is a tool which creates a mapping from published nostr events to old void.cat links, this report can be used later to prompt the user to mirror their files to nostr.download
This commit is contained in:
parent
37e158550a
commit
623bb8f0b5
1139
Cargo.lock
generated
1139
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
11
Cargo.toml
@ -7,6 +7,10 @@ edition = "2021"
|
|||||||
name = "void_cat_migrate"
|
name = "void_cat_migrate"
|
||||||
required-features = ["bin-void-cat-migrate"]
|
required-features = ["bin-void-cat-migrate"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "void_cat_forced_migrate"
|
||||||
|
required-features = ["bin-void-cat-force-migrate"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "route96"
|
name = "route96"
|
||||||
path = "src/bin/main.rs"
|
path = "src/bin/main.rs"
|
||||||
@ -21,6 +25,7 @@ labels = ["nip96", "dep:candle-core", "dep:candle-nn", "dep:candle-transformers"
|
|||||||
nip96 = ["media-compression"]
|
nip96 = ["media-compression"]
|
||||||
blossom = []
|
blossom = []
|
||||||
bin-void-cat-migrate = ["dep:sqlx-postgres"]
|
bin-void-cat-migrate = ["dep:sqlx-postgres"]
|
||||||
|
bin-void-cat-force-migrate = ["dep:regex", "dep:nostr-cursor"]
|
||||||
torrent-v2 = []
|
torrent-v2 = []
|
||||||
analytics = []
|
analytics = []
|
||||||
void-cat-redirects = ["dep:sqlx-postgres"]
|
void-cat-redirects = ["dep:sqlx-postgres"]
|
||||||
@ -31,12 +36,12 @@ react-ui = []
|
|||||||
log = "0.4.21"
|
log = "0.4.21"
|
||||||
nostr = "0.37.0"
|
nostr = "0.37.0"
|
||||||
pretty_env_logger = "0.5.0"
|
pretty_env_logger = "0.5.0"
|
||||||
rocket = { version = "0.5.0", features = ["json"] }
|
rocket = { version = "0.5.1", features = ["json"] }
|
||||||
tokio = { version = "1.37.0", features = ["rt", "rt-multi-thread", "macros"] }
|
tokio = { version = "1.37.0", features = ["rt", "rt-multi-thread", "macros"] }
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
hex = { version = "0.4.3", features = ["serde"] }
|
hex = { version = "0.4.3", features = ["serde"] }
|
||||||
serde = { version = "1.0.198", features = ["derive"] }
|
serde = { version = "1.0.198", features = ["derive"] }
|
||||||
uuid = { version = "1.8.0", features = ["v4"] }
|
uuid = { version = "1.8.0", features = ["v4", "serde"] }
|
||||||
anyhow = "^1.0.82"
|
anyhow = "^1.0.82"
|
||||||
sha2 = "0.10.8"
|
sha2 = "0.10.8"
|
||||||
sqlx = { version = "0.8.1", features = ["mysql", "runtime-tokio", "chrono", "uuid"] }
|
sqlx = { version = "0.8.1", features = ["mysql", "runtime-tokio", "chrono", "uuid"] }
|
||||||
@ -55,4 +60,6 @@ candle-nn = { git = "https://git.v0l.io/huggingface/candle.git", tag = "0.8.1",
|
|||||||
candle-transformers = { git = "https://git.v0l.io/huggingface/candle.git", tag = "0.8.1", optional = true }
|
candle-transformers = { git = "https://git.v0l.io/huggingface/candle.git", tag = "0.8.1", optional = true }
|
||||||
sqlx-postgres = { version = "0.8.2", optional = true, features = ["chrono", "uuid"] }
|
sqlx-postgres = { version = "0.8.2", optional = true, features = ["chrono", "uuid"] }
|
||||||
http-range-header = { version = "0.4.2", optional = true }
|
http-range-header = { version = "0.4.2", optional = true }
|
||||||
|
nostr-cursor = { git = "https://git.v0l.io/Kieran/nostr_backup_proc.git", branch = "main", optional = true }
|
||||||
|
regex = { version = "1.11.1", optional = true }
|
||||||
|
|
||||||
|
70
src/bin/void_cat_forced_migrate.rs
Normal file
70
src/bin/void_cat_forced_migrate.rs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
use clap::Parser;
|
||||||
|
use log::{info, warn};
|
||||||
|
use nostr::serde_json;
|
||||||
|
use nostr_cursor::cursor::NostrCursor;
|
||||||
|
use regex::Regex;
|
||||||
|
use rocket::futures::StreamExt;
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use tokio::fs::File;
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(version, about)]
|
||||||
|
struct ProgramArgs {
|
||||||
|
/// Directory pointing to archives to scan
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub archive: PathBuf,
|
||||||
|
|
||||||
|
/// Output path .csv
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub output: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), anyhow::Error> {
|
||||||
|
pretty_env_logger::init();
|
||||||
|
|
||||||
|
let args: ProgramArgs = ProgramArgs::parse();
|
||||||
|
|
||||||
|
let mut report: HashMap<String, HashSet<Uuid>> = HashMap::new();
|
||||||
|
|
||||||
|
let mut binding = NostrCursor::new(args.archive);
|
||||||
|
let mut cursor = Box::pin(binding.walk());
|
||||||
|
let matcher = Regex::new(r"void\.cat/d/(\w+)")?;
|
||||||
|
while let Some(Ok(e)) = cursor.next().await {
|
||||||
|
if e.content.contains("void.cat") {
|
||||||
|
let links = matcher.captures_iter(&e.content).collect::<Vec<_>>();
|
||||||
|
for link in links {
|
||||||
|
let g = link.get(1).unwrap().as_str();
|
||||||
|
let base58 = if let Ok(b) = nostr::bitcoin::base58::decode(g) {
|
||||||
|
b
|
||||||
|
} else {
|
||||||
|
warn!("Invalid base58 id {}", g);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let uuid = if let Ok(u) = Uuid::from_slice_le(base58.as_slice()) {
|
||||||
|
u
|
||||||
|
} else {
|
||||||
|
warn!("Invalid uuid {}", g);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
info!("Got link: {} => {}", g, e.pubkey);
|
||||||
|
if let Some(ur) = report.get_mut(&e.pubkey) {
|
||||||
|
ur.insert(uuid);
|
||||||
|
} else {
|
||||||
|
report.insert(e.pubkey.clone(), HashSet::from([uuid]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let json = serde_json::to_string(&report)?;
|
||||||
|
File::create(args.output)
|
||||||
|
.await?
|
||||||
|
.write_all(json.as_bytes())
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user