π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move Space photo post creation into ente-space
Manav Rathi5398811c96e0
diff --git a/rust/bindings/wasm/space/src/space.rs b/rust/bindings/wasm/space/src/space.rsindex fde44c9ddc..d719a85cd4 100644--- a/rust/bindings/wasm/space/src/space.rs+++ b/rust/bindings/wasm/space/src/space.rs@@ -1055,47 +1055,22 @@ impl SpaceAccountCtxHandle {photos: Vec<<PostPhotoInput as Tsify>::JsType>,caption: Option<String>,) -> Result<<PostResponse as Tsify>::JsType, Error> {- if photos.is_empty() || photos.len() > 10 {- return Err(- ente_space::Error::InvalidInput("Choose between 1 and 10 photos".into()).into(),- );- }let photos = photos.into_iter().map(PostPhotoInput::from_js).collect::<Result<Vec<_>, _>>()?;- let post_key = self.inner.generate_post_key();- let mut objects = Vec::with_capacity(photos.len());- for (position, photo) in photos.into_iter().enumerate() {- let mut object = self- .inner- .upload_post_photo_asset(- &space_id,- &post_key,- &photo.bytes.to_vec(),- ente_space::PostPhotoAssetOptions {- width: photo.options.width,- height: photo.options.height,- media_type: photo.options.media_type,- thumb_hash: photo.options.thumb_hash,- },- )- .await?;- object.position = Some(position as i32);- objects.push(object);- }- let (post_id, _) = self- .inner- .create_post(- &space_id,- &objects,- caption.as_ref().map(String::as_bytes),- Some(&post_key),- )- .await?;+ let photos = photos.into_iter().map(|photo| ente_space::PostPhotoInput {+ bytes: photo.bytes.to_vec(),+ options: ente_space::PostPhotoAssetOptions {+ width: photo.options.width,+ height: photo.options.height,+ media_type: photo.options.media_type,+ thumb_hash: photo.options.thumb_hash,+ },+ });let post = self.inner- .get_post(&space_id, post_id, Some(&space_id))+ .create_photo_post(&space_id, photos, caption.as_deref()).await?;post_to_js(post).into_js().map_err(Into::into)}diff --git a/rust/crates/space/src/client/mod.rs b/rust/crates/space/src/client/mod.rsindex 0f1799102d..24c15520fe 100644--- a/rust/crates/space/src/client/mod.rs+++ b/rust/crates/space/src/client/mod.rs@@ -77,6 +77,11 @@ pub struct PostPhotoAssetOptions {pub thumb_hash: Option<String>,}+pub struct PostPhotoInput {+ pub bytes: Vec<u8>,+ pub options: PostPhotoAssetOptions,+}+fn profile_object_id_from_key(object_key: &str) -> Result<String> {object_key.rsplit('/')diff --git a/rust/crates/space/src/client/posts.rs b/rust/crates/space/src/client/posts.rsindex 64571aacc9..4bd876bbec 100644--- a/rust/crates/space/src/client/posts.rs+++ b/rust/crates/space/src/client/posts.rs@@ -1,5 +1,5 @@use super::{- AccountSpaceCtx, decrypt_post_object_metadata, ensure_post_objects_are_photos,+ AccountSpaceCtx, PostPhotoInput, decrypt_post_object_metadata, ensure_post_objects_are_photos,retain_content_error,};use crate::crypto::{decrypt_secretbox_payload, encrypt_secretbox_payload, generate_key};@@ -18,6 +18,36 @@ impl AccountSpaceCtx {generate_key()}+ pub async fn create_photo_post(+ &self,+ space_id: &str,+ photos: impl ExactSizeIterator<Item = PostPhotoInput>,+ caption: Option<&str>,+ ) -> Result<Post> {+ let photo_count = photos.len();+ if !(1..=10).contains(&photo_count) {+ return Err(Error::InvalidInput("Choose between 1 and 10 photos".into()));+ }+ let post_key = self.generate_post_key();+ let mut objects = Vec::with_capacity(photo_count);+ for (position, photo) in photos.enumerate() {+ let mut object = self+ .upload_post_photo_asset(space_id, &post_key, &photo.bytes, photo.options)+ .await?;+ object.position = Some(position as i32);+ objects.push(object);+ }+ let (post_id, _) = self+ .create_post(+ space_id,+ &objects,+ caption.map(str::as_bytes),+ Some(&post_key),+ )+ .await?;+ self.get_post(space_id, post_id, Some(space_id)).await+ }+pub async fn create_post(&self,space_id: &str,diff --git a/rust/crates/space/src/lib.rs b/rust/crates/space/src/lib.rsindex fcb10d4c7b..b904a22b3c 100644--- a/rust/crates/space/src/lib.rs+++ b/rust/crates/space/src/lib.rs@@ -9,7 +9,7 @@ pub use client::{MAX_SPACE_COVER_PLAINTEXT_BYTES, MAX_SPACE_COVER_UPLOAD_BYTES,MAX_SPACE_MESSAGE_CIPHER_DECODED_BYTES, MAX_SPACE_MESSAGE_PAYLOAD_BYTES,MAX_SPACE_MESSAGE_TEXT_BYTES, MAX_SPACE_MESSAGE_TEXT_CHARS, MAX_SPACE_POST_PLAINTEXT_BYTES,- MAX_SPACE_POST_UPLOAD_BYTES, PostPhotoAssetOptions, SpaceLinkCtx,+ MAX_SPACE_POST_UPLOAD_BYTES, PostPhotoAssetOptions, PostPhotoInput, SpaceLinkCtx,};pub use error::{Error, Result};pub use models::{