implement optional binary files copy

This commit is contained in:
postscriptum 2025-07-01 20:13:44 +03:00
parent cf8c676732
commit ef1ba39589
5 changed files with 101 additions and 43 deletions

View file

@ -21,12 +21,12 @@ fn main() -> Result<()> {
let s = Snac::init(c.source, c.user)?;
println!("export begin...");
let (mut u, mut t) = sync(&s, &n)?;
let (mut u, mut t) = sync(&s, &n, c.binary)?;
match c.rotate {
Some(r) => loop {
println!("queue completed (updated: {u} / total: {t}), await {r} seconds to rotate...");
std::thread::sleep(std::time::Duration::from_secs(r));
(u, t) = sync(&s, &n)?;
(u, t) = sync(&s, &n, c.binary)?;
},
None => println!("export completed (updated: {u} / total: {t})."),
}
@ -34,7 +34,7 @@ fn main() -> Result<()> {
Ok(())
}
fn sync(snac: &Snac, nex: &Nex) -> Result<(usize, usize)> {
fn sync(snac: &Snac, nex: &Nex, is_binary: bool) -> Result<(usize, usize)> {
let mut t = 0; // total
let mut u = 0; // updated
for user in &snac.users {
@ -49,12 +49,20 @@ fn sync(snac: &Snac, nex: &Nex) -> Result<(usize, usize)> {
content,
post.url,
post.attachment.map(|a| {
use nex::Source;
let mut attachments = Vec::with_capacity(a.len());
for attachment in a {
attachments.push((
attachment.name,
attachment.media_type,
attachment.url,
if is_binary {
Source::File(
user.file(attachment.url.split('/').next_back().unwrap())
.unwrap(),
)
} else {
Source::Url(attachment.url)
},
))
}
attachments