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