mirror of
https://codeberg.org/postscriptum/snac2nex.git
synced 2026-03-31 13:15:27 +00:00
fix missed attachment index extend on update, implement shared filepath function
This commit is contained in:
parent
4e41f3fdf8
commit
b8c5e2de86
2 changed files with 28 additions and 10 deletions
23
src/nex.rs
23
src/nex.rs
|
|
@ -130,6 +130,14 @@ impl Nex {
|
|||
fs::write(&s, updated.unwrap_or(published).to_string())?
|
||||
} else {
|
||||
if let Some(ref mut i) = index {
|
||||
if let Some(ref a) = attachments {
|
||||
for (n, (_, _, source)) in a.iter().enumerate() {
|
||||
match source {
|
||||
Source::File(f) => i.push(attachment::filepath(&d, f, n)),
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
}
|
||||
i.extend([d, f, p, s]);
|
||||
}
|
||||
return Ok(Sync {
|
||||
|
|
@ -162,22 +170,19 @@ impl Nex {
|
|||
match source {
|
||||
Source::Url(url) => url,
|
||||
Source::File(from) => {
|
||||
let mut to = PathBuf::from(&d);
|
||||
let f = format!(
|
||||
"{}{}",
|
||||
n + 1,
|
||||
from.extension()
|
||||
.map(|e| format!(".{}", e.to_string_lossy()))
|
||||
.unwrap_or_default(),
|
||||
let to = attachment::filepath(&d, &from, n);
|
||||
let uri = format!(
|
||||
"{}/{}",
|
||||
d.file_name().unwrap().to_string_lossy(),
|
||||
to.file_name().unwrap().to_string_lossy()
|
||||
);
|
||||
to.push(&f);
|
||||
if !to.exists() {
|
||||
self.attachment.sync(&from, &to).unwrap()
|
||||
}
|
||||
if let Some(ref mut i) = index {
|
||||
i.push(to);
|
||||
}
|
||||
format!("{}/{f}", d.file_name().unwrap().to_string_lossy())
|
||||
uri
|
||||
}
|
||||
}
|
||||
));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::{Result, bail};
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub enum Attachment {
|
||||
Copy,
|
||||
|
|
@ -62,3 +62,16 @@ impl Attachment {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filepath(d: &PathBuf, from: &Path, n: usize) -> PathBuf {
|
||||
let mut to = PathBuf::from(&d);
|
||||
let f = format!(
|
||||
"{}{}",
|
||||
n + 1,
|
||||
from.extension()
|
||||
.map(|e| format!(".{}", e.to_string_lossy()))
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
to.push(&f);
|
||||
to
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue