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

Add intercom functionality for setting factory thumbnails

This commit is contained in:
NG (Graham)
2025-12-13 16:10:45 -05:00
parent aedec62b8d
commit f6f6e1f127
17 changed files with 96 additions and 36 deletions

View File

@@ -22,19 +22,23 @@ impl oj_rc_factory::VehicleFactoryAdapter for Factory {
}
}
async fn upload(&self, vehicle: oj_rc_factory::VehicleUploadInfo) -> Result<bool, Box<dyn std::error::Error>> {
async fn upload(&self, vehicle: oj_rc_factory::VehicleUploadInfo) -> Result<oj_rc_factory::VehicleThumbnailInfo, Box<dyn std::error::Error>> {
match self {
Self::Arc(x) => x.upload(vehicle).await,
Self::Custom(x) => x.upload(vehicle).await,
Self::None => Ok(false),
Self::None => Ok(oj_rc_factory::VehicleThumbnailInfo {
id: i32::MIN,
thumbnail: vehicle.thumbnail,
needs_upload: false,
}),
}
}
}
impl Factory {
pub async fn from_config(conf: &crate::persist::FactoryConfig) -> Result<Self, Box<dyn std::error::Error + 'static>> {
pub async fn from_config(conf: &crate::persist::FactoryConfig, settings: &crate::persist::config::ServerConfig) -> Result<Self, Box<dyn std::error::Error + 'static>> {
Ok(match &conf.adapter {
crate::persist::AdapterSettings::Arc(x) => Self::Arc(oj_rc_factory::arc::ArcAdapter::init(&x.uri, x.show_expired, x.cdn.clone(), x.override_cdn, x.spoof_username).await?),
crate::persist::AdapterSettings::Arc(x) => Self::Arc(oj_rc_factory::arc::ArcAdapter::init(&x.uri, x.show_expired, settings.cdn_url.to_owned(), x.override_cdn, x.spoof_username).await?),
crate::persist::AdapterSettings::None => Self::None,
})
}

View File

@@ -293,8 +293,8 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
auto_signup: self.settings.server.auto_signup,
queue_mode: super::QueueChangeMode::from_persist(self.settings.server.queue_mode.clone()),
cdn_url: self.settings.server.cdn_url.trim_end_matches('/').to_owned(),
auth_url: self.settings.server.auth_url.trim_matches('/').to_owned(),
intercom_url: self.settings.server.intercom_url.trim_matches('/').to_owned(),
auth_url: self.settings.server.auth_url.trim_end_matches('/').to_owned(),
intercom_url: self.settings.server.intercom_url.trim_end_matches('/').to_owned(),
}
}
@@ -308,7 +308,7 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
}
async fn factory(&self) -> Result<crate::factory::Factory, Box<dyn std::error::Error + 'static>> {
crate::factory::Factory::from_config(&self.factory).await
crate::factory::Factory::from_config(&self.factory, &<Self as super::ConfigProvider<()>>::server_config(self)).await
}
fn cubes(&self) -> &'_ indexmap::IndexMap<String, crate::persist::Cube> {

View File

@@ -124,7 +124,7 @@ fn default_server_conf() -> ServerSettings {
}
}
pub fn default_cdn_root_url() -> String {
fn default_cdn_root_url() -> String {
"http://127.0.0.1:8010".to_owned()
}

View File

@@ -53,6 +53,21 @@ impl super::IntercomUser for super::account_json::UserData {
Ok(())
}
async fn save_factory_thumbnail(&self, factory_id: i32, image: Vec<u8>) -> Result<(), polariton_server::operations::SimpleOpError> {
let token = generate_token(factory_id.to_string().as_bytes(), &self.secret);
let auth_header_val = format!("Internal {}", token);
let url = format!("{}/roboshop/Live/{}", self.cdn, factory_id);
if let Err(e) = self.http_client.post(url)
.header("Authorization", auth_header_val)
.body(image)
.send()
.await {
log::error!("Failed to update factory thumbnail for {} ({}): {}", self.account.public_id, self.account.id, e);
return Err((crate::data::error_codes::WebServicesError::UnexpectedError as i16).into());
}
Ok(())
}
async fn webservice_listener(&self) -> Result<super::IntercomListener<IntercomWebServiceUserMessage>, polariton_server::operations::SimpleOpError> {
self.listen_on_websocket(".oj_services").await
.map_err(|e| polariton_server::operations::SimpleOpError::with_message(

View File

@@ -336,6 +336,7 @@ pub trait MultiplayerUser: IntercomUser + CommonUser {
#[async_trait::async_trait]
pub trait IntercomUser: CommonUser {
async fn save_custom_avatar(&self, image: Vec<u8>) -> Result<(), polariton_server::operations::SimpleOpError>;
async fn save_factory_thumbnail(&self, factory_id: i32, image: Vec<u8>) -> Result<(), polariton_server::operations::SimpleOpError>;
async fn webservice_listener(&self) -> Result<IntercomListener<super::intercom::IntercomWebServiceUserMessage>, polariton_server::operations::SimpleOpError>;
async fn show_dev_message(&self, msg: super::intercom::IntercomDevMessage, to: Vec<String>);
async fn enter_maintenance(&self, msg: super::intercom::IntercomMaintenanceMessage, to: Vec<String>);

View File

@@ -31,19 +31,12 @@ pub struct ArcFactorySettings {
pub uri: String,
#[serde(default = "default_true")]
pub show_expired: bool,
/// should probably end with /roboshop/arc/Live/
#[serde(default = "default_arc_live_url")]
pub cdn: String,
#[serde(default)]
pub override_cdn: bool,
#[serde(default = "default_true")]
pub spoof_username: bool,
}
fn default_arc_live_url() -> String {
format!("{}/roboshop/arc/Live/", super::settings::default_cdn_root_url())
}
fn default_true() -> bool {
true
}