logging, formatting in previews/mod.rs
parent
8d51529f38
commit
172404a2d9
|
@ -1,6 +1,7 @@
|
|||
use crate::util::hash::Hash;
|
||||
use crate::{database::UpEndDatabase, util::hash::b58_encode};
|
||||
use anyhow::{anyhow, Result};
|
||||
use log::{debug, trace};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::File,
|
||||
|
@ -9,15 +10,15 @@ use std::{
|
|||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use self::audio::AudioPath;
|
||||
use self::image::ImagePath;
|
||||
use self::text::TextPath;
|
||||
use self::video::VideoPath;
|
||||
use self::audio::AudioPath;
|
||||
|
||||
pub mod audio;
|
||||
pub mod image;
|
||||
pub mod text;
|
||||
pub mod video;
|
||||
pub mod audio;
|
||||
|
||||
pub trait Previewable {
|
||||
fn get_thumbnail(&self) -> Result<Option<Vec<u8>>>;
|
||||
|
@ -52,11 +53,14 @@ impl PreviewStore {
|
|||
}
|
||||
|
||||
pub fn get(&self, hash: Hash) -> Result<Option<PathBuf>> {
|
||||
debug!("Preview for {hash:?} requested...");
|
||||
let path_mutex = self.get_path(&hash);
|
||||
let thumbpath = path_mutex.lock().unwrap();
|
||||
if thumbpath.exists() {
|
||||
trace!("Preview for {hash:?} already exists, returning {thumbpath:?}");
|
||||
Ok(Some(thumbpath.clone()))
|
||||
} else {
|
||||
trace!("Calculating preview for {hash:?}...");
|
||||
let connection = self.db.connection()?;
|
||||
let files = connection.retrieve_file(&hash)?;
|
||||
if let Some(file) = files.get(0) {
|
||||
|
@ -75,6 +79,8 @@ impl PreviewStore {
|
|||
_ => Err(anyhow!("Unknown file type, or file doesn't exist.")),
|
||||
}?;
|
||||
|
||||
trace!("Got preview for {hash:?}.");
|
||||
|
||||
if let Some(data) = preview {
|
||||
std::fs::create_dir_all(&self.path)?;
|
||||
let mut file = File::create(&*thumbpath)?;
|
||||
|
|
Loading…
Reference in New Issue