aboutsummaryrefslogtreecommitdiff
path: root/crates/whirl_api/src/routes/worlds/info/mod.rs
blob: a9d098ab026a5b5968d714ac81aea8ff528e144b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (C) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only

#[derive(Serialize, Deserialize)]
pub struct Parameters {
  username: Option<String>,
}

#[allow(clippy::needless_pass_by_value, clippy::unused_async)]
pub async fn info(
  axum::extract::Query(req): axum::extract::Query<Parameters>,
) -> &'static str {
  let mut easy = curl::easy::Easy::new();

  easy
    .url(&format!(
      "http://www-dynamic.us.worlds.net/cgi-bin/profile.pl?{}",
      req.username.as_ref().unwrap_or(&String::new()),
    ))
    .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();
  }

  Box::leak(String::from_utf8(response).unwrap().into_boxed_str())
}