Skip to content

Commit

Permalink
Use mpb attached picture also for icons and collapsed folder
Browse files Browse the repository at this point in the history
  • Loading branch information
izderadicka committed Sep 4, 2022
1 parent 659a5a9 commit 6710480
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions crates/collection/src/audio_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ impl FolderLister {
files = f.files;
tags = f.tags;
is_file = true;
if cover.is_none() {
cover = f.cover;
}
if description.is_none() {
description = f.description;
}
// TODO: Should this be also collapsed?
//is_collapsed = true;
}
Expand Down
15 changes: 12 additions & 3 deletions src/services/icon/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use collection::{audio_meta::is_audio, extract_cover};
use headers::{ContentLength, ContentType};
use hyper::{Body, Response};
use image::io::Reader as ImageReader;
Expand All @@ -16,7 +17,7 @@ use super::subs::add_cache_headers;

pub mod cache;

pub fn icon_response(path: impl AsRef<Path>) -> Result<Response<Body>> {
pub fn icon_response(path: impl AsRef<Path> + std::fmt::Debug) -> Result<Response<Body>> {
let cache_enabled = !get_config().icons.cache_disabled;
let data = match if cache_enabled {
cached_icon(&path)
Expand Down Expand Up @@ -48,9 +49,17 @@ pub fn icon_response(path: impl AsRef<Path>) -> Result<Response<Body>> {
builder.body(data.into()).map_err(anyhow::Error::from)
}

pub fn scale_cover(path: impl AsRef<Path>) -> Result<Vec<u8>> {
pub fn scale_cover(path: impl AsRef<Path> + std::fmt::Debug) -> Result<Vec<u8>> {
use image::imageops::FilterType;
let img = ImageReader::open(&path)?.with_guessed_format()?.decode()?;
let img = if is_audio(&path) {
let data = extract_cover(&path)
.ok_or_else(|| anyhow::Error::msg("Cover is missing, but is expected"))?;
ImageReader::new(Cursor::new(data))
.with_guessed_format()?
.decode()?
} else {
ImageReader::open(&path)?.with_guessed_format()?.decode()?
};
let sz = get_config().icons.size;
let scaled = img.resize(
sz,
Expand Down

0 comments on commit 6710480

Please sign in to comment.