Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
4ffeaa5784 | |||
607f964928 | |||
8dc7c96f2d | |||
68d751f81f | |||
c2052be036 | |||
2e9485dea6 |
731
Cargo.lock
generated
731
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
workspace = { members = ["rbx_asset", "rox_compiler"] }
|
||||
[package]
|
||||
name = "asset-tool"
|
||||
version = "0.4.8"
|
||||
version = "0.4.7"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rbx_asset"
|
||||
version = "0.2.5"
|
||||
version = "0.2.3"
|
||||
edition = "2021"
|
||||
publish = ["strafesnet"]
|
||||
repository = "https://git.itzana.me/StrafesNET/asset-tool"
|
||||
|
@ -1,5 +1,3 @@
|
||||
use crate::ResponseError;
|
||||
|
||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||
#[allow(nonstandard_style,dead_code)]
|
||||
pub enum AssetType{
|
||||
@ -42,7 +40,6 @@ impl AssetOperation{
|
||||
#[derive(Debug)]
|
||||
pub enum CreateError{
|
||||
Parse(url::ParseError),
|
||||
Response(ResponseError),
|
||||
Serialize(serde_json::Error),
|
||||
Reqwest(reqwest::Error),
|
||||
}
|
||||
@ -105,7 +102,6 @@ pub struct UpdatePlaceResponse{
|
||||
#[derive(Debug)]
|
||||
pub enum UpdateError{
|
||||
ParseError(url::ParseError),
|
||||
Response(ResponseError),
|
||||
SerializeError(serde_json::Error),
|
||||
Reqwest(reqwest::Error),
|
||||
}
|
||||
@ -171,7 +167,6 @@ pub struct GetAssetRequest{
|
||||
#[derive(Debug)]
|
||||
pub enum GetError{
|
||||
ParseError(url::ParseError),
|
||||
Response(ResponseError),
|
||||
Reqwest(reqwest::Error),
|
||||
IO(std::io::Error)
|
||||
}
|
||||
@ -208,7 +203,6 @@ pub struct AssetVersionsResponse{
|
||||
#[derive(Debug)]
|
||||
pub enum AssetVersionsError{
|
||||
ParseError(url::ParseError),
|
||||
Response(ResponseError),
|
||||
Reqwest(reqwest::Error),
|
||||
}
|
||||
impl std::fmt::Display for AssetVersionsError{
|
||||
@ -244,7 +238,6 @@ pub struct InventoryPageResponse{
|
||||
#[derive(Debug)]
|
||||
pub enum InventoryPageError{
|
||||
ParseError(url::ParseError),
|
||||
Response(ResponseError),
|
||||
Reqwest(reqwest::Error),
|
||||
}
|
||||
impl std::fmt::Display for InventoryPageError{
|
||||
@ -375,9 +368,9 @@ impl CloudContext{
|
||||
.text("request",request_config)
|
||||
.part("fileContent",part);
|
||||
|
||||
let operation=crate::response_ok(
|
||||
self.post_form(url,form).await.map_err(CreateError::Reqwest)?
|
||||
).await.map_err(CreateError::Response)?
|
||||
let operation=self.post_form(url,form).await
|
||||
.map_err(CreateError::Reqwest)?
|
||||
.error_for_status().map_err(CreateError::Reqwest)?
|
||||
.json::<RobloxOperation>().await.map_err(CreateError::Reqwest)?;
|
||||
|
||||
Ok(AssetOperation{
|
||||
@ -394,9 +387,10 @@ impl CloudContext{
|
||||
.text("request",request_config)
|
||||
.part("fileContent",reqwest::multipart::Part::bytes(body));
|
||||
|
||||
let operation=crate::response_ok(
|
||||
self.patch_form(url,form).await.map_err(UpdateError::Reqwest)?
|
||||
).await.map_err(UpdateError::Response)?
|
||||
let operation=self.patch_form(url,form).await
|
||||
.map_err(UpdateError::Reqwest)?
|
||||
//roblox api documentation is very poor, just give the status code and drop the json
|
||||
.error_for_status().map_err(UpdateError::Reqwest)?
|
||||
.json::<RobloxOperation>().await.map_err(UpdateError::Reqwest)?;
|
||||
|
||||
Ok(AssetOperation{
|
||||
@ -407,27 +401,24 @@ impl CloudContext{
|
||||
let raw_url=format!("https://apis.roblox.com/assets/v1/operations/{}",config.operation_id);
|
||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||
|
||||
crate::response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
.error_for_status().map_err(GetError::Reqwest)?
|
||||
.json::<RobloxOperation>().await.map_err(GetError::Reqwest)
|
||||
}
|
||||
pub async fn get_asset_info(&self,config:GetAssetInfoRequest)->Result<AssetResponse,GetError>{
|
||||
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}",config.asset_id);
|
||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||
|
||||
crate::response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
.error_for_status().map_err(GetError::Reqwest)?
|
||||
.json::<AssetResponse>().await.map_err(GetError::Reqwest)
|
||||
}
|
||||
pub async fn get_asset_version(&self,config:GetAssetVersionRequest)->Result<Vec<u8>,GetError>{
|
||||
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}/versions/{}",config.asset_id,config.version);
|
||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||
|
||||
let body=crate::response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
let body=self.get(url).await.map_err(GetError::Reqwest)?
|
||||
.error_for_status().map_err(GetError::Reqwest)?
|
||||
.bytes().await.map_err(GetError::Reqwest)?;
|
||||
|
||||
match maybe_gzip_decode(&mut std::io::Cursor::new(body)){
|
||||
@ -450,9 +441,8 @@ impl CloudContext{
|
||||
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}/versions",config.asset_id);
|
||||
let url=reqwest::Url::parse(raw_url.as_str()).map_err(AssetVersionsError::ParseError)?;
|
||||
|
||||
crate::response_ok(
|
||||
self.get(url).await.map_err(AssetVersionsError::Reqwest)?
|
||||
).await.map_err(AssetVersionsError::Response)?
|
||||
self.get(url).await.map_err(AssetVersionsError::Reqwest)?
|
||||
.error_for_status().map_err(AssetVersionsError::Reqwest)?
|
||||
.json::<AssetVersionsResponse>().await.map_err(AssetVersionsError::Reqwest)
|
||||
}
|
||||
pub async fn inventory_page(&self,config:InventoryPageRequest)->Result<InventoryPageResponse,InventoryPageError>{
|
||||
@ -465,9 +455,8 @@ impl CloudContext{
|
||||
}
|
||||
}
|
||||
|
||||
crate::response_ok(
|
||||
self.get(url).await.map_err(InventoryPageError::Reqwest)?
|
||||
).await.map_err(InventoryPageError::Response)?
|
||||
self.get(url).await.map_err(InventoryPageError::Reqwest)?
|
||||
.error_for_status().map_err(InventoryPageError::Reqwest)?
|
||||
.json::<InventoryPageResponse>().await.map_err(InventoryPageError::Reqwest)
|
||||
}
|
||||
pub async fn update_place(&self,config:UpdatePlaceRequest,body:impl Into<reqwest::Body>+Clone)->Result<UpdatePlaceResponse,UpdateError>{
|
||||
@ -479,9 +468,8 @@ impl CloudContext{
|
||||
query.append_pair("versionType","Published");
|
||||
}
|
||||
|
||||
crate::response_ok(
|
||||
self.post(url,body).await.map_err(UpdateError::Reqwest)?
|
||||
).await.map_err(UpdateError::Response)?
|
||||
self.post(url,body).await.map_err(UpdateError::Reqwest)?
|
||||
.error_for_status().map_err(UpdateError::Reqwest)?
|
||||
.json::<UpdatePlaceResponse>().await.map_err(UpdateError::Reqwest)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
use crate::ResponseError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PostError{
|
||||
Reqwest(reqwest::Error),
|
||||
@ -25,7 +23,6 @@ pub struct CreateRequest{
|
||||
pub enum CreateError{
|
||||
ParseError(url::ParseError),
|
||||
PostError(PostError),
|
||||
Response(ResponseError),
|
||||
Reqwest(reqwest::Error),
|
||||
}
|
||||
impl std::fmt::Display for CreateError{
|
||||
@ -49,7 +46,6 @@ pub enum UploadError{
|
||||
ParseError(url::ParseError),
|
||||
PostError(PostError),
|
||||
Reqwest(reqwest::Error),
|
||||
Response(ResponseError),
|
||||
AssetIdIsZero,
|
||||
}
|
||||
impl std::fmt::Display for UploadError{
|
||||
@ -58,11 +54,11 @@ impl std::fmt::Display for UploadError{
|
||||
}
|
||||
}
|
||||
impl std::error::Error for UploadError{}
|
||||
type RobloxUploadResponse=u64;
|
||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||
#[allow(nonstandard_style,dead_code)]
|
||||
pub struct UploadResponse{
|
||||
pub AssetId:u64,
|
||||
pub AssetVersionId:u64,
|
||||
}
|
||||
|
||||
#[allow(nonstandard_style,dead_code)]
|
||||
@ -73,7 +69,6 @@ pub struct GetAssetRequest{
|
||||
#[derive(Debug)]
|
||||
pub enum GetError{
|
||||
ParseError(url::ParseError),
|
||||
Response(ResponseError),
|
||||
Reqwest(reqwest::Error),
|
||||
IO(std::io::Error)
|
||||
}
|
||||
@ -110,7 +105,6 @@ pub struct AssetVersionsPageResponse{
|
||||
#[derive(Debug)]
|
||||
pub enum PageError{
|
||||
ParseError(url::ParseError),
|
||||
Response(ResponseError),
|
||||
Reqwest(reqwest::Error),
|
||||
}
|
||||
impl std::fmt::Display for PageError{
|
||||
@ -210,9 +204,8 @@ fn read_readable(mut readable:impl std::io::Read)->std::io::Result<Vec<u8>>{
|
||||
#[derive(Clone)]
|
||||
pub struct Cookie(String);
|
||||
impl Cookie{
|
||||
/// cookie is prepended with ".ROBLOSECURITY=" by this function
|
||||
pub fn new(cookie:String)->Self{
|
||||
Self(format!(".ROBLOSECURITY={cookie}"))
|
||||
Self(cookie)
|
||||
}
|
||||
pub fn get(self)->String{
|
||||
self.0
|
||||
@ -272,14 +265,10 @@ impl CookieContext{
|
||||
query.append_pair("groupId",group_id.to_string().as_str());
|
||||
}
|
||||
}
|
||||
let asset_id=crate::response_ok(
|
||||
self.post(url,body).await.map_err(CreateError::PostError)?
|
||||
).await.map_err(CreateError::Response)?
|
||||
.json::<RobloxUploadResponse>().await.map_err(CreateError::Reqwest)?;
|
||||
|
||||
Ok(UploadResponse{
|
||||
AssetId:asset_id,
|
||||
})
|
||||
self.post(url,body).await.map_err(CreateError::PostError)?
|
||||
.error_for_status().map_err(CreateError::Reqwest)?
|
||||
.json::<UploadResponse>().await.map_err(CreateError::Reqwest)
|
||||
}
|
||||
pub async fn upload(&self,config:UploadRequest,body:impl Into<reqwest::Body>+Clone)->Result<UploadResponse,UploadError>{
|
||||
let mut url=reqwest::Url::parse("https://data.roblox.com/Data/Upload.ashx?json=1&type=Model&genreTypeId=1").map_err(UploadError::ParseError)?;
|
||||
@ -307,14 +296,10 @@ impl CookieContext{
|
||||
query.append_pair("groupId",group_id.to_string().as_str());
|
||||
}
|
||||
}
|
||||
let asset_id=crate::response_ok(
|
||||
self.post(url,body).await.map_err(UploadError::PostError)?
|
||||
).await.map_err(UploadError::Response)?
|
||||
.json::<RobloxUploadResponse>().await.map_err(UploadError::Reqwest)?;
|
||||
|
||||
Ok(UploadResponse{
|
||||
AssetId:asset_id,
|
||||
})
|
||||
self.post(url,body).await.map_err(UploadError::PostError)?
|
||||
.error_for_status().map_err(UploadError::Reqwest)?
|
||||
.json::<UploadResponse>().await.map_err(UploadError::Reqwest)
|
||||
}
|
||||
pub async fn get_asset(&self,config:GetAssetRequest)->Result<Vec<u8>,GetError>{
|
||||
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/").map_err(GetError::ParseError)?;
|
||||
@ -326,9 +311,8 @@ impl CookieContext{
|
||||
query.append_pair("version",version.to_string().as_str());
|
||||
}
|
||||
}
|
||||
let body=crate::response_ok(
|
||||
self.get(url).await.map_err(GetError::Reqwest)?
|
||||
).await.map_err(GetError::Response)?
|
||||
let body=self.get(url).await.map_err(GetError::Reqwest)?
|
||||
.error_for_status().map_err(GetError::Reqwest)?
|
||||
.bytes().await.map_err(GetError::Reqwest)?;
|
||||
|
||||
match maybe_gzip_decode(&mut std::io::Cursor::new(body)){
|
||||
@ -349,9 +333,9 @@ impl CookieContext{
|
||||
query.append_pair("cursor",cursor);
|
||||
}
|
||||
}
|
||||
crate::response_ok(
|
||||
self.get(url).await.map_err(PageError::Reqwest)?
|
||||
).await.map_err(PageError::Response)?
|
||||
|
||||
self.get(url).await.map_err(PageError::Reqwest)?
|
||||
.error_for_status().map_err(PageError::Reqwest)?
|
||||
.json::<AssetVersionsPageResponse>().await.map_err(PageError::Reqwest)
|
||||
}
|
||||
pub async fn get_creations_page(&self,config:&CreationsPageRequest)->Result<CreationsPageResponse,PageError>{
|
||||
@ -364,9 +348,9 @@ impl CookieContext{
|
||||
query.append_pair("cursor",cursor);
|
||||
}
|
||||
}
|
||||
crate::response_ok(
|
||||
self.get(url).await.map_err(PageError::Reqwest)?
|
||||
).await.map_err(PageError::Response)?
|
||||
|
||||
self.get(url).await.map_err(PageError::Reqwest)?
|
||||
.error_for_status().map_err(PageError::Reqwest)?
|
||||
.json::<CreationsPageResponse>().await.map_err(PageError::Reqwest)
|
||||
}
|
||||
pub async fn get_user_inventory_page(&self,config:&UserInventoryPageRequest)->Result<UserInventoryPageResponse,PageError>{
|
||||
@ -378,9 +362,9 @@ impl CookieContext{
|
||||
query.append_pair("cursor",cursor);
|
||||
}
|
||||
}
|
||||
crate::response_ok(
|
||||
self.get(url).await.map_err(PageError::Reqwest)?
|
||||
).await.map_err(PageError::Response)?
|
||||
|
||||
self.get(url).await.map_err(PageError::Reqwest)?
|
||||
.error_for_status().map_err(PageError::Reqwest)?
|
||||
.json::<UserInventoryPageResponse>().await.map_err(PageError::Reqwest)
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,2 @@
|
||||
pub mod cloud;
|
||||
pub mod cookie;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub struct StatusCodeWithUrlAndBody{
|
||||
pub status_code:reqwest::StatusCode,
|
||||
pub url:url::Url,
|
||||
pub body:String,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum ResponseError{
|
||||
Reqwest(reqwest::Error),
|
||||
StatusCodeWithUrlAndBody(StatusCodeWithUrlAndBody),
|
||||
}
|
||||
impl std::fmt::Display for ResponseError{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ResponseError{}
|
||||
// lazy function to draw out meaningful info from http response on failure
|
||||
pub async fn response_ok(response:reqwest::Response)->Result<reqwest::Response,ResponseError>{
|
||||
let status_code=response.status();
|
||||
if status_code.is_success(){
|
||||
Ok(response)
|
||||
}else{
|
||||
let url=response.url().to_owned();
|
||||
let bytes=response.bytes().await.map_err(ResponseError::Reqwest)?;
|
||||
let body=String::from_utf8_lossy(&bytes).to_string();
|
||||
Err(ResponseError::StatusCodeWithUrlAndBody(StatusCodeWithUrlAndBody{
|
||||
status_code,
|
||||
url,
|
||||
body,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -621,7 +621,7 @@ async fn cookie_from_args(literal:Option<String>,environment:Option<String>,file
|
||||
(None,None,Some(cookie_file))=>tokio::fs::read_to_string(cookie_file).await?,
|
||||
_=>Err(anyhow::Error::msg("Illegal cookie argument triple"))?,
|
||||
};
|
||||
Ok(Cookie::new(cookie))
|
||||
Ok(Cookie::new(format!(".ROBLOSECURITY={cookie}")))
|
||||
}
|
||||
async fn api_key_from_args(literal:Option<String>,environment:Option<String>,file:Option<PathBuf>)->AResult<ApiKey>{
|
||||
let api_key=match (literal,environment,file){
|
||||
|
Loading…
Reference in New Issue
Block a user