Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix Space CI validation warnings

Neeraj Gupta3d4402fc1e89
diff --git a/rust/bindings/wasm/ente-wasm/src/space.rs b/rust/bindings/wasm/ente-wasm/src/space.rs
index 8c90d175d1..c01a10cfba 100644
--- a/rust/bindings/wasm/ente-wasm/src/space.rs
+++ b/rust/bindings/wasm/ente-wasm/src/space.rs
@@ -5,8 +5,9 @@ use std::collections::BTreeMap;
use ente_core::{crypto::decode_b64, http::Error as HttpError};
use ente_space::{
AccountSpaceCtx, CreatedSpace, DecryptedMessage, DecryptedPost, DecryptedSpaceProfile,
- MessageConversationActivity, MessageResponse, OpenAccountSpaceCtxInput, PostResponse,
- ProfileAvatarResponse, ProfileCoverResponse, SpaceActorResponse, SpaceError as CoreSpaceError,
+ MessageConversationActivity, MessageResponse, OpenAccountSpaceCtxInput, PostPhotoAssetOptions,
+ PostResponse, ProfileAvatarResponse, ProfileCoverResponse, SpaceActorResponse,
+ SpaceError as CoreSpaceError,
};
use serde::{Deserialize, Serialize};
use serde_wasm_bindgen as swb;
@@ -746,6 +747,7 @@ impl SpaceAccountCtxHandle {
}
/// Create a single-photo post with optional caption.
+ #[allow(clippy::too_many_arguments)]
pub async fn create_photo_post(
&self,
space_id: String,
@@ -763,10 +765,12 @@ impl SpaceAccountCtxHandle {
&space_id,
&post_key,
&photo_bytes,
- width,
- height,
- media_type,
- thumb_hash,
+ PostPhotoAssetOptions {
+ width,
+ height,
+ media_type,
+ thumb_hash,
+ },
)
.await?;
let (post_id, _) = self
diff --git a/rust/e2e/tests/space_e2e.rs b/rust/e2e/tests/space_e2e.rs
index adfb544f78..84a763171d 100644
--- a/rust/e2e/tests/space_e2e.rs
+++ b/rust/e2e/tests/space_e2e.rs
@@ -2,7 +2,7 @@
mod space;
mod support;
-use ente_space::AccountSpaceCtx;
+use ente_space::{AccountSpaceCtx, PostPhotoAssetOptions};
use support::auth;
@@ -136,10 +136,12 @@ async fn space_bootstrap_posts_and_friend_share_suite() {
&owner_space.space_id,
&post_key,
TEST_WEBP_BYTES,
- Some(320),
- Some(240),
- Some("image/webp".to_owned()),
- None,
+ PostPhotoAssetOptions {
+ width: Some(320),
+ height: Some(240),
+ media_type: Some("image/webp".to_owned()),
+ thumb_hash: None,
+ },
)
.await
.expect("post asset upload should succeed");
@@ -336,10 +338,12 @@ async fn space_unfriend_revokes_reciprocal_account_access_suite() {
&owner_space.space_id,
&post_key,
TEST_WEBP_BYTES,
- Some(320),
- Some(240),
- Some("image/webp".to_owned()),
- None,
+ PostPhotoAssetOptions {
+ width: Some(320),
+ height: Some(240),
+ media_type: Some("image/webp".to_owned()),
+ thumb_hash: None,
+ },
)
.await
.expect("post asset upload should succeed");
@@ -596,10 +600,12 @@ async fn space_rotation_history_and_refresh_suite() {
&owner_space.space_id,
&post_key_v1,
TEST_WEBP_BYTES,
- Some(320),
- Some(240),
- Some("image/webp".to_owned()),
- None,
+ PostPhotoAssetOptions {
+ width: Some(320),
+ height: Some(240),
+ media_type: Some("image/webp".to_owned()),
+ thumb_hash: None,
+ },
)
.await
.expect("v1 post asset upload should succeed");
@@ -657,10 +663,12 @@ async fn space_rotation_history_and_refresh_suite() {
&owner_space.space_id,
&post_key_v2,
TEST_WEBP_BYTES,
- Some(320),
- Some(240),
- Some("image/webp".to_owned()),
- None,
+ PostPhotoAssetOptions {
+ width: Some(320),
+ height: Some(240),
+ media_type: Some("image/webp".to_owned()),
+ thumb_hash: None,
+ },
)
.await
.expect("v2 post asset upload should succeed");
diff --git a/rust/space/src/client/assets.rs b/rust/space/src/client/assets.rs
index a420f0bd49..f32a29f3ee 100644
--- a/rust/space/src/client/assets.rs
+++ b/rust/space/src/client/assets.rs
@@ -7,9 +7,9 @@
//! upload (posts are photo-only).
use super::{
- AccountSpaceCtx, UPLOAD_PURPOSE_AVATAR, UPLOAD_PURPOSE_COVER, encrypt_post_object_metadata,
- ensure_space_upload_size, ensure_supported_photo_bytes, ensure_supported_photo_media_type,
- profile_object_id_from_key,
+ AccountSpaceCtx, PostPhotoAssetOptions, UPLOAD_PURPOSE_AVATAR, UPLOAD_PURPOSE_COVER,
+ encrypt_post_object_metadata, ensure_space_upload_size, ensure_supported_photo_bytes,
+ ensure_supported_photo_media_type, profile_object_id_from_key,
};
use crate::crypto::{content_md5_base64, encrypt_asset_payload};
use crate::error::{Result, SpaceError};
@@ -134,13 +134,10 @@ impl AccountSpaceCtx {
space_id: &str,
post_key: &[u8],
plaintext: &[u8],
- width: Option<i32>,
- height: Option<i32>,
- media_type: Option<String>,
- thumb_hash: Option<String>,
+ options: PostPhotoAssetOptions,
) -> Result<PostObjectPayload> {
let inferred_media_type = ensure_supported_photo_bytes(plaintext)?;
- let media_type = ensure_supported_photo_media_type(media_type.as_deref())?
+ let media_type = ensure_supported_photo_media_type(options.media_type.as_deref())?
.unwrap_or_else(|| inferred_media_type.to_owned());
let mut object = self
.upload_post_asset(space_id, post_key, plaintext, Some(0))
@@ -148,10 +145,10 @@ impl AccountSpaceCtx {
object.metadata_cipher = Some(encrypt_post_object_metadata(
post_key,
&PostObjectMetadata {
- width: width.filter(|value| *value > 0),
- height: height.filter(|value| *value > 0),
+ width: options.width.filter(|value| *value > 0),
+ height: options.height.filter(|value| *value > 0),
media_type: Some(media_type),
- thumb_hash,
+ thumb_hash: options.thumb_hash,
..Default::default()
},
)?);
diff --git a/rust/space/src/client/mod.rs b/rust/space/src/client/mod.rs
index e59da9e1f6..2636c8507f 100644
--- a/rust/space/src/client/mod.rs
+++ b/rust/space/src/client/mod.rs
@@ -13,6 +13,7 @@ mod test_support;
mod tests;
use std::{
+ cmp::Reverse,
collections::BTreeMap,
sync::{Mutex, MutexGuard},
};
@@ -56,6 +57,14 @@ pub const MAX_SPACE_MESSAGE_CIPHER_DECODED_BYTES: usize = 6 * 1024;
pub const MAX_SPACE_MESSAGE_PAYLOAD_BYTES: usize =
MAX_SPACE_MESSAGE_CIPHER_DECODED_BYTES - SECRETBOX_PAYLOAD_OVERHEAD_BYTES;
+#[derive(Debug, Clone, Default)]
+pub struct PostPhotoAssetOptions {
+ pub width: Option<i32>,
+ pub height: Option<i32>,
+ pub media_type: Option<String>,
+ pub thumb_hash: Option<String>,
+}
+
fn profile_object_id_from_key(object_key: &str) -> Result<String> {
object_key
.rsplit('/')
@@ -729,7 +738,7 @@ pub(super) fn build_space_key_history_map(
let mut history = BTreeMap::new();
history.insert(current_version, current_key.to_vec());
let mut ordered = versions.to_vec();
- ordered.sort_by(|left, right| right.version.cmp(&left.version));
+ ordered.sort_by_key(|entry| Reverse(entry.version));
for entry in ordered {
if entry.wrapped_prev_key.is_empty() || entry.version <= 1 {
continue;
diff --git a/rust/space/src/client/tests.rs b/rust/space/src/client/tests.rs
index 2eb781a80b..e076df846a 100644
--- a/rust/space/src/client/tests.rs
+++ b/rust/space/src/client/tests.rs
@@ -278,10 +278,12 @@ async fn upload_post_photo_asset_attaches_photo_metadata() {
"space_owner_main",
&post_key,
TEST_WEBP_BYTES,
- Some(4032),
- Some(3024),
- Some("image/webp".to_owned()),
- Some("thumbhash-test".to_owned()),
+ PostPhotoAssetOptions {
+ width: Some(4032),
+ height: Some(3024),
+ media_type: Some("image/webp".to_owned()),
+ thumb_hash: Some("thumbhash-test".to_owned()),
+ },
)
.await
.expect("photo upload should succeed");
@@ -310,10 +312,12 @@ async fn upload_post_photo_asset_rejects_video_media_type() {
"space_owner_main",
&generate_key(),
TEST_WEBP_BYTES,
- Some(4032),
- Some(3024),
- Some("video/mp4".to_owned()),
- None,
+ PostPhotoAssetOptions {
+ width: Some(4032),
+ height: Some(3024),
+ media_type: Some("video/mp4".to_owned()),
+ thumb_hash: None,
+ },
)
.await
.expect_err("video media type should fail before upload");
@@ -331,10 +335,12 @@ async fn upload_post_photo_asset_rejects_video_bytes() {
"space_owner_main",
&generate_key(),
TEST_MP4_BYTES,
- Some(1920),
- Some(1080),
- Some("image/webp".to_owned()),
- None,
+ PostPhotoAssetOptions {
+ width: Some(1920),
+ height: Some(1080),
+ media_type: Some("image/webp".to_owned()),
+ thumb_hash: None,
+ },
)
.await
.expect_err("video bytes should fail before upload");
diff --git a/rust/space/src/lib.rs b/rust/space/src/lib.rs
index f31b26071c..8a4abdb021 100644
--- a/rust/space/src/lib.rs
+++ b/rust/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,
+ MAX_SPACE_POST_UPLOAD_BYTES, PostPhotoAssetOptions,
};
pub use error::{Result, SpaceError};
pub use models::{
diff --git a/web/apps/space/src/components/SpaceFileViewer.tsx b/web/apps/space/src/components/SpaceFileViewer.tsx
index e9c01568f3..08abd561d9 100644
--- a/web/apps/space/src/components/SpaceFileViewer.tsx
+++ b/web/apps/space/src/components/SpaceFileViewer.tsx
@@ -402,7 +402,10 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
(!onPublishDraftPost && !canQueueDraftPostPublish);
const isReplyActionRunning = replyActionPhase != null;
const canReplyToPost = Boolean(
- !isDraftPost && activePhoto.spaceId && activePhoto.postId && onReplyToPost,
+ !isDraftPost &&
+ activePhoto.spaceId &&
+ activePhoto.postId &&
+ onReplyToPost,
);
const isReplyMode =
canReplyToPost &&