roblox_api/api/data/
mod.rs1use reqwest::header::{self, HeaderValue};
2
3use crate::{AssetTypeId, Error, client::Client};
4
5pub const URL: &str = "https://data.roblox.com/data";
6
7#[deprecated = "Use assets::v1"]
15pub async fn upload(
16 client: &mut Client,
17 id: Option<u64>,
18 name: &str,
19 description: &str,
20 asset_type: AssetTypeId,
21 group_id: Option<u64>,
22 genre: u8,
23 is_public: bool,
24 allow_comments: bool,
25 bytes: &[u8],
26) -> Result<u64, Error> {
27 let id = id.unwrap_or(0);
28 let genre_type_id = genre;
29
30 let mut url = format!("{URL}/upload.ashx&assetid={id}");
31 if let AssetTypeId::Model = asset_type {
32 url.push_str("&type=Model");
33 } else if let AssetTypeId::Place = asset_type {
34 url.push_str("&type=Place");
35 } else {
36 let asset_type_id = asset_type as u8;
37 url.push_str(&format!("&assetTypeId={asset_type_id}"));
38 }
39
40 if let Some(group_id) = group_id {
41 url.push_str(&format!("&groupId={}", group_id));
42 }
43
44 let mut headers = client.requestor.default_headers.clone();
45 headers.insert(
46 header::ACCEPT,
47 HeaderValue::from_str("application/json").unwrap(),
48 );
49
50 headers.insert(
51 header::CONTENT_TYPE,
52 HeaderValue::from_str("application/octect-stream").unwrap(),
53 );
54
55 let result = client
56 .requestor
57 .client
58 .post(url)
59 .query(&[
60 ("name", name),
61 ("description", description),
62 ("genreTypeId", &genre_type_id.to_string()),
63 ("isPublic", &is_public.to_string()),
64 ("allowComments", &allow_comments.to_string()),
65 ])
66 .headers(headers.clone())
67 .body(bytes.to_owned())
68 .send()
69 .await;
70
71 let response = client.requestor.validate_response(result).await?;
72
73 println!("test: {:?}", headers.clone());
74 let json = response.text().await?;
75
76 println!("text: {}", json.clone());
77 let id: u64 = json.parse().map_err(|_| Error::BadJson)?;
78
79 Ok(id)
80}