mirror of
https://github.com/a-b-street/abstreet.git
synced 2025-01-05 04:52:16 +03:00
Get the HTTP POST working on wasm too
This commit is contained in:
parent
01fbfd37ae
commit
090256668e
@ -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]
|
||||
|
15
abstio/src/http_post.rs
Normal file
15
abstio/src/http_post.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use anyhow::Result;
|
||||
|
||||
/// Performs an HTTP POST request and returns the respone.
|
||||
pub async fn http_post<I: AsRef<str>>(url: I, body: String) -> Result<String> {
|
||||
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)
|
||||
}
|
@ -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
|
||||
|
@ -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<dyn State<App>> {
|
||||
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::<App, String>::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<dyn Send + FnOnce(&App) -> String> = Box::new(move |_| uuid);
|
||||
Ok(wrapper)
|
||||
|
Loading…
Reference in New Issue
Block a user