Skip to main content

app_facade_api/
user.rs

1//! Cloud-owned account profile.
2//!
3//! The display name is the account `name`. Avatar bytes stay in private object
4//! storage: the account stores the object key, prepare returns a short-lived
5//! upload URL, and get returns a short-lived read URL. Neither value is a
6//! Space setting.
7
8use serde::{Deserialize, Serialize};
9
10pub const PROFILE_GET: &str = "/app/user/profile/get";
11pub const PROFILE_UPDATE: &str = "/app/user/profile/update";
12pub const AVATAR_PREPARE: &str = "/app/user/profile/avatar/prepare";
13pub const AVATAR_COMMIT: &str = "/app/user/profile/avatar/commit";
14pub const AVATAR_CLEAR: &str = "/app/user/profile/avatar/clear";
15pub const CONTRACT: &str = "mhome.user.profile.v1";
16
17pub const REQUEST_TARGETS: &[&str] = &[
18    PROFILE_GET,
19    PROFILE_UPDATE,
20    AVATAR_PREPARE,
21    AVATAR_COMMIT,
22    AVATAR_CLEAR,
23];
24
25#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
26#[serde(rename_all = "camelCase", deny_unknown_fields)]
27pub struct ProfileGetRequest {}
28
29#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
30#[serde(rename_all = "camelCase", deny_unknown_fields)]
31pub struct ProfileUpdateRequest {
32    pub name: String,
33}
34
35#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
36#[serde(rename_all = "camelCase", deny_unknown_fields)]
37pub struct PrepareAvatarRequest {
38    pub content_type: String,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42#[serde(rename_all = "camelCase", deny_unknown_fields)]
43pub struct CommitAvatarRequest {
44    pub object_key: String,
45}
46
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
48#[serde(rename_all = "camelCase", deny_unknown_fields)]
49pub struct ClearAvatarRequest {}
50
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
52#[serde(rename_all = "camelCase")]
53pub struct UserProfile {
54    pub name: String,
55    pub email: String,
56    #[serde(default, skip_serializing_if = "Option::is_none")]
57    pub avatar_url: Option<String>,
58    #[serde(default, skip_serializing_if = "Option::is_none")]
59    pub avatar_expires_at_ms: Option<i64>,
60}
61
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63#[serde(rename_all = "camelCase")]
64pub struct PreparedAvatarUpload {
65    pub object_key: String,
66    pub upload_url: String,
67    pub expires_at_ms: i64,
68    pub content_type: String,
69    pub max_bytes: i64,
70}