diff --git a/mediarepo-daemon/Cargo.lock b/mediarepo-daemon/Cargo.lock index 2c22cda..09927fb 100644 --- a/mediarepo-daemon/Cargo.lock +++ b/mediarepo-daemon/Cargo.lock @@ -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", diff --git a/mediarepo-daemon/mediarepo-core/Cargo.lock b/mediarepo-daemon/mediarepo-core/Cargo.lock index 503932e..36d52b5 100644 --- a/mediarepo-daemon/mediarepo-core/Cargo.lock +++ b/mediarepo-daemon/mediarepo-core/Cargo.lock @@ -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", diff --git a/mediarepo-daemon/mediarepo-core/Cargo.toml b/mediarepo-daemon/mediarepo-core/Cargo.toml index ab1bffc..b226f7e 100644 --- a/mediarepo-daemon/mediarepo-core/Cargo.toml +++ b/mediarepo-daemon/mediarepo-core/Cargo.toml @@ -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" diff --git a/mediarepo-daemon/mediarepo-database/Cargo.lock b/mediarepo-daemon/mediarepo-database/Cargo.lock index 7b86779..f628953 100644 --- a/mediarepo-daemon/mediarepo-database/Cargo.lock +++ b/mediarepo-daemon/mediarepo-database/Cargo.lock @@ -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", diff --git a/mediarepo-daemon/mediarepo-model/Cargo.lock b/mediarepo-daemon/mediarepo-model/Cargo.lock index 899c871..b449de6 100644 --- a/mediarepo-daemon/mediarepo-model/Cargo.lock +++ b/mediarepo-daemon/mediarepo-model/Cargo.lock @@ -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", diff --git a/mediarepo-daemon/mediarepo-model/src/thumbnail.rs b/mediarepo-daemon/mediarepo-model/src/thumbnail.rs index 6b2982b..be45be5 100644 --- a/mediarepo-daemon/mediarepo-model/src/thumbnail.rs +++ b/mediarepo-daemon/mediarepo-model/src/thumbnail.rs @@ -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> { 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(()) + } } diff --git a/mediarepo-daemon/mediarepo-socket/Cargo.lock b/mediarepo-daemon/mediarepo-socket/Cargo.lock index 88789e0..ca24f33 100644 --- a/mediarepo-daemon/mediarepo-socket/Cargo.lock +++ b/mediarepo-daemon/mediarepo-socket/Cargo.lock @@ -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", diff --git a/mediarepo-daemon/mediarepo-socket/Cargo.toml b/mediarepo-daemon/mediarepo-socket/Cargo.toml index 8dac018..df3631f 100644 --- a/mediarepo-daemon/mediarepo-socket/Cargo.toml +++ b/mediarepo-daemon/mediarepo-socket/Cargo.toml @@ -34,4 +34,4 @@ features = ["tokio-executor"] [dependencies.mediarepo-api] git = "https://github.com/Trivernis/mediarepo-api.git" -rev = "6fbc72699a565b1ca3f76f58c3dafbe9790c758e" \ No newline at end of file +rev = "17fb433f4d682aac427730acfacb571b2bf14544" \ No newline at end of file diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs index d6a47cd..2bd0835 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs @@ -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( + ctx: &Context, + event: Event, + ) -> IPCResult<()> { + let repo = get_repo_from_context(ctx).await; + let id = event.data::()?; + 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)]