1
0
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:
NG (Graham)
2025-08-13 17:36:44 -04:00
parent 2642767a27
commit a8692b2839
16 changed files with 178 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
use actix_web::{get, web::{Data, Path}, Responder};
use actix_web::{get, post, web::{Data, Path, Bytes}, Responder};
#[get("/customavatar/Live/{name}")]
pub async fn get(cli: Data<crate::cli::CliArgs>, name: Path<String>) -> impl Responder {
@@ -11,3 +11,12 @@ pub async fn get(cli: Data<crate::cli::CliArgs>, name: Path<String>) -> impl Res
actix_files::NamedFile::open_async(std::path::PathBuf::from(&cli.assets_robocraft).join(super::DEFAULT_IMAGE)).await
}
}
#[post("/customavatar/Live/{name}")]
pub async fn post(cli: Data<crate::cli::CliArgs>, auth: Data<crate::robocraft::IntercomAuth>, name: Path<String>, body: Bytes, req: actix_web::HttpRequest) -> Result<actix_web::HttpResponse, super::IntercomOpError> {
auth.validate(&req, &name)?;
let path = std::path::PathBuf::from(&cli.data_robocraft).join("customavatars").join(format!("{}.jpg", *name));
log::debug!("Saving customavatar for {} to {}: {}B", name, path.display(), body.len());
std::fs::write(path, &body).map_err(super::IntercomOpError::Io)?;
Ok(actix_web::HttpResponse::NoContent().finish())
}