Skip to content

armgit / ente

Public Imported from GitHub
0

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

Update space client routes

Neeraj Guptaf3c0254a79d3
diff --git a/rust/bindings/wasm/ente-wasm/src/space.rs b/rust/bindings/wasm/ente-wasm/src/space.rs
index e488afa520..35c14debff 100644
--- a/rust/bindings/wasm/ente-wasm/src/space.rs
+++ b/rust/bindings/wasm/ente-wasm/src/space.rs
@@ -1320,8 +1320,11 @@ impl SpaceAccountCtxHandle {
}
/// Delete a post.
- pub async fn delete_post(&self, post_id: i64) -> Result<(), WasmSpaceError> {
- self.inner.delete_post(post_id).await.map_err(Into::into)
+ pub async fn delete_post(&self, space_id: String, post_id: i64) -> Result<(), WasmSpaceError> {
+ self.inner
+ .delete_post(&space_id, post_id)
+ .await
+ .map_err(Into::into)
}
/// List friends for a space.
diff --git a/rust/e2e/tests/support/space.rs b/rust/e2e/tests/support/space.rs
index 66af5c1ac7..84de457060 100644
--- a/rust/e2e/tests/support/space.rs
+++ b/rust/e2e/tests/support/space.rs
@@ -13,7 +13,7 @@ struct SpaceBrowserSessionResponse {
pub async fn open_ctx(endpoint: &str, account: &TestAccount) -> AccountSpaceCtx {
let session = reqwest::Client::new()
- .post(format!("{endpoint}/space/sessions"))
+ .post(format!("{endpoint}/account/space/sessions"))
.header("X-Auth-Token", &account.auth_token)
.header("X-Client-Package", App::Photos.client_package())
.json(&serde_json::json!({ "sessionWrapKey": "space-e2e-session-wrap-key" }))
diff --git a/rust/space/src/client/assets.rs b/rust/space/src/client/assets.rs
index ca2a8d3649..a25b51daed 100644
--- a/rust/space/src/client/assets.rs
+++ b/rust/space/src/client/assets.rs
@@ -34,10 +34,10 @@ impl AccountSpaceCtx {
size: size as i64,
content_md5: content_md5.to_owned(),
purpose: None,
- space_id: Some(space_id.to_owned()),
};
+ let path = format!("/spaces/{space_id}/uploads/presign");
self.client()
- .post_json("/space/uploads/presign", &request)
+ .post_json(&path, &request)
.await
.map_err(Into::into)
}
@@ -53,10 +53,10 @@ impl AccountSpaceCtx {
size: size as i64,
content_md5: content_md5.to_owned(),
purpose: Some(UPLOAD_PURPOSE_AVATAR.to_owned()),
- space_id: Some(space_id.to_owned()),
};
+ let path = format!("/spaces/{space_id}/uploads/presign");
self.client()
- .post_json("/space/uploads/presign", &request)
+ .post_json(&path, &request)
.await
.map_err(Into::into)
}
@@ -72,10 +72,10 @@ impl AccountSpaceCtx {
size: size as i64,
content_md5: content_md5.to_owned(),
purpose: Some(UPLOAD_PURPOSE_COVER.to_owned()),
- space_id: Some(space_id.to_owned()),
};
+ let path = format!("/spaces/{space_id}/uploads/presign");
self.client()
- .post_json("/space/uploads/presign", &request)
+ .post_json(&path, &request)
.await
.map_err(Into::into)
}
diff --git a/rust/space/src/client/entity_keys.rs b/rust/space/src/client/entity_keys.rs
index 7c45147758..1feb65660d 100644
--- a/rust/space/src/client/entity_keys.rs
+++ b/rust/space/src/client/entity_keys.rs
@@ -2,7 +2,7 @@
//!
//! Entity keys are small wrapped keys the server stores per account under a
//! string type tag (for example the Space root key). These methods read and
-//! write them through the `/space/entity-key` endpoints; the payload is opaque
+//! write them through the `/account/space/entity-key` endpoints; the payload is opaque
//! ciphertext to this layer.
use super::AccountSpaceCtx;
@@ -15,7 +15,7 @@ impl AccountSpaceCtx {
let query = vec![("type", key_type.to_owned())];
let payload = self
.client()
- .get_json_optional::<EntityKeyResponse>("/space/entity-key", &query)
+ .get_json_optional::<EntityKeyResponse>("/account/space/entity-key", &query)
.await?;
Ok(payload.map(|value| EntityKeyPayload {
encrypted_key: value.encrypted_key,
@@ -33,7 +33,7 @@ impl AccountSpaceCtx {
};
match self
.client()
- .post_empty("/space/entity-key", &request)
+ .post_empty("/account/space/entity-key", &request)
.await
{
Ok(_) => Ok(()),
@@ -53,7 +53,7 @@ impl AccountSpaceCtx {
};
let response = self
.client()
- .post_json::<EntityKeyResponse, _>("/space/entity-key/ensure", &request)
+ .post_json::<EntityKeyResponse, _>("/account/space/entity-key/ensure", &request)
.await?;
Ok(EntityKeyPayload {
encrypted_key: response.encrypted_key,
diff --git a/rust/space/src/client/friends.rs b/rust/space/src/client/friends.rs
index 490b779d58..e1b6feed7c 100644
--- a/rust/space/src/client/friends.rs
+++ b/rust/space/src/client/friends.rs
@@ -38,12 +38,12 @@ impl AccountSpaceCtx {
let payload = AddFriendPayload {
target_space_id: Some(target_space_id.to_owned()),
target_username: None,
- requester_space_id: requester_space.space_id,
requester_friend_sealed_space_key: encode_b64(&requester_share),
requester_key_version: requester_space.key_version,
};
+ let path = format!("/spaces/{}/friends/add", requester_space.space_id);
self.client()
- .post_json("/space/friends/add", &payload)
+ .post_json(&path, &payload)
.await
.map_err(Into::into)
}
@@ -74,11 +74,8 @@ impl AccountSpaceCtx {
&self,
space_id: &str,
) -> Result<Vec<SpaceFriendRequestResponse>> {
- let query = vec![("spaceId", space_id.to_owned())];
- self.client()
- .get_json("/space/friends/requests", &query)
- .await
- .map_err(Into::into)
+ let path = format!("/spaces/{space_id}/friends/requests");
+ self.client().get_json(&path, &[]).await.map_err(Into::into)
}
pub async fn confirm_friend_request(
@@ -106,11 +103,13 @@ impl AccountSpaceCtx {
let (target_space, target_space_key) = self.profile_space_access(space_id).await?;
let target_share = seal_with_public_key(&target_space_key, &requester_public_key)?;
let payload = ConfirmFriendRequestPayload {
- space_id: target_space.space_id,
target_friend_sealed_space_key: encode_b64(&target_share),
target_key_version: target_space.key_version,
};
- let path = format!("/space/friends/requests/{request_id}/confirm");
+ let path = format!(
+ "/spaces/{}/friends/requests/{request_id}/confirm",
+ target_space.space_id
+ );
let response = self.client().post_json(&path, &payload).await?;
self.clear_friend_share_cache()?;
Ok(response)
@@ -122,46 +121,38 @@ impl AccountSpaceCtx {
"friend request id is required".into(),
));
}
- let path = format!("/space/friends/requests/{request_id}");
- let query = vec![("spaceId", space_id.to_owned())];
+ let path = format!("/spaces/{space_id}/friends/requests/{request_id}");
self.client()
- .delete_empty(&path, &query)
+ .delete_empty(&path, &[])
.await
.map_err(Into::into)
}
pub async fn unfriend_by_space(&self, actor_space_id: &str, space_id: &str) -> Result<()> {
let request = FriendTargetPayload {
- space_id: actor_space_id.to_owned(),
target_username: None,
target_space_id: Some(space_id.to_owned()),
};
- self.client()
- .post_empty("/space/friends/unfriend", &request)
- .await?;
+ let path = format!("/spaces/{actor_space_id}/friends/unfriend");
+ self.client().post_empty(&path, &request).await?;
self.clear_friend_share_cache()?;
Ok(())
}
pub async fn unfriend_by_username(&self, actor_space_id: &str, username: &str) -> Result<()> {
let request = FriendTargetPayload {
- space_id: actor_space_id.to_owned(),
target_username: Some(username.to_owned()),
target_space_id: None,
};
- self.client()
- .post_empty("/space/friends/unfriend", &request)
- .await?;
+ let path = format!("/spaces/{actor_space_id}/friends/unfriend");
+ self.client().post_empty(&path, &request).await?;
self.clear_friend_share_cache()?;
Ok(())
}
pub async fn list_space_friends(&self, space_id: &str) -> Result<Vec<SpaceFriendResponse>> {
- let query = vec![("spaceId", space_id.to_owned())];
- self.client()
- .get_json("/space/friends", &query)
- .await
- .map_err(Into::into)
+ let path = format!("/spaces/{space_id}/friends");
+ self.client().get_json(&path, &[]).await.map_err(Into::into)
}
pub async fn get_relationship(
@@ -169,12 +160,10 @@ impl AccountSpaceCtx {
space_id: &str,
target_space_id: &str,
) -> Result<FriendRelationshipResponse> {
- let query = vec![
- ("spaceId", space_id.to_owned()),
- ("targetSpaceId", target_space_id.to_owned()),
- ];
+ let query = vec![("targetSpaceId", target_space_id.to_owned())];
+ let path = format!("/spaces/{space_id}/friends/relationship");
self.client()
- .get_json("/space/friends/relationship", &query)
+ .get_json(&path, &query)
.await
.map_err(Into::into)
}
@@ -203,14 +192,12 @@ impl AccountSpaceCtx {
return Ok(0);
}
let payload = RefreshFriendSharesRequest {
- space_id: space_id.to_owned(),
key_version: access.key_version,
shares: updates,
};
let updated = payload.shares.len();
- self.client()
- .post_empty("/space/friends/shares/refresh", &payload)
- .await?;
+ let path = format!("/spaces/{space_id}/friends/shares/refresh");
+ self.client().post_empty(&path, &payload).await?;
self.clear_friend_share_cache()?;
Ok(updated)
}
diff --git a/rust/space/src/client/keys.rs b/rust/space/src/client/keys.rs
index c65a3831b4..1f70342bc2 100644
--- a/rust/space/src/client/keys.rs
+++ b/rust/space/src/client/keys.rs
@@ -100,7 +100,6 @@ impl AccountSpaceCtx {
let next_space_key = generate_key();
let space_root_key = self.get_or_create_space_root_key().await?;
let request = RotateSpaceKeyRequest {
- space_id: space_id.to_owned(),
key_version: current.key_version,
root_wrapped_space_key: encode_b64(&encrypt_secretbox_payload(
&space_root_key,
@@ -115,9 +114,10 @@ impl AccountSpaceCtx {
&next_profile,
)?),
};
+ let path = format!("/spaces/{space_id}/rotate");
let response = self
.client()
- .post_json::<SpaceKeyResponse, _>("/space/rotate", &request)
+ .post_json::<SpaceKeyResponse, _>(&path, &request)
.await?;
self.clear_owned_space_cache()?;
Ok(CreatedSpace {
diff --git a/rust/space/src/client/links.rs b/rust/space/src/client/links.rs
index c13addc3d7..af2dcce84c 100644
--- a/rust/space/src/client/links.rs
+++ b/rust/space/src/client/links.rs
@@ -18,7 +18,7 @@ use ente_core::crypto::{decode_b64, encode_b64};
impl AccountSpaceCtx {
pub async fn get_space_link_status(&self, space_id: &str) -> Result<SpaceLinkStatusResponse> {
- let path = format!("/space/links/{space_id}");
+ let path = format!("/spaces/{space_id}/links");
self.client().get_json(&path, &[]).await.map_err(Into::into)
}
@@ -30,8 +30,8 @@ impl AccountSpaceCtx {
SpaceError::InvalidInput(format!("space {space_id} is not owned by the account"))
})?;
let access_key = generate_space_link_access_key()?;
- self.write_space_link(space_id, access, access_key, "/space/links")
- .await
+ let path = format!("/spaces/{space_id}/links");
+ self.write_space_link(access, access_key, &path).await
}
pub async fn rotate_space_link(&self, space_id: &str) -> Result<CreatedSpaceLink> {
@@ -42,13 +42,12 @@ impl AccountSpaceCtx {
SpaceError::InvalidInput(format!("space {space_id} is not owned by the account"))
})?;
let access_key = generate_space_link_access_key()?;
- self.write_space_link(space_id, access, access_key, "/space/links/rotate")
- .await
+ let path = format!("/spaces/{space_id}/links/rotate");
+ self.write_space_link(access, access_key, &path).await
}
async fn write_space_link(
&self,
- space_id: &str,
access: ResolvedOwnedSpaceAccess,
access_key: String,
path: &str,
@@ -57,7 +56,6 @@ impl AccountSpaceCtx {
let auth_key = derive_space_link_auth_key(&access_key_material)?;
let wrap_key = derive_space_link_wrap_key(&access_key_material)?;
let request = SpaceLinkCreateRequest {
- space_id: space_id.to_owned(),
auth_key: encode_b64(&auth_key),
key_version: access.key_version,
link_wrapped_space_key: encode_b64(&encrypt_secretbox_payload(
@@ -99,7 +97,7 @@ impl AccountSpaceCtx {
}
pub async fn delete_space_link(&self, space_id: &str) -> Result<()> {
- let path = format!("/space/links/{space_id}");
+ let path = format!("/spaces/{space_id}/links");
self.client().delete_empty(&path, &[]).await?;
Ok(())
}
diff --git a/rust/space/src/client/messages.rs b/rust/space/src/client/messages.rs
index 8fec51e4c4..8e8b6c6d0f 100644
--- a/rust/space/src/client/messages.rs
+++ b/rust/space/src/client/messages.rs
@@ -28,15 +28,16 @@ impl AccountSpaceCtx {
cursor: Option<String>,
limit: Option<i32>,
) -> Result<MessageConversationPage> {
- let mut query = vec![("spaceId", space_id.to_owned())];
+ let mut query = Vec::new();
if let Some(value) = cursor.filter(|value| !value.trim().is_empty()) {
query.push(("cursor", value));
}
if let Some(value) = limit {
query.push(("limit", value.to_string()));
}
+ let path = format!("/spaces/{space_id}/messages");
self.client()
- .get_json("/space/messages", &query)
+ .get_json(&path, &query)
.await
.map_err(Into::into)
}
@@ -48,14 +49,14 @@ impl AccountSpaceCtx {
cursor: Option<String>,
limit: Option<i32>,
) -> Result<MessagePage> {
- let mut query = vec![("viewerSpaceId", viewer_space_id.to_owned())];
+ let mut query = Vec::new();
if let Some(value) = cursor.filter(|value| !value.trim().is_empty()) {
query.push(("cursor", value));
}
if let Some(value) = limit {
query.push(("limit", value.to_string()));
}
- let path = format!("/space/messages/{space_id}");
+ let path = format!("/spaces/{viewer_space_id}/messages/{space_id}");
self.client()
.get_json(&path, &query)
.await
@@ -80,7 +81,7 @@ impl AccountSpaceCtx {
let request = self
.message_request_for_payload(sender_space_id, &friend.public_key, &payload, None)
.await?;
- let path = format!("/space/messages/{space_id}");
+ let path = format!("/spaces/{sender_space_id}/messages/{space_id}");
self.client()
.post_json(&path, &request)
.await
@@ -115,7 +116,7 @@ impl AccountSpaceCtx {
Some(reply_message_id),
)
.await?;
- let path = format!("/space/messages/{space_id}");
+ let path = format!("/spaces/{sender_space_id}/messages/{space_id}");
self.client()
.post_json(&path, &request)
.await
@@ -171,7 +172,7 @@ impl AccountSpaceCtx {
let request = self
.message_request_for_payload(sender_space_id, &post.author.public_key, &payload, None)
.await?;
- let path = format!("/space/posts/{post_id}/reply");
+ let path = format!("/spaces/{sender_space_id}/posts/{post_id}/reply");
self.client()
.post_json(&path, &request)
.await
@@ -210,11 +211,8 @@ impl AccountSpaceCtx {
if message_id.is_empty() {
return Err(SpaceError::InvalidInput("message id is required".into()));
}
- let request = LikeMessageRequest {
- space_id: space_id.to_owned(),
- like,
- };
- let path = format!("/space/message/{message_id}/like");
+ let request = LikeMessageRequest { like };
+ let path = format!("/spaces/{space_id}/message/{message_id}/like");
self.client()
.post_json(&path, &request)
.await
@@ -226,10 +224,9 @@ impl AccountSpaceCtx {
if message_id.is_empty() {
return Err(SpaceError::InvalidInput("message id is required".into()));
}
- let path = format!("/space/message/{message_id}");
- let query = vec![("spaceId", space_id.to_owned())];
+ let path = format!("/spaces/{space_id}/message/{message_id}");
self.client()
- .delete_empty(&path, &query)
+ .delete_empty(&path, &[])
.await
.map_err(Into::into)
}
@@ -263,7 +260,6 @@ impl AccountSpaceCtx {
let sender_key = seal_with_public_key(&message_key, &identity.public_key)?;
let recipient_key = seal_with_public_key(&message_key, &recipient_public_key)?;
Ok(CreateMessageRequest {
- space_id: sender_space_id.to_owned(),
message_id: None,
message_cipher: encode_b64(&encrypt_secretbox_payload(&message_key, &plaintext)?),
sender_encrypted_message_key: encode_b64(&sender_key),
diff --git a/rust/space/src/client/mod.rs b/rust/space/src/client/mod.rs
index d23ed5b83b..0bd09f1848 100644
--- a/rust/space/src/client/mod.rs
+++ b/rust/space/src/client/mod.rs
@@ -159,7 +159,7 @@ impl AccountSpaceCtx {
}
let spaces: Vec<SpaceKeyResponse> = self
.client
- .get_json("/space", &[])
+ .get_json("/account/space", &[])
.await
.map_err(SpaceError::from)?;
*cache_lock(&self.owned_spaces_cache, "owned spaces")? = Some(spaces.clone());
@@ -167,11 +167,8 @@ impl AccountSpaceCtx {
}
pub async fn list_friend_shares(&self, space_id: &str) -> Result<Vec<FriendShareResponse>> {
- let query = vec![("spaceId", space_id.to_owned())];
- self.client
- .get_json("/space/friends/shares", &query)
- .await
- .map_err(Into::into)
+ let path = format!("/spaces/{space_id}/friends/shares");
+ self.client.get_json(&path, &[]).await.map_err(Into::into)
}
pub(crate) fn decrypt_space_identity(&self, space: &SpaceKeyResponse) -> Result<SpaceIdentity> {
@@ -298,7 +295,7 @@ impl AccountSpaceCtx {
};
let response = self
.client
- .post_json::<SpaceKeyResponse, _>("/space", &request)
+ .post_json::<SpaceKeyResponse, _>("/account/space", &request)
.await?;
self.cache_created_owned_space(SpaceKeyResponse {
space_id: response.space_id.clone(),
@@ -336,7 +333,7 @@ impl AccountSpaceCtx {
space_id: &str,
space_slug: &str,
) -> Result<SpaceLookupResponse> {
- let path = format!("/space/{space_id}/slug");
+ let path = format!("/spaces/{space_id}/slug");
let request = UpdateSpaceSlugRequest {
space_slug: space_slug.to_owned(),
};
diff --git a/rust/space/src/client/posts.rs b/rust/space/src/client/posts.rs
index 8869c15baf..16f411980c 100644
--- a/rust/space/src/client/posts.rs
+++ b/rust/space/src/client/posts.rs
@@ -48,7 +48,6 @@ impl AccountSpaceCtx {
None => None,
};
let request = CreatePostRequest {
- space_id: space_id.to_owned(),
encrypted_post_key: encode_b64(&encrypt_secretbox_payload(
&access.space_key,
&post_key_bytes,
@@ -57,9 +56,10 @@ impl AccountSpaceCtx {
caption_cipher,
objects: objects.to_vec(),
};
+ let path = format!("/spaces/{space_id}/posts");
let response = self
.client()
- .post_json::<CreatePostResponse, _>("/space/posts", &request)
+ .post_json::<CreatePostResponse, _>(&path, &request)
.await?;
Ok((response.post_id, post_key_bytes))
}
@@ -93,25 +93,23 @@ impl AccountSpaceCtx {
cursor: Option<String>,
limit: Option<i32>,
) -> Result<FeedPage> {
- let mut query = vec![("spaceId", space_id.to_owned())];
+ let mut query = Vec::new();
if let Some(value) = cursor.filter(|value| !value.trim().is_empty()) {
query.push(("cursor", value));
}
if let Some(value) = limit {
query.push(("limit", value.to_string()));
}
+ let path = format!("/spaces/{space_id}/feed");
self.client()
- .get_json("/space/feed", &query)
+ .get_json(&path, &query)
.await
.map_err(Into::into)
}
pub async fn unread_status(&self, space_id: &str) -> Result<SpaceUnreadStatusResponse> {
- let query = vec![("spaceId", space_id.to_owned())];
- self.client()
- .get_json("/space/unread", &query)
- .await
- .map_err(Into::into)
+ let path = format!("/spaces/{space_id}/unread");
+ self.client().get_json(&path, &[]).await.map_err(Into::into)
}
pub async fn mark_notifications_read(
@@ -129,14 +127,9 @@ impl AccountSpaceCtx {
"friend space id is required".into(),
));
}
+ let path = format!("/spaces/{space_id}/messages/read");
self.client()
- .post_json(
- "/space/messages/read",
- &MarkNotificationsReadRequest {
- space_id,
- friend_space_id,
- },
- )
+ .post_json(&path, &MarkNotificationsReadRequest { friend_space_id })
.await
.map_err(Into::into)
}
@@ -376,21 +369,20 @@ impl AccountSpaceCtx {
caption_plaintext: Option<&[u8]>,
) -> Result<()> {
let request = UpdatePostCaptionRequest {
- space_id: space_id.to_owned(),
caption_cipher: match caption_plaintext {
Some(value) => Some(encode_b64(&encrypt_secretbox_payload(post_key, value)?)),
None => None,
},
};
- let path = format!("/space/posts/{post_id}/caption");
+ let path = format!("/spaces/{space_id}/posts/{post_id}/caption");
self.client()
.post_empty(&path, &request)
.await
.map_err(Into::into)
}
- pub async fn delete_post(&self, post_id: i64) -> Result<()> {
- let path = format!("/space/posts/{post_id}");
+ pub async fn delete_post(&self, space_id: &str, post_id: i64) -> Result<()> {
+ let path = format!("/spaces/{space_id}/posts/{post_id}");
self.client()
.delete_empty(&path, &[])
.await
@@ -403,11 +395,8 @@ impl AccountSpaceCtx {
post_id: i64,
like: bool,
) -> Result<LikePostResponse> {
- let path = format!("/space/posts/{post_id}/like");
- let request = LikePostRequest {
- space_id: space_id.to_owned(),
- like,
- };
+ let path = format!("/spaces/{space_id}/posts/{post_id}/like");
+ let request = LikePostRequest { like };
self.client()
.post_json(&path, &request)
.await
diff --git a/rust/space/src/client/profiles.rs b/rust/space/src/client/profiles.rs
index 9210225d13..bd0ed1219b 100644
--- a/rust/space/src/client/profiles.rs
+++ b/rust/space/src/client/profiles.rs
@@ -88,7 +88,6 @@ impl AccountSpaceCtx {
SpaceError::InvalidInput(format!("space {space_id} is not owned by the account"))
})?;
let request = UpdateSpaceProfileRequest {
- space_id: space_id.to_owned(),
key_version: space_key.key_version,
encrypted_profile: encode_b64(&encrypt_secretbox_payload(
&space_key.space_key,
@@ -99,9 +98,10 @@ impl AccountSpaceCtx {
remove_avatar,
remove_cover,
};
+ let path = format!("/spaces/{space_id}/profile");
let response = self
.client()
- .post_json("/space/profile", &request)
+ .post_json(&path, &request)
.await
.map_err(SpaceError::from)?;
self.update_cached_owned_space_profile(space_id, request.encrypted_profile)?;
diff --git a/rust/space/src/client/tests.rs b/rust/space/src/client/tests.rs
index dd00389e43..ec2f096afa 100644
--- a/rust/space/src/client/tests.rs
+++ b/rust/space/src/client/tests.rs
@@ -21,7 +21,7 @@ use serde_json::json;
async fn account_http_client_sends_space_session_token_header() {
let mut server = Server::new_async().await;
let request = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body("{}")
@@ -37,7 +37,7 @@ async fn account_http_client_sends_space_session_token_header() {
)
.expect("http client");
- let _: serde_json::Value = client.get_json("/space", &[]).await.unwrap();
+ let _: serde_json::Value = client.get_json("/account/space", &[]).await.unwrap();
request.assert_async().await;
}
@@ -350,7 +350,7 @@ async fn account_space_key_resolution_is_cached_within_context() {
let friend_sealed_space_key = encode_b64(&sealed_share);
let spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(owned_space_response(
@@ -364,12 +364,8 @@ async fn account_space_key_resolution_is_cached_within_context() {
.create_async()
.await;
let shares = server
- .mock("GET", "/space/friends/shares")
+ .mock("GET", "/spaces/space_owner_main/friends/shares")
.match_header("x-space-session-token", "space-session-token")
- .match_query(Matcher::UrlEncoded(
- "spaceId".into(),
- "space_owner_main".into(),
- ))
.with_status(200)
.with_body(
json!([{
@@ -413,12 +409,11 @@ async fn upload_post_asset_uses_presign_and_object_store() {
let ctx = test_account_ctx(&server.url());
let presign = server
- .mock("POST", "/space/uploads/presign")
+ .mock("POST", "/spaces/space_owner_main/uploads/presign")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
Matcher::Regex("\"size\"".into()),
Matcher::Regex("\"contentMD5\":\"[^\"]+\"".into()),
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
]))
.with_status(200)
.with_body(
@@ -461,12 +456,11 @@ async fn upload_post_photo_asset_attaches_photo_metadata() {
let mut server = Server::new_async().await;
let ctx = test_account_ctx(&server.url());
let presign = server
- .mock("POST", "/space/uploads/presign")
+ .mock("POST", "/spaces/space_owner_main/uploads/presign")
.match_header("x-space-session-token", "space-session-token")
- .match_body(Matcher::AllOf(vec![
- Matcher::Regex("\"contentMD5\":\"[^\"]+\"".into()),
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
- ]))
+ .match_body(Matcher::AllOf(vec![Matcher::Regex(
+ "\"contentMD5\":\"[^\"]+\"".into(),
+ )]))
.with_status(200)
.with_body(
json!({
@@ -617,12 +611,11 @@ async fn upload_avatar_uses_avatar_presign_and_object_store() {
let mut server = Server::new_async().await;
let ctx = test_account_ctx(&server.url());
let presign = server
- .mock("POST", "/space/uploads/presign")
+ .mock("POST", "/spaces/space_owner_main/uploads/presign")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
Matcher::Regex("\"purpose\":\"avatar\"".into()),
Matcher::Regex("\"contentMD5\":\"[^\"]+\"".into()),
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
Matcher::Regex("\"size\"".into()),
]))
.with_status(200)
@@ -678,12 +671,11 @@ async fn upload_cover_uses_cover_presign_and_object_store() {
let mut server = Server::new_async().await;
let ctx = test_account_ctx(&server.url());
let presign = server
- .mock("POST", "/space/uploads/presign")
+ .mock("POST", "/spaces/space_owner_main/uploads/presign")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
Matcher::Regex("\"purpose\":\"cover\"".into()),
Matcher::Regex("\"contentMD5\":\"[^\"]+\"".into()),
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
Matcher::Regex("\"size\"".into()),
]))
.with_status(200)
@@ -826,7 +818,7 @@ async fn create_space_with_key_sends_encrypted_space_and_profile_payloads() {
let ctx = test_account_ctx_with_space_root_key(&server.url(), space_root_key);
let space_key = generate_key();
let create_space = server
- .mock("POST", "/space")
+ .mock("POST", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
Matcher::Regex("\"spaceSlug\":\"owner-main\"".into()),
@@ -871,7 +863,7 @@ async fn create_space_updates_loaded_owned_space_cache() {
let ctx = test_account_ctx_with_space_root_key(&server.url(), space_root_key);
let space_key = generate_key();
let list_spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body("[]")
@@ -879,7 +871,7 @@ async fn create_space_updates_loaded_owned_space_cache() {
.create_async()
.await;
let create_space = server
- .mock("POST", "/space")
+ .mock("POST", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(
@@ -895,12 +887,11 @@ async fn create_space_updates_loaded_owned_space_cache() {
.create_async()
.await;
let update_profile = server
- .mock("POST", "/space/profile")
+ .mock("POST", "/spaces/space_owner_main/profile")
.match_header("x-space-session-token", "space-session-token")
- .match_body(Matcher::AllOf(vec![
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
- Matcher::Regex("\"encryptedProfile\":\"[^\"]+\"".into()),
- ]))
+ .match_body(Matcher::AllOf(vec![Matcher::Regex(
+ "\"encryptedProfile\":\"[^\"]+\"".into(),
+ )]))
.with_status(200)
.with_body(json!({ "status": "ok" }).to_string())
.create_async()
@@ -942,7 +933,7 @@ async fn list_owned_spaces_reuses_loaded_cache() {
let space_root_key = generate_key();
let space_key = generate_key();
let list_spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(owned_space_response(
@@ -984,7 +975,7 @@ async fn create_post_includes_space_key_version() {
let ctx = test_account_ctx_with_space_root_key(&server.url(), space_root_key.clone());
let space_key = generate_key();
let spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(
@@ -1000,7 +991,7 @@ async fn create_post_includes_space_key_version() {
.create_async()
.await;
let create = server
- .mock("POST", "/space/posts")
+ .mock("POST", "/spaces/space_owner_main/posts")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::Regex("\"keyVersion\":3".into()))
.with_status(200)
@@ -1058,7 +1049,7 @@ async fn update_space_profile_sends_encrypted_profile_and_profile_assets() {
let ctx = test_account_ctx_with_space_root_key(&server.url(), space_root_key.clone());
let space_key = generate_key();
let spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(owned_space_response(
@@ -1071,10 +1062,9 @@ async fn update_space_profile_sends_encrypted_profile_and_profile_assets() {
.create_async()
.await;
let update = server
- .mock("POST", "/space/profile")
+ .mock("POST", "/spaces/space_owner_main/profile")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
Matcher::Regex("\"keyVersion\":3".into()),
Matcher::Regex("\"encryptedProfile\":\"[^\"]+\"".into()),
Matcher::Regex("\"avatar\"".into()),
@@ -1171,7 +1161,7 @@ async fn get_space_profile_decrypted_loads_and_decrypts_profile() {
.create_async()
.await;
let spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(owned_space_response(
@@ -1208,7 +1198,7 @@ async fn add_friend_from_link_creates_friend_request() {
let (target_public_key, _) = generate_keypair().expect("valid target keypair");
let spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(
@@ -1224,11 +1214,10 @@ async fn add_friend_from_link_creates_friend_request() {
.create_async()
.await;
let add = server
- .mock("POST", "/space/friends/add")
+ .mock("POST", "/spaces/space_viewer_main/friends/add")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
Matcher::Regex("\"targetSpaceId\":\"space_owner_main\"".into()),
- Matcher::Regex("\"requesterSpaceId\":\"space_viewer_main\"".into()),
Matcher::Regex("\"requesterKeyVersion\":4".into()),
Matcher::Regex("\"requesterFriendSealedSpaceKey\":\"[^\"]+\"".into()),
]))
@@ -1262,32 +1251,31 @@ async fn space_status_mutations_accept_empty_server_responses() {
let ctx = test_account_ctx(&server.url());
let delete_post = server
- .mock("DELETE", "/space/posts/42")
+ .mock("DELETE", "/spaces/space_viewer_main/posts/42")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.create_async()
.await;
let unfriend_space = server
- .mock("POST", "/space/friends/unfriend")
+ .mock("POST", "/spaces/space_viewer_main/friends/unfriend")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::JsonString(
- json!({"spaceId": "space_viewer_main", "targetSpaceId": "space_owner_main"})
- .to_string(),
+ json!({"targetSpaceId": "space_owner_main"}).to_string(),
))
.with_status(200)
.create_async()
.await;
let unfriend_username = server
- .mock("POST", "/space/friends/unfriend")
+ .mock("POST", "/spaces/space_viewer_main/friends/unfriend")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::JsonString(
- json!({"spaceId": "space_viewer_main", "targetUsername": "owner"}).to_string(),
+ json!({"targetUsername": "owner"}).to_string(),
))
.with_status(200)
.create_async()
.await;
- ctx.delete_post(42)
+ ctx.delete_post("space_viewer_main", 42)
.await
.expect("delete post should accept empty response");
ctx.unfriend_by_space("space_viewer_main", "space_owner_main")
@@ -1307,12 +1295,11 @@ async fn update_post_caption_uses_caption_endpoint() {
let mut server = Server::new_async().await;
let ctx = test_account_ctx(&server.url());
let update = server
- .mock("POST", "/space/posts/42/caption")
+ .mock("POST", "/spaces/space_owner_main/posts/42/caption")
.match_header("x-space-session-token", "space-session-token")
- .match_body(Matcher::AllOf(vec![
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
- Matcher::Regex("\"captionCipher\":\"[^\"]+\"".into()),
- ]))
+ .match_body(Matcher::AllOf(vec![Matcher::Regex(
+ "\"captionCipher\":\"[^\"]+\"".into(),
+ )]))
.with_status(200)
.create_async()
.await;
@@ -1334,11 +1321,9 @@ async fn like_post_uses_post_like_endpoint() {
let mut server = Server::new_async().await;
let ctx = test_account_ctx(&server.url());
let like = server
- .mock("POST", "/space/posts/42/like")
+ .mock("POST", "/spaces/space_owner_main/posts/42/like")
.match_header("x-space-session-token", "space-session-token")
- .match_body(Matcher::JsonString(
- json!({"spaceId": "space_owner_main", "like": true}).to_string(),
- ))
+ .match_body(Matcher::JsonString(json!({"like": true}).to_string()))
.with_status(200)
.with_body(json!({"liked": true}).to_string())
.create_async()
@@ -1358,21 +1343,17 @@ async fn unread_methods_use_read_marker_endpoints() {
let mut server = Server::new_async().await;
let ctx = test_account_ctx(&server.url());
let status = server
- .mock("GET", "/space/unread")
+ .mock("GET", "/spaces/space_owner_main/unread")
.match_header("x-space-session-token", "space-session-token")
- .match_query(Matcher::UrlEncoded(
- "spaceId".into(),
- "space_owner_main".into(),
- ))
.with_status(200)
.with_body(json!({"notificationsUnread": false}).to_string())
.create_async()
.await;
let notifications_read = server
- .mock("POST", "/space/messages/read")
+ .mock("POST", "/spaces/space_owner_main/messages/read")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::JsonString(
- json!({"spaceId": "space_owner_main", "friendSpaceId": "space_friend"}).to_string(),
+ json!({"friendSpaceId": "space_friend"}).to_string(),
))
.with_status(200)
.with_body(json!({"notificationsUnread": false}).to_string())
@@ -1403,12 +1384,8 @@ async fn message_actions_use_message_endpoints() {
let (friend_public_key, _) = generate_keypair().expect("valid friend keypair");
let friends = server
- .mock("GET", "/space/friends")
+ .mock("GET", "/spaces/space_owner_main/friends")
.match_header("x-space-session-token", "space-session-token")
- .match_query(Matcher::UrlEncoded(
- "spaceId".into(),
- "space_owner_main".into(),
- ))
.with_status(200)
.with_body(
json!([{
@@ -1426,10 +1403,9 @@ async fn message_actions_use_message_endpoints() {
.create_async()
.await;
let reply = server
- .mock("POST", "/space/messages/space_friend")
+ .mock("POST", "/spaces/space_owner_main/messages/space_friend")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
Matcher::Regex("\"replyMessageId\":\"wmsg_parent\"".into()),
Matcher::Regex("\"messageCipher\":\"[^\"]+\"".into()),
Matcher::Regex("\"senderEncryptedMessageKey\":\"[^\"]+\"".into()),
@@ -1466,22 +1442,16 @@ async fn message_actions_use_message_endpoints() {
.create_async()
.await;
let like = server
- .mock("POST", "/space/message/wmsg_reply/like")
+ .mock("POST", "/spaces/space_owner_main/message/wmsg_reply/like")
.match_header("x-space-session-token", "space-session-token")
- .match_body(Matcher::JsonString(
- json!({"spaceId": "space_owner_main", "like": true}).to_string(),
- ))
+ .match_body(Matcher::JsonString(json!({"like": true}).to_string()))
.with_status(200)
.with_body(json!({"liked": true}).to_string())
.create_async()
.await;
let delete = server
- .mock("DELETE", "/space/message/wmsg_reply")
+ .mock("DELETE", "/spaces/space_owner_main/message/wmsg_reply")
.match_header("x-space-session-token", "space-session-token")
- .match_query(Matcher::UrlEncoded(
- "spaceId".into(),
- "space_owner_main".into(),
- ))
.with_status(200)
.create_async()
.await;
@@ -1597,12 +1567,8 @@ async fn list_space_friends_uses_space_friends_endpoint() {
let mut server = Server::new_async().await;
let ctx = test_account_ctx(&server.url());
let friends = server
- .mock("GET", "/space/friends")
+ .mock("GET", "/spaces/space_owner_main/friends")
.match_header("x-space-session-token", "space-session-token")
- .match_query(Matcher::UrlEncoded(
- "spaceId".into(),
- "space_owner_main".into(),
- ))
.with_status(200)
.with_body(
json!([{
@@ -1637,12 +1603,12 @@ async fn get_relationship_uses_relationship_endpoint() {
let mut server = Server::new_async().await;
let ctx = test_account_ctx(&server.url());
let relationship = server
- .mock("GET", "/space/friends/relationship")
+ .mock("GET", "/spaces/space_owner_main/friends/relationship")
.match_header("x-space-session-token", "space-session-token")
- .match_query(Matcher::AllOf(vec![
- Matcher::UrlEncoded("spaceId".into(), "space_owner_main".into()),
- Matcher::UrlEncoded("targetSpaceId".into(), "space_friend".into()),
- ]))
+ .match_query(Matcher::AllOf(vec![Matcher::UrlEncoded(
+ "targetSpaceId".into(),
+ "space_friend".into(),
+ )]))
.with_status(200)
.with_body(json!({"relationship": "friend"}).to_string())
.create_async()
@@ -1695,7 +1661,7 @@ async fn refresh_friend_shares_accepts_empty_server_response() {
let (friend_public_key, _) = generate_keypair().expect("valid friend keypair");
let spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(
@@ -1711,12 +1677,8 @@ async fn refresh_friend_shares_accepts_empty_server_response() {
.create_async()
.await;
let friends = server
- .mock("GET", "/space/friends")
+ .mock("GET", "/spaces/space_owner_main/friends")
.match_header("x-space-session-token", "space-session-token")
- .match_query(Matcher::UrlEncoded(
- "spaceId".into(),
- "space_owner_main".into(),
- ))
.with_status(200)
.with_body(
json!([{
@@ -1734,7 +1696,7 @@ async fn refresh_friend_shares_accepts_empty_server_response() {
.create_async()
.await;
let refresh = server
- .mock("POST", "/space/friends/shares/refresh")
+ .mock("POST", "/spaces/space_owner_main/friends/shares/refresh")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
Matcher::Regex("\"friendSpaceId\":\"space_viewer\"".into()),
@@ -1773,7 +1735,7 @@ async fn space_link_status_create_and_delete_use_link_endpoints() {
);
let spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(owned_space_response(
@@ -1787,7 +1749,7 @@ async fn space_link_status_create_and_delete_use_link_endpoints() {
.create_async()
.await;
let status = server
- .mock("GET", "/space/links/space_owner_main")
+ .mock("GET", "/spaces/space_owner_main/links")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(
@@ -1806,10 +1768,9 @@ async fn space_link_status_create_and_delete_use_link_endpoints() {
.create_async()
.await;
let create = server
- .mock("POST", "/space/links")
+ .mock("POST", "/spaces/space_owner_main/links")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
Matcher::Regex("\"authKey\":\"[^\"]+\"".into()),
Matcher::Regex("\"keyVersion\":3".into()),
Matcher::Regex("\"linkWrappedSpaceKey\":\"[^\"]+\"".into()),
@@ -1831,10 +1792,9 @@ async fn space_link_status_create_and_delete_use_link_endpoints() {
.create_async()
.await;
let rotate = server
- .mock("POST", "/space/links/rotate")
+ .mock("POST", "/spaces/space_owner_main/links/rotate")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
Matcher::Regex("\"authKey\":\"[^\"]+\"".into()),
Matcher::Regex("\"keyVersion\":3".into()),
Matcher::Regex("\"linkWrappedSpaceKey\":\"[^\"]+\"".into()),
@@ -1856,7 +1816,7 @@ async fn space_link_status_create_and_delete_use_link_endpoints() {
.create_async()
.await;
let delete = server
- .mock("DELETE", "/space/links/space_owner_main")
+ .mock("DELETE", "/spaces/space_owner_main/links")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.create_async()
@@ -1907,7 +1867,7 @@ async fn create_space_link_reuses_encrypted_access_key_returned_by_post() {
);
let spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(owned_space_response(
@@ -1920,10 +1880,9 @@ async fn create_space_link_reuses_encrypted_access_key_returned_by_post() {
.create_async()
.await;
let create = server
- .mock("POST", "/space/links")
+ .mock("POST", "/spaces/space_owner_main/links")
.match_header("x-space-session-token", "space-session-token")
.match_body(Matcher::AllOf(vec![
- Matcher::Regex("\"spaceId\":\"space_owner_main\"".into()),
Matcher::Regex("\"authKey\":\"[^\"]+\"".into()),
Matcher::Regex("\"keyVersion\":3".into()),
Matcher::Regex("\"linkWrappedSpaceKey\":\"[^\"]+\"".into()),
@@ -1963,10 +1922,9 @@ async fn list_feed_uses_space_feed_endpoint() {
let mut server = Server::new_async().await;
let ctx = test_account_ctx(&server.url());
let feed = server
- .mock("GET", "/space/feed")
+ .mock("GET", "/spaces/space_owner_main/feed")
.match_header("x-space-session-token", "space-session-token")
.match_query(Matcher::AllOf(vec![
- Matcher::UrlEncoded("spaceId".into(), "space_owner_main".into()),
Matcher::UrlEncoded("cursor".into(), "cursor-1".into()),
Matcher::UrlEncoded("limit".into(), "5".into()),
]))
@@ -2070,7 +2028,7 @@ async fn fetch_post_decrypted_uses_post_by_id_endpoint() {
let caption = b"hello from post";
let spaces = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(
@@ -2135,7 +2093,7 @@ async fn hydrate_space_keys_loads_owned_and_friends_spaces() {
.expect("sealed space share");
let owned = server
- .mock("GET", "/space")
+ .mock("GET", "/account/space")
.match_header("x-space-session-token", "space-session-token")
.with_status(200)
.with_body(
@@ -2151,12 +2109,8 @@ async fn hydrate_space_keys_loads_owned_and_friends_spaces() {
.create_async()
.await;
let shares = server
- .mock("GET", "/space/friends/shares")
+ .mock("GET", "/spaces/space_owner_main/friends/shares")
.match_header("x-space-session-token", "space-session-token")
- .match_query(Matcher::UrlEncoded(
- "spaceId".into(),
- "space_owner_main".into(),
- ))
.with_status(200)
.with_body(
json!([{
diff --git a/rust/space/src/transport.rs b/rust/space/src/transport.rs
index 1fef9bf8c9..27e3fb94c1 100644
--- a/rust/space/src/transport.rs
+++ b/rust/space/src/transport.rs
@@ -64,8 +64,6 @@ pub struct PresignUploadRequest {
pub content_md5: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub purpose: Option<String>,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub space_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -100,7 +98,6 @@ pub struct PostObjectPayload {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreatePostRequest {
- pub space_id: String,
pub encrypted_post_key: String,
pub key_version: i32,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -117,7 +114,6 @@ pub struct CreatePostResponse {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LikePostRequest {
- pub space_id: String,
pub like: bool,
}
@@ -129,7 +125,6 @@ pub struct LikePostResponse {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MarkNotificationsReadRequest {
- pub space_id: String,
pub friend_space_id: String,
}
@@ -142,7 +137,6 @@ pub struct SpaceUnreadStatusResponse {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LikeMessageRequest {
- pub space_id: String,
pub like: bool,
}
@@ -154,7 +148,6 @@ pub struct LikeMessageResponse {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateMessageRequest {
- pub space_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub message_id: Option<String>,
pub message_cipher: String,
@@ -267,7 +260,6 @@ pub struct MessageConversationPage {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdatePostCaptionRequest {
- pub space_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub caption_cipher: Option<String>,
}
@@ -343,7 +335,6 @@ pub type ProfileCoverResponse = ProfileAvatarResponse;
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateSpaceProfileRequest {
- pub space_id: String,
pub key_version: i32,
pub encrypted_profile: String,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -387,7 +378,6 @@ pub struct SpaceProfileResponse {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RotateSpaceKeyRequest {
- pub space_id: String,
pub root_wrapped_space_key: String,
pub key_version: i32,
pub wrapped_prev_key: String,
@@ -431,7 +421,6 @@ mod tests {
#[test]
fn profile_asset_payloads_serialize_object_id_for_avatar_and_cover() {
let request = UpdateSpaceProfileRequest {
- space_id: "space_owner_main".to_owned(),
key_version: 3,
encrypted_profile: "encrypted-profile".to_owned(),
avatar: Some(ProfileAvatarPayload {
@@ -529,7 +518,6 @@ pub struct AddFriendPayload {
pub target_space_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub target_username: Option<String>,
- pub requester_space_id: String,
pub requester_friend_sealed_space_key: String,
pub requester_key_version: i32,
}
@@ -537,7 +525,6 @@ pub struct AddFriendPayload {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ConfirmFriendRequestPayload {
- pub space_id: String,
pub target_friend_sealed_space_key: String,
pub target_key_version: i32,
}
@@ -557,7 +544,6 @@ pub struct FriendRelationshipResponse {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FriendTargetPayload {
- pub space_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub target_username: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -591,7 +577,6 @@ pub struct ShareUpdatePayload {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RefreshFriendSharesRequest {
- pub space_id: String,
pub key_version: i32,
pub shares: Vec<ShareUpdatePayload>,
}
@@ -636,7 +621,6 @@ pub struct SpaceLinkStatusResponse {
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SpaceLinkCreateRequest {
- pub space_id: String,
pub auth_key: String,
pub key_version: i32,
pub link_wrapped_space_key: String,
diff --git a/server/space/api/sessions_test.go b/server/space/api/sessions_test.go
index 541e1c4e7c..fb033dbf1e 100644
--- a/server/space/api/sessions_test.go
+++ b/server/space/api/sessions_test.go
@@ -47,8 +47,8 @@ func setupSpaceSessionAPITest(t *testing.T) (*Handlers, *spacerepo.Module, int64
func TestCreateSpaceBrowserSessionReturnsToken(t *testing.T) {
handlers, repos, userID := setupSpaceSessionAPITest(t)
router := gin.New()
- router.POST("/space/sessions", handlers.CreateBrowserSession)
- req := httptest.NewRequest(http.MethodPost, "/space/sessions", bytes.NewBufferString(`{"sessionWrapKey":"session-wrap-key"}`))
+ router.POST("/account/space/sessions", handlers.CreateBrowserSession)
+ req := httptest.NewRequest(http.MethodPost, "/account/space/sessions", bytes.NewBufferString(`{"sessionWrapKey":"session-wrap-key"}`))
req.Header.Set("X-Auth-User-ID", strconv.FormatInt(userID, 10))
recorder := httptest.NewRecorder()
@@ -77,7 +77,7 @@ func TestRegisteredTokenSessionRoutesAllowEntityKeyEnsureBeforeBrowserSession(t
ensureReq := httptest.NewRequest(
http.MethodPost,
- "/space/entity-key/ensure",
+ "/account/space/entity-key/ensure",
bytes.NewBufferString(`{"type":"space","encryptedKey":"`+testEncodedSpaceEntityKey(72)+`"}`),
)
ensureReq.Header.Set("X-Auth-User-ID", strconv.FormatInt(userID, 10))
@@ -88,7 +88,7 @@ func TestRegisteredTokenSessionRoutesAllowEntityKeyEnsureBeforeBrowserSession(t
require.Equal(t, http.StatusOK, ensureRecorder.Code)
require.JSONEq(t, `{"type":"space","encryptedKey":"`+testEncodedSpaceEntityKey(72)+`"}`, ensureRecorder.Body.String())
- getReq := httptest.NewRequest(http.MethodGet, "/space/entity-key?type=space", nil)
+ getReq := httptest.NewRequest(http.MethodGet, "/account/space/entity-key?type=space", nil)
getReq.Header.Set("X-Auth-User-ID", strconv.FormatInt(userID, 10))
getRecorder := httptest.NewRecorder()
@@ -100,11 +100,11 @@ func TestRegisteredTokenSessionRoutesAllowEntityKeyEnsureBeforeBrowserSession(t
func TestSpaceEntityKeyRejectsSplitFormatPayload(t *testing.T) {
handlers, repos, userID := setupSpaceSessionAPITest(t)
router := gin.New()
- router.POST("/space/entity-key", handlers.CreateSpaceEntityKey)
- router.POST("/space/entity-key/ensure", handlers.EnsureSpaceEntityKey)
+ router.POST("/account/space/entity-key", handlers.CreateSpaceEntityKey)
+ router.POST("/account/space/entity-key/ensure", handlers.EnsureSpaceEntityKey)
body := `{"type":"space","encryptedKey":"` + testEncodedSpaceEntityKey(48) + `","header":"` + testEncodedSpaceEntityKey(24) + `"}`
- for _, path := range []string{"/space/entity-key", "/space/entity-key/ensure"} {
+ for _, path := range []string{"/account/space/entity-key", "/account/space/entity-key/ensure"} {
req := httptest.NewRequest(http.MethodPost, path, bytes.NewBufferString(body))
req.Header.Set("X-Auth-User-ID", strconv.FormatInt(userID, 10))
recorder := httptest.NewRecorder()
@@ -165,8 +165,8 @@ func TestBootstrapBrowserSessionAcceptsHeader(t *testing.T) {
tokenHash := sha256.Sum256([]byte(token))
require.NoError(t, repos.Sessions.CreateBrowserSession(context.Background(), tokenHash[:], userID, "session-wrap-key", timeutil.NDaysFromNow(1)))
router := gin.New()
- router.POST("/space/sessions/bootstrap", handlers.BootstrapBrowserSession)
- req := httptest.NewRequest(http.MethodPost, "/space/sessions/bootstrap", nil)
+ router.POST("/account/space/sessions/bootstrap", handlers.BootstrapBrowserSession)
+ req := httptest.NewRequest(http.MethodPost, "/account/space/sessions/bootstrap", nil)
req.Header.Set(controller.SpaceBrowserSessionTokenHeader, token)
recorder := httptest.NewRecorder()
@@ -182,8 +182,8 @@ func TestDeleteBrowserSessionRevokesHeaderSession(t *testing.T) {
tokenHash := sha256.Sum256([]byte(token))
require.NoError(t, repos.Sessions.CreateBrowserSession(context.Background(), tokenHash[:], userID, "session-wrap-key", timeutil.NDaysFromNow(1)))
router := gin.New()
- router.DELETE("/space/sessions/current", handlers.DeleteBrowserSession)
- req := httptest.NewRequest(http.MethodDelete, "/space/sessions/current", nil)
+ router.DELETE("/account/space/sessions/current", handlers.DeleteBrowserSession)
+ req := httptest.NewRequest(http.MethodDelete, "/account/space/sessions/current", nil)
req.Header.Set(controller.SpaceBrowserSessionTokenHeader, token)
recorder := httptest.NewRecorder()
diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsx
index 1c0f7a6d38..8a601f5d16 100644
--- a/web/apps/space/src/pages/app/index.tsx
+++ b/web/apps/space/src/pages/app/index.tsx
@@ -284,7 +284,9 @@ const Page: React.FC = () => {
: undefined
}
onDeletePost={async (postId) => {
- await deleteCurrentPost(postId);
+ const spaceId = profile?.spaceId;
+ if (!spaceId) throw new Error("Missing space.");
+ await deleteCurrentPost(spaceId, postId);
setLocalFeedPosts((currentPosts) =>
currentPosts.filter(
(item) =>
diff --git a/web/apps/space/src/pages/app/profile.tsx b/web/apps/space/src/pages/app/profile.tsx
index 706d531c14..f1b2f5a516 100644
--- a/web/apps/space/src/pages/app/profile.tsx
+++ b/web/apps/space/src/pages/app/profile.tsx
@@ -180,7 +180,9 @@ const Page: React.FC = () => {
}}
onDraftPostPublished={() => void router.push(spaceRoutes.home)}
onDeletePost={async (postId) => {
- await deleteCurrentPost(postId);
+ const spaceId = profile?.spaceId;
+ if (!spaceId) throw new Error("Missing space.");
+ await deleteCurrentPost(spaceId, postId);
setLocalFeedPosts((currentPosts) =>
currentPosts.filter(
(item) =>
diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.ts
index 4b9dd1965f..824d37427a 100644
--- a/web/apps/space/src/services/space.ts
+++ b/web/apps/space/src/services/space.ts
@@ -1308,10 +1308,10 @@ export const markCurrentMessagesRead = async (
}
};
-export const deleteCurrentPost = async (postId: number) => {
+export const deleteCurrentPost = async (spaceId: string, postId: number) => {
const ctx = await ensureCurrentSpaceContext();
try {
- await ctx.delete_post(BigInt(postId));
+ await ctx.delete_post(spaceId, BigInt(postId));
} finally {
releaseCurrentSpaceContext(ctx);
}
diff --git a/web/apps/space/src/services/spacePersistentSession.ts b/web/apps/space/src/services/spacePersistentSession.ts
index 188db244c7..3939a0bc54 100644
--- a/web/apps/space/src/services/spacePersistentSession.ts
+++ b/web/apps/space/src/services/spacePersistentSession.ts
@@ -106,7 +106,7 @@ export const createSpaceBrowserSession = async (
authToken: string,
) => {
const sessionWrapKey = await generateKey();
- const res = await fetch(await apiURL("/space/sessions"), {
+ const res = await fetch(await apiURL("/account/space/sessions"), {
method: "POST",
headers: {
...spaceBootstrapAuthHeaders(authToken),
@@ -158,7 +158,7 @@ const restoreSpaceBrowserSession = async () => {
const persisted = savedPersistedSession();
if (!persisted) return false;
- const res = await fetch(await apiURL("/space/sessions/bootstrap"), {
+ const res = await fetch(await apiURL("/account/space/sessions/bootstrap"), {
method: "POST",
headers: {
...publicRequestHeaders(),
@@ -192,7 +192,7 @@ export const getOrCreateSpaceRootKey = async (
) => {
const candidate = await generateKey();
const encryptedKey = await encryptSpaceRootEntityKey(candidate, masterKey);
- const res = await fetch(await apiURL("/space/entity-key/ensure"), {
+ const res = await fetch(await apiURL("/account/space/entity-key/ensure"), {
method: "POST",
headers: {
...spaceBootstrapAuthHeaders(authToken),
@@ -209,7 +209,7 @@ export const revokeSpaceBrowserSession = async () => {
const sessionToken = savedSpaceSessionToken();
try {
if (!sessionToken) return;
- const res = await fetch(await apiURL("/space/sessions/current"), {
+ const res = await fetch(await apiURL("/account/space/sessions/current"), {
method: "DELETE",
headers: {
...publicRequestHeaders(),