Format and lint

This commit is contained in:
Andras Schmelczer 2026-02-08 12:37:07 +00:00
parent 42ee2d4c51
commit 04a78e7bfe
75 changed files with 1290 additions and 719 deletions

View file

@ -15,7 +15,7 @@ use crate::routes::FeatureInfo;
use crate::state::AppState;
const MAX_EXPORT_POSTCODES: usize = 250;
/// Height (in pixels) reserved for the OG image row
/// Height (in pixels) reserved for the screenshot row
const IMAGE_ROW_HEIGHT: f64 = 225.0;
#[derive(Deserialize)]
@ -152,7 +152,7 @@ pub async fn get_export(
let public_url = state.public_url.clone();
// Compute view param for OG image and dashboard URL
// Compute view param for screenshot and dashboard URL
let center_lat = (south + north) / 2.0;
let center_lon = (west + east) / 2.0;
let lat_span = north - south;
@ -164,7 +164,7 @@ pub async fn get_export(
let view_param = format!("{:.4},{:.4},{:.1}", center_lat, center_lon, zoom);
// Fetch screenshot (async, before spawn_blocking)
let og_image_bytes = fetch_screenshot(&state, &view_param, filters_str.as_deref()).await;
let screenshot_bytes = fetch_screenshot(&state, &view_param, filters_str.as_deref()).await;
// Build feature name → description map from the precomputed features response
let feature_descriptions: FxHashMap<String, String> = state
@ -335,16 +335,16 @@ pub async fn get_export(
.set_row_format(0, &link_fmt)
.map_err(|err| format!("Failed to set row format: {err}"))?;
// Row 1: OG image (if available)
// Row 1: screenshot (if available)
let mut current_row = 1u32;
if let Some(ref img_bytes) = og_image_bytes {
if let Some(ref img_bytes) = screenshot_bytes {
match Image::new_from_buffer(img_bytes) {
Ok(mut image) => {
// Scale image to fit: ~400px wide, auto height preserving aspect ratio
image = image.set_scale_to_size(400, 300, true);
sheet
.insert_image(current_row, 0, &image)
.map_err(|err| format!("Failed to insert OG image: {err}"))?;
.map_err(|err| format!("Failed to insert screenshot: {err}"))?;
// Set row height to accommodate the image
sheet
.set_row_height(current_row, IMAGE_ROW_HEIGHT)
@ -352,7 +352,7 @@ pub async fn get_export(
current_row += 1;
}
Err(err) => {
warn!("Failed to parse OG image for export: {err}");
warn!("Failed to parse screenshot for export: {err}");
// Skip image row, don't leave a gap
}
}
@ -479,7 +479,7 @@ pub async fn get_export(
postcodes = postcode_aggs.len(),
sampled = was_sampled,
features = all_feature_indices.len(),
has_og_image = og_image_bytes.is_some(),
has_screenshot = screenshot_bytes.is_some(),
bytes = buf.len(),
total_ms = format_args!("{:.1}", t_total.as_secs_f64() * 1000.0),
"GET /api/export"