diff options
| author | Fuwn <[email protected]> | 2021-07-05 15:19:50 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-07-05 15:19:50 -0700 |
| commit | 192b702cc5efab5eea0ebde8ef9fc25c83372dc3 (patch) | |
| tree | 7e985584aa5b15045a41759afe9357eb3b272795 | |
| parent | feat(whirl_api): /api/v1/worlds/vip endpoint (diff) | |
| download | whirl-192b702cc5efab5eea0ebde8ef9fc25c83372dc3.tar.xz whirl-192b702cc5efab5eea0ebde8ef9fc25c83372dc3.zip | |
feat(whirl_api): /api/v1/worlds/info endpoint
An endpoint for grabbing user profile information. Example usage:
https://api.whirlsplash.org/api/v1/worlds/info?username=fuwn will return *a lot of information*.
| -rw-r--r-- | crates/whirl_api/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/whirl_api/src/routes/worlds/info/mod.rs | 38 | ||||
| -rw-r--r-- | crates/whirl_api/src/routes/worlds/mod.rs | 1 |
3 files changed, 40 insertions, 0 deletions
diff --git a/crates/whirl_api/src/lib.rs b/crates/whirl_api/src/lib.rs index 59de414..a72df55 100644 --- a/crates/whirl_api/src/lib.rs +++ b/crates/whirl_api/src/lib.rs @@ -57,6 +57,7 @@ impl Api { .service(resource("/").to(|| async { "Whirlsplash" })) .service(resource("/api/v1/statistics").to(routes::stats::statistics)) .service(resource("/api/v1/worlds/vip").to(routes::worlds::vip::vip)) + .service(resource("/api/v1/worlds/info").to(routes::worlds::info::info)) }) .bind(address)? .run(); diff --git a/crates/whirl_api/src/routes/worlds/info/mod.rs b/crates/whirl_api/src/routes/worlds/info/mod.rs new file mode 100644 index 0000000..eedac82 --- /dev/null +++ b/crates/whirl_api/src/routes/worlds/info/mod.rs @@ -0,0 +1,38 @@ +// Copyright (C) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +use std::str::from_utf8; + +use actix_web::{HttpRequest, HttpResponse}; + +// error: this argument is passed by value, but not consumed in the function +// body +#[allow(clippy::needless_pass_by_value)] +pub fn info(req: HttpRequest) -> HttpResponse { + let mut easy = curl::easy::Easy::new(); + + easy + .url(&format!( + "http://www-dynamic.us.worlds.net/cgi-bin/profile.pl?{}", + qstring::QString::from(req.query_string()) + .get("username") + .unwrap_or("null"), + )) + .unwrap(); + + let mut response = Vec::new(); + + // https://docs.rs/curl/0.4.6/curl/easy/struct.Easy.html + { + let mut transfer = easy.transfer(); + transfer + .write_function(|data| { + response.extend_from_slice(data); + Ok(data.len()) + }) + .unwrap(); + transfer.perform().unwrap(); + } + + HttpResponse::Ok().body(from_utf8(&response).unwrap().to_string()) +} diff --git a/crates/whirl_api/src/routes/worlds/mod.rs b/crates/whirl_api/src/routes/worlds/mod.rs index 32351f8..21f4222 100644 --- a/crates/whirl_api/src/routes/worlds/mod.rs +++ b/crates/whirl_api/src/routes/worlds/mod.rs @@ -1,4 +1,5 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only +pub mod info; pub mod vip; |