use std::time::Duration;
use dotenvy_macro::dotenv;
use roblox_api::{
AssetTypeId,
api::{
assets::{
self,
v1::{CreationContext, Creator},
},
develop, users,
},
client::Client,
};
#[tokio::main]
async fn main() {
let mut client = Client::from_cookie(dotenv!("ROBLOX_COOKIE").into());
let authenticated = users::v1::authenticated_details(&mut client).await.unwrap();
let bytes = &mut [
0x3c, 0x72, 0x6f, 0x62, 0x6c, 0x6f, 0x78, 0x21, 0x89, 0xff, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x4e, 0x53, 0x54, 0x17, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x06, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x50, 0x61, 0x72, 0x74, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x52, 0x4e, 0x54, 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x53, 0x49, 0x47, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x6c, 0x64, 0x65, 0x6e, 0x20, 0x77, 0x61, 0x73, 0x20, 0x68, 0x65, 0x72,
0x65, 0x45, 0x4e, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x2f, 0x72, 0x6f, 0x62, 0x6c, 0x6f, 0x78,
0x3e,
];
let _ = assets::v1::upload(
&mut client,
&[],
"",
"",
AssetTypeId::Model,
CreationContext {
creator: Creator::UserId(authenticated.id.to_string()),
expected_price: None,
},
)
.await;
let state = assets::v1::upload(
&mut client,
bytes,
"Test model",
"",
AssetTypeId::Model,
CreationContext {
creator: Creator::UserId(authenticated.id.to_string()),
expected_price: None,
},
)
.await
.unwrap();
let mut id = None;
while id == None {
let state = assets::v1::status(&mut client, &state.operation_id)
.await
.unwrap();
if let Some(ref r) = state.response {
id = Some(r.id.parse::<u64>().unwrap())
} else {
println!("sleeping until asset gets uploaded");
std::thread::sleep(Duration::from_secs(1));
}
}
let id = id.unwrap();
bytes[71..71 + 30].fill(0x00);
assets::v1::update(&mut client, id, bytes, "Test Model", "", AssetTypeId::Model)
.await
.unwrap();
println!("Updated model: {id}");
std::thread::sleep(Duration::from_secs(1));
develop::v1::revert_asset_version(&mut client, id, 1)
.await
.unwrap();
println!("Revert model: {id} to the first version");
let result = assets::v1::upload(
&mut client,
&[],
"test",
"",
AssetTypeId::Decal,
CreationContext {
creator: Creator::UserId(authenticated.id.to_string()),
expected_price: None,
},
)
.await
.unwrap();
println!("New asset status: {result:?}");
let asset_status = assets::v1::status(&mut client, &result.operation_id)
.await
.unwrap();
println!("Asset status: {asset_status:?}");
let assets = develop::v1::assets(&mut client, &[47433]).await.unwrap();
println!("Assets: {assets:?}");
}