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:
@@ -32,6 +32,8 @@ async fn main() -> std::io::Result<()> {
|
||||
.service(robocraft::brawl_data::get)
|
||||
.service(robocraft::campaign_data::get)
|
||||
.service(robocraft::factory::arc::get)
|
||||
.service(robocraft::factory::thumbnail::get)
|
||||
.service(robocraft::factory::thumbnail::post)
|
||||
.service(robocraft::favicon::get)
|
||||
})
|
||||
.bind((cli_args.ip, cli_args.port))?
|
||||
|
||||
@@ -8,7 +8,7 @@ static ZIP_FILE: std::sync::Mutex<Option<zip::read::ZipArchive<std::io::BufReade
|
||||
pub async fn get(cli: Data<crate::cli::CliArgs>, id: Path<u32>) -> HttpResponse {
|
||||
let id: u32 = *id;
|
||||
let zip_path = std::path::PathBuf::from(&cli.data_robocraft).join("rc_archive_thumbnails.zip");
|
||||
let thumb_dir_path = std::path::PathBuf::from(&cli.data_robocraft).join("factorythumbnails");
|
||||
let thumb_dir_path = std::path::PathBuf::from(&cli.data_robocraft).join(super::THUMBNAIL_DIR);
|
||||
try_find_file(zip_path, thumb_dir_path, id).await
|
||||
}
|
||||
|
||||
@@ -79,6 +79,8 @@ fn get_file_in_zip(zip_path: std::path::PathBuf, id: u32) -> zip::result::ZipRes
|
||||
}
|
||||
|
||||
fn get_file_in_thumbnails(dir: std::path::PathBuf, id: u32) -> std::io::Result<Vec<u8>> {
|
||||
// in case someone has extracted the thumbnail zip
|
||||
// (newly-uploaded vehicles use the general thumbnail CDN endpoint)
|
||||
let prefix = format!("{} - ", id);
|
||||
for ent in std::fs::read_dir(&dir)? {
|
||||
let ent = ent?;
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
pub mod arc;
|
||||
pub mod thumbnail;
|
||||
|
||||
const THUMBNAIL_DIR: &str = "factorythumbnails";
|
||||
|
||||
22
cdn/src/robocraft/factory/thumbnail.rs
Normal file
22
cdn/src/robocraft/factory/thumbnail.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use actix_web::{get, post, web::{Data, Path, Bytes}, Responder};
|
||||
|
||||
#[get("/roboshop/Live/{id}")]
|
||||
pub async fn get(cli: Data<crate::cli::CliArgs>, id: Path<u32>) -> impl Responder {
|
||||
let path = std::path::PathBuf::from(&cli.data_robocraft).join(super::THUMBNAIL_DIR).join(format!("{}.jpg", id));
|
||||
log::debug!("RC asset at {} (exists? {})", path.display(), path.exists());
|
||||
if path.exists() {
|
||||
actix_files::NamedFile::open_async(path).await
|
||||
} else {
|
||||
log::info!("Not found /roboshop/Live/{} -> {}, using default image", id, path.display());
|
||||
actix_files::NamedFile::open_async(std::path::PathBuf::from(&cli.assets_robocraft).join(super::super::DEFAULT_IMAGE)).await
|
||||
}
|
||||
}
|
||||
|
||||
#[post("/roboshop/Live/{id}")]
|
||||
pub async fn post(cli: Data<crate::cli::CliArgs>, auth: Data<crate::robocraft::IntercomAuth>, id: Path<i32>, body: Bytes, req: actix_web::HttpRequest) -> Result<actix_web::HttpResponse, crate::robocraft::IntercomOpError> {
|
||||
auth.validate(&req, &id.to_string())?;
|
||||
let path = std::path::PathBuf::from(&cli.data_robocraft).join(super::THUMBNAIL_DIR).join(format!("{}.jpg", *id));
|
||||
log::debug!("Saving factory thumbnail for {} to {}: {}B", id, path.display(), body.len());
|
||||
std::fs::write(path, &body).map_err(crate::robocraft::IntercomOpError::Io)?;
|
||||
Ok(actix_web::HttpResponse::NoContent().finish())
|
||||
}
|
||||
Reference in New Issue
Block a user