From 090256668e7c4cab6feae6e99cbc620749df39bd Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 16 Aug 2021 14:22:57 -0700 Subject: [PATCH] Get the HTTP POST working on wasm too --- abstio/Cargo.toml | 2 +- abstio/src/http_post.rs | 15 +++++++++++++++ abstio/src/lib.rs | 2 ++ game/src/ungap/mod.rs | 8 +++----- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 abstio/src/http_post.rs diff --git a/abstio/Cargo.toml b/abstio/Cargo.toml index f2ddebd325..7c33a8550b 100644 --- a/abstio/Cargo.toml +++ b/abstio/Cargo.toml @@ -11,12 +11,12 @@ bincode = "1.3.1" instant = "0.1.7" lazy_static = "1.4.0" log = "0.4.14" +reqwest = { version = "0.11.0", default-features=false, features=["rustls-tls"] } serde = "1.0.123" serde_json = "1.0.61" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] futures-channel = { version = "0.3.12"} -reqwest = { version = "0.11.0", default-features=false, features=["rustls-tls"] } tokio = "1.1.1" [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/abstio/src/http_post.rs b/abstio/src/http_post.rs new file mode 100644 index 0000000000..ecb6f196ca --- /dev/null +++ b/abstio/src/http_post.rs @@ -0,0 +1,15 @@ +use anyhow::Result; + +/// Performs an HTTP POST request and returns the respone. +pub async fn http_post>(url: I, body: String) -> Result { + let url = url.as_ref(); + info!("HTTP POST to {}", url); + let resp = reqwest::Client::new() + .post(url) + .body(body) + .send() + .await? + .text() + .await?; + Ok(resp) +} diff --git a/abstio/src/lib.rs b/abstio/src/lib.rs index af342247f3..ec5edd9b6c 100644 --- a/abstio/src/lib.rs +++ b/abstio/src/lib.rs @@ -25,9 +25,11 @@ pub use download::*; pub use abst_data::*; pub use abst_paths::*; +pub use http_post::*; mod abst_data; mod abst_paths; +mod http_post; mod io; /// An adapter for widgetry::Settings::read_svg to read SVGs using this crate's methods for finding diff --git a/game/src/ungap/mod.rs b/game/src/ungap/mod.rs index 853d5f7a8a..11bb75247a 100644 --- a/game/src/ungap/mod.rs +++ b/game/src/ungap/mod.rs @@ -410,16 +410,14 @@ fn make_legend(ctx: &mut EventCtx, app: &App, elevation: bool, nearby: bool) -> fn share_proposal(ctx: &mut EventCtx, app: &App) -> Box> { let (_, outer_progress_rx) = futures_channel::mpsc::channel(1); - let (mut inner_progress_tx, inner_progress_rx) = futures_channel::mpsc::channel(1); + let (_, inner_progress_rx) = futures_channel::mpsc::channel(1); let edits_json = abstutil::to_json_terse(&app.primary.map.get_edits().to_permanent(&app.primary.map)); - let url = "http://localhost:8080/create"; + let url = "http://localhost:8080/v1/create"; FutureLoader::::new_state( ctx, Box::pin(async move { - let raw_bytes = - abstio::download_bytes(url, Some(edits_json), &mut inner_progress_tx).await?; - let uuid = String::from_utf8(raw_bytes)?; + let uuid = abstio::http_post(url, edits_json).await?; // TODO I'm so lost in this type magic let wrapper: Box String> = Box::new(move |_| uuid); Ok(wrapper)