Skip to content

Commit

Permalink
Irvine veh proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed Apr 1, 2024
1 parent 326df51 commit 81c796e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 35 additions & 0 deletions src/birch/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 81c796e

Please sign in to comment.