25 lines
511 B
Rust
25 lines
511 B
Rust
|
use std::path::PathBuf;
|
||
|
|
||
|
use bytes::Bytes;
|
||
|
|
||
|
pub(crate) struct Thumbnails {
|
||
|
folder: PathBuf,
|
||
|
}
|
||
|
|
||
|
impl Thumbnails {
|
||
|
pub(crate) fn new(folder: PathBuf) -> Thumbnails {
|
||
|
Thumbnails { folder }
|
||
|
}
|
||
|
|
||
|
pub(crate) fn get(&self, path: &str) -> Option<Bytes> {
|
||
|
let asset = self.folder.join(format!("{path}.jpg"));
|
||
|
|
||
|
if let Ok(data) = std::fs::read(asset) {
|
||
|
return Some(Bytes::from(data));
|
||
|
}
|
||
|
|
||
|
tracing::warn!("Thumbnail not found: {path}");
|
||
|
None
|
||
|
}
|
||
|
}
|