mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Enable premium, add custom avatar saving support to complete #10
This commit is contained in:
28
rc_core/src/persist/user/intercom.rs
Normal file
28
rc_core/src/persist/user/intercom.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
#[async_trait::async_trait]
|
||||
impl super::IntercomUser for super::account_json::UserData {
|
||||
async fn save_custom_avatar(&self, image: Vec<u8>) -> Result<(), polariton_server::operations::SimpleOpError> {
|
||||
// seems to always be jpg
|
||||
let token = generate_token(self.account.public_id.as_bytes(), &self.secret);
|
||||
let auth_header_val = format!("Internal {}", token);
|
||||
let url = format!("{}/customavatar/Live/{}", self.cdn, self.account.public_id);
|
||||
if let Err(e) = reqwest::Client::new().post(url)
|
||||
.header("Authorization", auth_header_val)
|
||||
.body(image)
|
||||
.send()
|
||||
.await {
|
||||
log::error!("Failed to update custom avatar for {} ({}): {}", self.account.public_id, self.account.id, e);
|
||||
return Err((crate::data::error_codes::WebServicesError::UnexpectedError as i16).into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_token(salt: &[u8], key: &[u8]) -> String {
|
||||
use sha2::{Digest, Sha512};
|
||||
let mut hasher = Sha512::new();
|
||||
hasher.update(salt);
|
||||
hasher.update(key);
|
||||
let token_bytes = hasher.finalize();
|
||||
hex::encode(&token_bytes[..])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user