1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Add avatar saving functionality (without CDN support)

This commit is contained in:
NG (Graham)
2025-05-25 12:26:08 -04:00
parent 2607903f7b
commit 956bb2149d
13 changed files with 184 additions and 34 deletions

View File

@@ -526,6 +526,40 @@ impl <C: Clone> super::User<C> for UserData {
Ok(0)
}
}
async fn get_avatar_info(&self) -> Result<super::GetAvatarInfo<C>, i16> {
let avatar_id_aux = self.db.user_aux_by_user_id_and_descriptor(self.account.id, rc_database::schema::user_aux::Descriptor::AvatarId).await
.map_err(|e| {
log::error!("Failed to retrieve AvatarId (user_aux) for user_id {}: {}", self.account.id, e);
DATABASE_ERR
})?
.ok_or_else(|| {
log::error!("Failed to find AvatarId (user_aux) for user_id {}", self.account.id);
DATABASE_ERR
})?;
let avatar_id: u32 = avatar_id_aux.data.parse()
.map_err(|e| {
log::error!("Failed to parse AvatarId (user_aux) for user_id {}: {}", self.account.id, e);
crate::data::error_codes::WebServicesError::UnexpectedError as i16
})?;
Ok(super::GetAvatarInfo {
avatar_id: polariton::operation::Typed::Int(if avatar_id == u32::MAX { 0 } else { avatar_id as i32 }),
use_custom: polariton::operation::Typed::Bool(avatar_id == u32::MAX),
})
}
async fn set_avatar_info(&self, info: super::AvatarInfo) -> Result<(), i16> {
let to_update = rc_database::schema::user_aux::ActiveModel {
data: rc_database::sea_orm::ActiveValue::Set(if info.use_custom { u32::MAX } else { info.avatar_id as u32 }.to_string()),
..Default::default()
};
self.db.update_user_aux_by_user_id_and_descriptor(to_update, self.account.id, rc_database::schema::user_aux::Descriptor::AvatarId).await
.map_err(|e| {
log::error!("Failed to update AvatarId (user_aux) for user_id {}: {}", self.account.id, e);
DATABASE_ERR
})?;
Ok(())
}
}
#[async_trait::async_trait]

View File

@@ -137,6 +137,13 @@ r#"{
creation_time: rc_database::sea_orm::ActiveValue::Set(current_time),
descriptor: rc_database::sea_orm::ActiveValue::Set(rc_database::schema::user_aux::Descriptor::SubscribedChannels),
data: rc_database::sea_orm::ActiveValue::Set("[\"sys\"]".to_owned()),
},
rc_database::schema::user_aux::ActiveModel {
id: Default::default(),
user_id: rc_database::sea_orm::ActiveValue::Set(user_id),
creation_time: rc_database::sea_orm::ActiveValue::Set(current_time),
descriptor: rc_database::sea_orm::ActiveValue::Set(rc_database::schema::user_aux::Descriptor::AvatarId),
data: rc_database::sea_orm::ActiveValue::Set((current_time % 16).to_string()),
}
]
}

View File

@@ -11,7 +11,7 @@ mod inventory;
pub use inventory::UnlockedParts;
mod traits;
pub use traits::{UserProvider, User, UserToken, UserSlots, UserSlotData, VehicleData, UserInfo, UserLoginInfo, ExtraUserInfo, UserAuthenticator, NewSlotData, UserId, RegistrationInfo, VehicleUploadData, ChatUser};
pub use traits::{UserProvider, User, UserToken, UserSlots, UserSlotData, VehicleData, UserInfo, UserLoginInfo, ExtraUserInfo, UserAuthenticator, NewSlotData, UserId, RegistrationInfo, VehicleUploadData, ChatUser, AvatarInfo, GetAvatarInfo};
pub const TOKEN_SECRET_FILENAME: &str = "token_secret.key";

View File

@@ -73,6 +73,8 @@ pub trait User<C>: ChatUser {
async fn singleplayer_robots(&self) -> Result<polariton::operation::Typed<C>, i16>;
async fn prepare_factory_upload(&self, vehicle: VehicleUploadData) -> Result<rc_factory::VehicleUploadInfo, i16>;
async fn last_seen(&self) -> Result<u64, i16>;
async fn get_avatar_info(&self) -> Result<GetAvatarInfo<C>, i16>;
async fn set_avatar_info(&self, info: AvatarInfo) -> Result<(), i16>;
}
pub struct UserSlots<C> {
@@ -122,13 +124,21 @@ pub struct VehicleUploadData {
pub thumbnail: Vec<u8>,
}
use polariton::operation::Typed;
pub struct GetAvatarInfo<C> {
pub avatar_id: polariton::operation::Typed<C>,
pub use_custom: polariton::operation::Typed<C>,
}
pub struct AvatarInfo {
pub avatar_id: i32,
pub use_custom: bool,
}
#[async_trait::async_trait]
pub trait ChatUser {
async fn subscribed_channels(&self) -> Result<Typed<()>, i16>;
async fn subscribed_channels(&self) -> Result<polariton::operation::Typed<()>, i16>;
async fn subscribed_channels_strings(&self) -> Result<Vec<String>, i16>;
async fn add_subscribed_channel(&self, channel: String, channel_ty: crate::data::channel::ChatChannelType) -> Result<Typed<()>, i16>;
async fn add_subscribed_channel(&self, channel: String, channel_ty: crate::data::channel::ChatChannelType) -> Result<polariton::operation::Typed<()>, i16>;
async fn remove_subscribed_channel(&self, channel: String, channel_ty: crate::data::channel::ChatChannelType) -> Result<(), i16>;
}