diff --git a/src/lib.rs b/src/lib.rs index 4cd87b2..78bd879 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,7 +69,7 @@ use self::{ queue::queue_generate, repo::{ sled::SledRepo, Alias, DeleteToken, FullRepo, HashRepo, IdentifierRepo, QueueRepo, Repo, - SettingsRepo, UploadId, UploadResult, + SettingsRepo, UploadId, UploadResult, VariantAccessRepo, }, serde_str::Serde, store::{ @@ -647,8 +647,15 @@ async fn process_details( }))); }; + let thumbnail_string = thumbnail_path.to_string_lossy().to_string(); + + if !config.server.read_only { + repo.accessed(hash.clone(), thumbnail_string.clone()) + .await?; + } + let identifier = repo - .variant_identifier::(hash, thumbnail_path.to_string_lossy().to_string()) + .variant_identifier::(hash, thumbnail_string) .await? .ok_or(UploadError::MissingAlias)?; @@ -706,6 +713,10 @@ async fn process( (hash, alias, true) }; + if !config.server.read_only { + repo.accessed(hash.clone(), path_string.clone()).await?; + } + let identifier_opt = repo .variant_identifier::(hash.clone(), path_string) .await?; @@ -819,6 +830,10 @@ async fn process_head( return Ok(HttpResponse::NotFound().finish()); }; + if !config.server.read_only { + repo.accessed(hash.clone(), path_string.clone()).await?; + } + let identifier_opt = repo .variant_identifier::(hash.clone(), path_string) .await?; diff --git a/src/repo.rs b/src/repo.rs index 898e0d5..3a0020e 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -188,6 +188,9 @@ pub(crate) trait VariantAccessRepo: BaseRepo { async fn accessed(&self, hash: Self::Bytes, variant: String) -> Result<(), RepoError>; + async fn contains_variant(&self, hash: Self::Bytes, variant: String) + -> Result; + async fn older_variants( &self, timestamp: time::OffsetDateTime, @@ -207,6 +210,14 @@ where T::accessed(self, hash, variant).await } + async fn contains_variant( + &self, + hash: Self::Bytes, + variant: String, + ) -> Result { + T::contains_variant(self, hash, variant).await + } + async fn older_variants( &self, timestamp: time::OffsetDateTime, diff --git a/src/repo/sled.rs b/src/repo/sled.rs index 2ef0329..de44482 100644 --- a/src/repo/sled.rs +++ b/src/repo/sled.rs @@ -354,6 +354,18 @@ impl VariantAccessRepo for SledRepo { .map_err(RepoError::from) } + async fn contains_variant( + &self, + hash: Self::Bytes, + variant: String, + ) -> Result { + let key = variant_access_key(&hash, &variant); + + let timestamp = b!(self.variant_access, variant_access.get(key)); + + Ok(timestamp.is_some()) + } + async fn older_variants( &self, timestamp: time::OffsetDateTime,