From 81c796e44f1ee2d3afe5bd4283cec84a53267b67 Mon Sep 17 00:00:00 2001 From: Kyler Chin <7539174+kylerchin@users.noreply.github.com> Date: Mon, 1 Apr 2024 06:06:48 -0700 Subject: [PATCH] Irvine veh proxy --- Cargo.toml | 1 + src/birch/server.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index ed3b60ac..e57b55bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,6 +97,7 @@ rstar = "0.12.0" sqlx = {version = "0.7.4", features = ["postgres","runtime-tokio", "macros"]} tilejson = "0.4.1" tile-grid = "=0.2.2" +zstd-safe = "7.1.0" [[bin]] name = "maple" diff --git a/src/birch/server.rs b/src/birch/server.rs index fbdf8469..b20df6ec 100644 --- a/src/birch/server.rs +++ b/src/birch/server.rs @@ -11,9 +11,11 @@ use diesel::SelectableHelper; use diesel_async::RunQueryDsl; use geojson::{Feature, GeoJson, Geometry, JsonValue, Value}; use sqlx::postgres::{PgPoolOptions, PgRow}; +use zstd_safe::WriteBuf; use sqlx::{FromRow, Row}; use qstring::QString; use rstar::RTree; +use rand::Rng; use serde::Deserialize; use serde_derive::Serialize; use serde_json::to_string; @@ -307,6 +309,39 @@ pub async fn metrolinktrackproxy(req: HttpRequest) -> impl Responder { } } +#[actix_web::get("/irvinevehproxy")] +pub async fn irvinevehproxy(req:HttpRequest) -> impl Responder { + let raw_data = + reqwest::get("https://passio3.com/irvine/passioTransit/gtfs/realtime/vehiclePositions").await; + + match raw_data { + Ok(raw_data) => { + //println!("Raw data successfully downloaded"); + + let raw_text = raw_data.bytes().await; + + match raw_text { + Ok(raw_bytes) => { + + let hashofresult = fasthash::metro::hash64(raw_bytes.as_ref()); + + HttpResponse::Ok() + .insert_header(("Content-Type", "application/x-protobuf")) + .insert_header(("hash", hashofresult)) + .body(raw_bytes) + + }, + Err(error) => HttpResponse::InternalServerError() + .insert_header(("Content-Type", "text/plain")) + .body("Could not fetch Irvine data"), + } + } + Err(error) => HttpResponse::InternalServerError() + .insert_header(("Content-Type", "text/plain")) + .body("Could not fetch Irvine data"), + } +} + #[actix_web::get("/amtrakproxy")] pub async fn amtrakproxy(req: HttpRequest) -> impl Responder { let raw_data =