diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-04-23 10:35:43 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2024-04-23 10:35:43 +0200 |
commit | 4594e068dbba3d3d704728449fc6ccaaadaa82f1 (patch) | |
tree | 6a098fba87dcbcb9b7754609deaac159abb82b92 /aero-user/src/storage/in_memory.rs | |
parent | 936f851fdb120dd0b46c4effeabe0dbb508d4d3d (diff) | |
download | aerogramme-4594e068dbba3d3d704728449fc6ccaaadaa82f1.tar.gz aerogramme-4594e068dbba3d3d704728449fc6ccaaadaa82f1.zip |
PUT seems to work
Diffstat (limited to 'aero-user/src/storage/in_memory.rs')
-rw-r--r-- | aero-user/src/storage/in_memory.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/aero-user/src/storage/in_memory.rs b/aero-user/src/storage/in_memory.rs index a676797..9ef2721 100644 --- a/aero-user/src/storage/in_memory.rs +++ b/aero-user/src/storage/in_memory.rs @@ -1,9 +1,12 @@ -use crate::storage::*; use std::collections::BTreeMap; use std::ops::Bound::{self, Excluded, Included, Unbounded}; use std::sync::RwLock; + +use sodiumoxide::{hex, crypto::hash}; use tokio::sync::Notify; +use crate::storage::*; + /// This implementation is very inneficient, and not completely correct /// Indeed, when the connector is dropped, the memory is freed. /// It means that when a user disconnects, its data are lost. @@ -80,6 +83,12 @@ impl InternalBlobVal { value: self.data.clone(), } } + fn etag(&self) -> String { + let digest = hash::hash(self.data.as_ref()); + let buff = digest.as_ref(); + let hexstr = hex::encode(buff); + format!("\"{}\"", hexstr) + } } type ArcRow = Arc<RwLock<HashMap<String, BTreeMap<String, InternalRowVal>>>>; @@ -300,13 +309,14 @@ impl IStore for MemStore { .ok_or(StorageError::NotFound) .map(|v| v.to_blob_val(blob_ref)) } - async fn blob_insert(&self, blob_val: BlobVal) -> Result<(), StorageError> { + async fn blob_insert(&self, blob_val: BlobVal) -> Result<String, StorageError> { tracing::trace!(entry=%blob_val.blob_ref, command="blob_insert"); let mut store = self.blob.write().or(Err(StorageError::Internal))?; let entry = store.entry(blob_val.blob_ref.0.clone()).or_default(); entry.data = blob_val.value.clone(); entry.metadata = blob_val.meta.clone(); - Ok(()) + + Ok(entry.etag()) } async fn blob_copy(&self, src: &BlobRef, dst: &BlobRef) -> Result<(), StorageError> { tracing::trace!(src=%src, dst=%dst, command="blob_copy"); |