From e0572b30d150e935cee3221aa800cba820653cd4 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Tue, 2 Jul 2024 02:56:58 +0200 Subject: [PATCH] fixed minor fuckups --- server/main-api/src/limited/hash_map.rs | 12 +++++++----- server/main-api/src/maps/mod.rs | 16 ++++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/server/main-api/src/limited/hash_map.rs b/server/main-api/src/limited/hash_map.rs index c4bc62753..da4322032 100644 --- a/server/main-api/src/limited/hash_map.rs +++ b/server/main-api/src/limited/hash_map.rs @@ -16,10 +16,12 @@ impl From> for LimitedHashMap { } const LIMIT: usize = 3; -impl fmt::Debug for LimitedHashMap { +impl fmt::Debug + for LimitedHashMap +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut collection = self.0.clone().into_iter().collect::>(); - collection.sort_unstable_by(|(k1,_),(k2,_)|k1.cmp(k2)); + let mut collection = self.0.clone().into_iter().collect::>(); + collection.sort_unstable_by(|(k1, _), (k2, _)| k1.cmp(k2)); if self.0.len() <= LIMIT { f.debug_map().entries(collection).finish() } else { @@ -28,8 +30,8 @@ impl fmt::Debug for L collection .into_iter() .take(LIMIT) - .map(|(k,v)|(OrMore::Value(k),OrMore::Value(v))) - .chain([(OrMore::More,OrMore::More)]) + .map(|(k, v)| (OrMore::Value(k), OrMore::Value(v))) + .chain([(OrMore::More, OrMore::More)]), ) .finish() } diff --git a/server/main-api/src/maps/mod.rs b/server/main-api/src/maps/mod.rs index 2a289e362..fdb198aa2 100644 --- a/server/main-api/src/maps/mod.rs +++ b/server/main-api/src/maps/mod.rs @@ -10,6 +10,7 @@ use tokio::time::Instant; use tracing::{debug, error, warn}; use unicode_truncate::UnicodeTruncateStr; +use crate::limited::vec::LimitedVec; use crate::maps::overlay_map::OverlayMapTask; use crate::maps::overlay_text::{OverlayText, CANTARELL_BOLD, CANTARELL_REGULAR}; use crate::models::Location; @@ -61,7 +62,10 @@ async fn get_localised_data( } #[tracing::instrument] -async fn construct_image_from_data(data: Location, format: PreviewFormat) -> Option> { +async fn construct_image_from_data( + data: Location, + format: PreviewFormat, +) -> Option> { let start_time = Instant::now(); let mut img = match format { PreviewFormat::OpenGraph => image::RgbaImage::new(1200, 630), @@ -91,10 +95,10 @@ fn draw_pin(img: &mut ImageBuffer, Vec>) { ); } -fn wrap_image_in_response(img: &image::RgbaImage) -> Vec { +fn wrap_image_in_response(img: &image::RgbaImage) -> LimitedVec { let mut w = Cursor::new(Vec::new()); img.write_to(&mut w, image::ImageFormat::Png).unwrap(); - w.into_inner() + LimitedVec(w.into_inner()) } const WHITE_PIXEL: Rgba = Rgba([255, 255, 255, 255]); fn draw_bottom(data: &Location, img: &mut image::RgbaImage) { @@ -125,13 +129,13 @@ fn draw_bottom(data: &Location, img: &mut image::RgbaImage) { .draw_onto(img); } -fn load_default_image() -> Vec { +fn load_default_image() -> LimitedVec { warn!("Loading default preview image, as map rendering failed. Check the connection to the tileserver"); let img = image::load_from_memory(include_bytes!("static/logo-card.png")).unwrap(); // encode the image as PNG let mut w = Cursor::new(Vec::new()); img.write_to(&mut w, image::ImageFormat::Png).unwrap(); - w.into_inner() + LimitedVec(w.into_inner()) } #[tracing::instrument(skip(pool))] @@ -216,5 +220,5 @@ pub async fn maps_handler( "Preview Generation for {id} took {elapsed:?}", elapsed = start_time.elapsed() ); - HttpResponse::Ok().content_type("image/png").body(img) + HttpResponse::Ok().content_type("image/png").body(img.0) }