Implement thumbnail delete command and update thumbnailer

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 3fb98188dc
commit e9d5aa6122

@ -855,8 +855,8 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "mediarepo-api"
version = "0.11.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=6fbc72699a565b1ca3f76f58c3dafbe9790c758e#6fbc72699a565b1ca3f76f58c3dafbe9790c758e"
version = "0.11.1"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=17fb433f4d682aac427730acfacb571b2bf14544#17fb433f4d682aac427730acfacb571b2bf14544"
dependencies = [
"chrono",
"serde",
@ -2076,9 +2076,9 @@ dependencies = [
[[package]]
name = "thumbnailer"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10341d6f800bc62e7b6cf98b78851385db843bdae629bc4353d30c2fde0ed011"
checksum = "4f5a7bb042dd56c9f08f46896e31a9e8bc8fcb3d4b0a0f9131a50a3b0d7e22c1"
dependencies = [
"image",
"mime",

@ -1407,9 +1407,9 @@ dependencies = [
[[package]]
name = "thumbnailer"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10341d6f800bc62e7b6cf98b78851385db843bdae629bc4353d30c2fde0ed011"
checksum = "4f5a7bb042dd56c9f08f46896e31a9e8bc8fcb3d4b0a0f9131a50a3b0d7e22c1"
dependencies = [
"image",
"mime",

@ -15,7 +15,7 @@ serde = "1.0.130"
rmp-ipc = "0.9.2"
typemap_rev = "0.1.5"
futures = "0.3.17"
thumbnailer = "0.1.0"
thumbnailer = "0.2.0"
itertools = "0.10.1"
glob = "0.3.0"

@ -1760,9 +1760,9 @@ dependencies = [
[[package]]
name = "thumbnailer"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10341d6f800bc62e7b6cf98b78851385db843bdae629bc4353d30c2fde0ed011"
checksum = "4f5a7bb042dd56c9f08f46896e31a9e8bc8fcb3d4b0a0f9131a50a3b0d7e22c1"
dependencies = [
"image",
"mime",

@ -1787,9 +1787,9 @@ dependencies = [
[[package]]
name = "thumbnailer"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10341d6f800bc62e7b6cf98b78851385db843bdae629bc4353d30c2fde0ed011"
checksum = "4f5a7bb042dd56c9f08f46896e31a9e8bc8fcb3d4b0a0f9131a50a3b0d7e22c1"
dependencies = [
"image",
"mime",

@ -1,9 +1,10 @@
use mediarepo_core::error::RepoResult;
use mediarepo_core::fs::thumbnail_store::Dimensions;
use std::path::PathBuf;
use tokio::fs::{File, OpenOptions};
use tokio::fs::{self, File, OpenOptions};
use tokio::io::BufReader;
#[derive(Debug)]
pub struct Thumbnail {
pub file_hash: String,
pub path: PathBuf,
@ -13,9 +14,17 @@ pub struct Thumbnail {
impl Thumbnail {
/// Returns the reader of the thumbnail file
#[tracing::instrument(level = "debug", skip(self))]
#[tracing::instrument(level = "debug")]
pub async fn get_reader(&self) -> RepoResult<BufReader<File>> {
let file = OpenOptions::new().read(true).open(&self.path).await?;
Ok(BufReader::new(file))
}
/// Deletes the thumbnail
#[tracing::instrument(level = "debug")]
pub async fn delete(self) -> RepoResult<()> {
fs::remove_file(&self.path).await?;
Ok(())
}
}

@ -802,8 +802,8 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "mediarepo-api"
version = "0.11.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=6fbc72699a565b1ca3f76f58c3dafbe9790c758e#6fbc72699a565b1ca3f76f58c3dafbe9790c758e"
version = "0.11.1"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=17fb433f4d682aac427730acfacb571b2bf14544#17fb433f4d682aac427730acfacb571b2bf14544"
dependencies = [
"chrono",
"serde",
@ -1923,9 +1923,9 @@ dependencies = [
[[package]]
name = "thumbnailer"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10341d6f800bc62e7b6cf98b78851385db843bdae629bc4353d30c2fde0ed011"
checksum = "4f5a7bb042dd56c9f08f46896e31a9e8bc8fcb3d4b0a0f9131a50a3b0d7e22c1"
dependencies = [
"image",
"mime",

@ -34,4 +34,4 @@ features = ["tokio-executor"]
[dependencies.mediarepo-api]
git = "https://github.com/Trivernis/mediarepo-api.git"
rev = "6fbc72699a565b1ca3f76f58c3dafbe9790c758e"
rev = "17fb433f4d682aac427730acfacb571b2bf14544"

@ -46,7 +46,8 @@ impl NamespaceProvider for FilesNamespace {
"read_file" => Self::read_file,
"get_thumbnails" => Self::thumbnails,
"get_thumbnail_of_size" => Self::get_thumbnail_of_size,
"update_file_name" => Self::update_file_name
"update_file_name" => Self::update_file_name,
"delete_thumbnails" => Self::delete_thumbnails
);
}
}
@ -299,6 +300,24 @@ impl FilesNamespace {
Ok(())
}
/// Deletes all thumbnails of a file
#[tracing::instrument(skip_all)]
async fn delete_thumbnails<S: AsyncProtocolStream>(
ctx: &Context<S>,
event: Event,
) -> IPCResult<()> {
let repo = get_repo_from_context(ctx).await;
let id = event.data::<FileIdentifier>()?;
let file = file_by_identifier(id, &repo).await?;
let thumbnails = repo.get_file_thumbnails(file.hash().to_owned()).await?;
for thumb in thumbnails {
thumb.delete().await?;
}
Ok(())
}
}
#[tracing::instrument(level = "trace", skip_all)]

Loading…
Cancel
Save