Skip to content

Commit

Permalink
Merge pull request #285 from go-bazzinga/debjit/avatars
Browse files Browse the repository at this point in the history
changed avatars
  • Loading branch information
debjit-bhowal-rs authored Aug 2, 2024
2 parents f0959f9 + bd31ec6 commit a2f0413
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ssr/src/component/video_player.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use leptos::*;
use leptos_dom::{html::Video, NodeRef};
use leptos_dom::html::Video;

#[component]
pub fn VideoPlayer(
Expand Down
3 changes: 3 additions & 0 deletions ssr/src/consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use reqwest::Url;

pub const CF_STREAM_BASE: &str = "https://customer-2p3jflss4r4hmpnz.cloudflarestream.com";
pub const FALLBACK_PROPIC_BASE: &str = "https://api.dicebear.com/7.x/big-smile/svg";
// an example URL is "https://imagedelivery.net/abXI9nS4DYYtyR1yFFtziA/gob.5/public";
pub const GOBGOB_PROPIC_URL: &str = "https://imagedelivery.net/abXI9nS4DYYtyR1yFFtziA/gob.";
pub const GOBGOB_TOTAL_COUNT: u32 = 18557;
pub const CF_WATERMARK_UID: &str = "c094ef579b950a6a5ae3e482268b81ca";
pub const ACCOUNT_CONNECTED_STORE: &str = "account-connected-1";
pub static CF_BASE_URL: Lazy<Url> =
Expand Down
24 changes: 10 additions & 14 deletions ssr/src/utils/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
UserProfileDetailsForFrontend,
},
component::infinite_scroller::{CursoredDataProvider, KeyedData, PageEntry},
consts::FALLBACK_PROPIC_BASE,
consts::{GOBGOB_PROPIC_URL, GOBGOB_TOTAL_COUNT},
state::canisters::Canisters,
};

Expand Down Expand Up @@ -44,9 +44,9 @@ impl From<UserProfileDetailsForFrontend> for ProfileDetails {
}
}

fn color_from_principal(principal: Principal) -> String {
let col_int = crc32fast::hash(principal.as_slice()) & 0xFFFFFF;
format!("{col_int:06x}")
fn index_from_principal(principal: Principal) -> u32 {
let hash_value = crc32fast::hash(principal.as_slice());
(hash_value % GOBGOB_TOTAL_COUNT) + 1
}

impl ProfileDetails {
Expand All @@ -63,22 +63,18 @@ impl ProfileDetails {
}

pub fn profile_pic_or_random(&self) -> String {
let propic = self.profile_pic.clone().unwrap_or_default();
if !propic.is_empty() {
return propic;
}
// let propic = self.profile_pic.clone().unwrap_or_default();
// if !propic.is_empty() {
// return propic;
// }

propic_from_principal(self.principal)
}
}

pub fn propic_from_principal(principal: Principal) -> String {
let background_color = color_from_principal(principal);
format!(
"{FALLBACK_PROPIC_BASE}?seed={}&backgroundColor={}&backgroundType=solid",
principal.to_text(),
background_color
)
let index = index_from_principal(principal);
format!("{GOBGOB_PROPIC_URL}{}/public", index)
}

#[derive(Clone, Copy)]
Expand Down

0 comments on commit a2f0413

Please sign in to comment.