|
|
|
@ -10,8 +10,10 @@ use std::{
|
|
|
|
|
};
|
|
|
|
|
use tar::Archive;
|
|
|
|
|
|
|
|
|
|
use crate::cli::GeneratorOptions;
|
|
|
|
|
use crate::data::Outbox;
|
|
|
|
|
use crate::{
|
|
|
|
|
cli::GeneratorOptions,
|
|
|
|
|
data::{Outbox, Person},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mod cli;
|
|
|
|
|
mod data;
|
|
|
|
@ -20,7 +22,7 @@ fn main() {
|
|
|
|
|
let args = GeneratorOptions::parse();
|
|
|
|
|
|
|
|
|
|
if let Err(err) = setup_dirs(&args) {
|
|
|
|
|
eprintln!("Could not create output or temp directory");
|
|
|
|
|
eprintln!("Could not create output directory");
|
|
|
|
|
eprintln!("Error: {}", err);
|
|
|
|
|
std::process::exit(1);
|
|
|
|
|
}
|
|
|
|
@ -32,34 +34,18 @@ fn main() {
|
|
|
|
|
std::process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let outbox_text = archive_result.unwrap();
|
|
|
|
|
|
|
|
|
|
let data: Result<Outbox, serde_json::Error> = serde_json::from_str(outbox_text.as_str());
|
|
|
|
|
|
|
|
|
|
if let Err(err) = data {
|
|
|
|
|
eprintln!("Could not parse outbox file");
|
|
|
|
|
eprintln!("Error: {}", err);
|
|
|
|
|
std::process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
let (_outbox_text, actor_text) = archive_result.unwrap();
|
|
|
|
|
let outbox_text = fs::read_to_string("./temp/outbox-formatted.json").unwrap();
|
|
|
|
|
let (outbox, author) = parse_json(outbox_text, actor_text);
|
|
|
|
|
|
|
|
|
|
let data = data.unwrap();
|
|
|
|
|
println!("{:?}\n", outbox.ordered_items.first().unwrap());
|
|
|
|
|
|
|
|
|
|
println!("{:?}", data.ordered_items.first().unwrap());
|
|
|
|
|
println!("{:?}", author)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn setup_dirs(args: &GeneratorOptions) -> Result<(), std::io::Error> {
|
|
|
|
|
let temp_dir = Path::new(&args.temp_dir);
|
|
|
|
|
let output_dir = Path::new(&args.output_dir);
|
|
|
|
|
|
|
|
|
|
// Clear temp dir
|
|
|
|
|
if !temp_dir.exists() {
|
|
|
|
|
fs::create_dir(temp_dir)?
|
|
|
|
|
} else {
|
|
|
|
|
for entry in fs::read_dir(temp_dir)? {
|
|
|
|
|
fs::remove_file(entry?.path())?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create output dir
|
|
|
|
|
if !output_dir.exists() {
|
|
|
|
|
fs::create_dir(output_dir)?;
|
|
|
|
@ -77,7 +63,7 @@ fn setup_dirs(args: &GeneratorOptions) -> Result<(), std::io::Error> {
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn read_archive(args: &GeneratorOptions) -> Result<String, std::io::Error> {
|
|
|
|
|
fn read_archive(args: &GeneratorOptions) -> Result<(String, String), std::io::Error> {
|
|
|
|
|
let path = &args.archive_file;
|
|
|
|
|
|
|
|
|
|
let tar_gz = File::open(path)?;
|
|
|
|
@ -85,6 +71,7 @@ fn read_archive(args: &GeneratorOptions) -> Result<String, std::io::Error> {
|
|
|
|
|
let mut archive = Archive::new(tar);
|
|
|
|
|
|
|
|
|
|
let mut outbox_text = String::new();
|
|
|
|
|
let mut actor_text = String::new();
|
|
|
|
|
|
|
|
|
|
for (_, file) in archive.entries()?.enumerate() {
|
|
|
|
|
let mut file = file?;
|
|
|
|
@ -94,13 +81,30 @@ fn read_archive(args: &GeneratorOptions) -> Result<String, std::io::Error> {
|
|
|
|
|
let path = path_result?.clone();
|
|
|
|
|
path_str = String::from_str(&path.to_string_lossy()).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if path_str.starts_with("media_attachments") {
|
|
|
|
|
file.unpack_in(&args.output_dir)?;
|
|
|
|
|
} else if path_str.eq("outbox.json") {
|
|
|
|
|
file.read_to_string(&mut outbox_text)?;
|
|
|
|
|
} else {
|
|
|
|
|
match path_str.as_str() {
|
|
|
|
|
"outbox.json" => {
|
|
|
|
|
file.read_to_string(&mut outbox_text)?;
|
|
|
|
|
}
|
|
|
|
|
"actor.json" => {
|
|
|
|
|
file.read_to_string(&mut actor_text)?;
|
|
|
|
|
}
|
|
|
|
|
"avatar.png" => {
|
|
|
|
|
file.unpack_in(&args.output_dir)?;
|
|
|
|
|
}
|
|
|
|
|
"header.png" => {
|
|
|
|
|
file.unpack_in(&args.output_dir)?;
|
|
|
|
|
}
|
|
|
|
|
_ => (),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let test = if 1 > 0 { 'a' } else { 'b' };
|
|
|
|
|
|
|
|
|
|
if outbox_text.len() < 1 {
|
|
|
|
|
return Err(std::io::Error::new(
|
|
|
|
|
ErrorKind::Other,
|
|
|
|
@ -108,5 +112,35 @@ fn read_archive(args: &GeneratorOptions) -> Result<String, std::io::Error> {
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(outbox_text)
|
|
|
|
|
if actor_text.len() < 1 {
|
|
|
|
|
return Err(std::io::Error::new(
|
|
|
|
|
ErrorKind::Other,
|
|
|
|
|
"No actor.json in archive",
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok((outbox_text, actor_text))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parse_json(outbox_text: String, actor_text: String) -> (Outbox, Person) {
|
|
|
|
|
let outbox_parse: Result<Outbox, serde_json::Error> =
|
|
|
|
|
serde_json::from_str(outbox_text.as_str());
|
|
|
|
|
let actor_parse: Result<Person, serde_json::Error> = serde_json::from_str(actor_text.as_str());
|
|
|
|
|
|
|
|
|
|
if let Err(err) = outbox_parse {
|
|
|
|
|
eprintln!("Could not parse outbox file");
|
|
|
|
|
eprintln!("Error: {}", err);
|
|
|
|
|
std::process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Err(err) = actor_parse {
|
|
|
|
|
eprintln!("Could not parse actor file");
|
|
|
|
|
eprintln!("Error: {}", err);
|
|
|
|
|
std::process::exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let outbox = outbox_parse.unwrap();
|
|
|
|
|
let author = actor_parse.unwrap();
|
|
|
|
|
|
|
|
|
|
(outbox, author)
|
|
|
|
|
}
|
|
|
|
|