bugfix: adding TextSvg to the saving and loading functions
Some checks failed
/ clippy (push) Failing after 4m59s
/ test (push) Failing after 5m29s

This commit is contained in:
Chris Cochrun 2026-02-23 10:01:34 -06:00
parent 605cf4c271
commit 0710eb9609
2 changed files with 42 additions and 11 deletions

View file

@ -77,6 +77,13 @@ pub fn save(
}
}
let mut append_file = |path: PathBuf| -> Result<()> {
let file_name = path.file_name().unwrap_or_default();
let mut file = fs::File::open(&path).into_diagnostic()?;
tar.append_file(file_name, &mut file).into_diagnostic()?;
Ok(())
};
for item in list {
let background;
let audio: Option<PathBuf>;
@ -113,21 +120,22 @@ pub fn save(
if let Some(path) = audio
&& path.exists()
{
let file_name = path.file_name().unwrap_or_default();
debug!(?path);
let mut file = fs::File::open(&path).into_diagnostic()?;
tar.append_file(file_name, &mut file)
.into_diagnostic()?;
append_file(path)?;
}
if let Some(background) = background
&& let path = background.path
&& path.exists()
{
debug!(?path);
let file_name = path.file_name().unwrap_or_default();
let mut file = fs::File::open(&path).into_diagnostic()?;
tar.append_file(file_name, &mut file)
.into_diagnostic()?;
append_file(path)?;
}
for slide in item.slides {
if let Some(svg) = slide.text_svg
&& let Some(path) = svg.path
{
append_file(path)?;
}
}
}
@ -206,6 +214,11 @@ pub fn load(path: impl AsRef<Path>) -> Result<Vec<ServiceItem>> {
let file_name = file.file_name();
let audio_path =
slide.audio().clone().unwrap_or_default();
let text_path = slide
.text_svg
.as_ref()
.map(|svg| svg.path.clone())
.flatten();
if Some(file_name.as_os_str())
== slide.background.path.file_name()
{
@ -217,6 +230,17 @@ pub fn load(path: impl AsRef<Path>) -> Result<Vec<ServiceItem>> {
.clone()
.set_audio(Some(file.path()));
*slide = new_slide;
} else if Some(file_name.as_os_str())
== text_path
.clone()
.unwrap_or_default()
.file_name()
{
slide
.text_svg
.as_mut()
.map(|svg| svg.path = Some(file.path()));
dbg!(&slide);
}
}
}
@ -391,7 +415,12 @@ mod test {
slide.text_svg.as_ref().map_or(Err(String::from("There is no TextSvg for this song")), |text_svg| {
text_svg.path.as_ref().map_or(Err(String::from("There is no path in this song's TextSvg")), |path| {
if path.exists() {
Ok(())
let mut path = path.clone();
if path.pop() && path == cache_dir {
Ok(())
} else {
Err(String::from("The path of the TextSvg isn't in the load directory"))
}
} else {
Err(String::from("The path in this TextSvg doesn't exist"))
}

View file

@ -467,6 +467,7 @@ impl TextSvg {
if path.exists() {
// debug!("cached");
let handle = Handle::from_path(&path);
self.path = Some(path.to_path_buf());
self.handle = Some(handle);
return self;
}
@ -497,11 +498,12 @@ impl TextSvg {
resvg::render(&resvg_tree, transform, &mut pixmap.as_mut());
// debug!("rendered");
if let Some(path) = cache
&& let Err(e) = pixmap.save_png(&path)
if let Some(path) = cache.as_ref()
&& let Err(e) = pixmap.save_png(path)
{
error!(?e, "Couldn't save a copy of the text");
}
self.path = cache;
// debug!("saved");
// let handle = Handle::from_path(path);