use old api for download, error on http status #4
@ -37,22 +37,27 @@ pub struct UpdateAssetRequest{
|
|||||||
//woo nested roblox stuff
|
//woo nested roblox stuff
|
||||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||||
#[allow(nonstandard_style,dead_code)]
|
#[allow(nonstandard_style,dead_code)]
|
||||||
pub struct Creator{
|
pub enum Creator{
|
||||||
pub userId:u64,
|
userId(String),//u64 string
|
||||||
pub groupId:u64,
|
groupId(String),//u64 string
|
||||||
}
|
}
|
||||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||||
#[allow(nonstandard_style,dead_code)]
|
#[allow(nonstandard_style,dead_code)]
|
||||||
pub struct CreationContext{
|
pub struct CreationContext{
|
||||||
pub creator:Creator,
|
pub creator:Creator,
|
||||||
pub expectedPrice:u64,
|
pub expectedPrice:Option<u64>,
|
||||||
}
|
}
|
||||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||||
#[allow(nonstandard_style,dead_code)]
|
#[allow(nonstandard_style,dead_code)]
|
||||||
pub enum ModerationResult{
|
pub enum ModerationState{
|
||||||
MODERATION_STATE_REVIEWING,
|
Reviewing,
|
||||||
MODERATION_STATE_REJECTED,
|
Rejected,
|
||||||
MODERATION_STATE_APPROVED,
|
Approved,
|
||||||
|
}
|
||||||
|
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct ModerationResult{
|
||||||
|
pub moderationState:ModerationState,
|
||||||
}
|
}
|
||||||
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||||
#[allow(nonstandard_style,dead_code)]
|
#[allow(nonstandard_style,dead_code)]
|
||||||
@ -83,6 +88,51 @@ impl std::fmt::Display for UpdateError{
|
|||||||
}
|
}
|
||||||
impl std::error::Error for UpdateError{}
|
impl std::error::Error for UpdateError{}
|
||||||
|
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct GetAssetInfoRequest{
|
||||||
|
pub asset_id:u64,
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"assetId": "5692158972",
|
||||||
|
"assetType": "Model",
|
||||||
|
"creationContext":{
|
||||||
|
"creator":
|
||||||
|
{
|
||||||
|
"groupId": "6980477"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "DisplayName: Ares\nCreator: titanicguy54",
|
||||||
|
"displayName": "bhop_ares.rbxmx",
|
||||||
|
"path": "assets/5692158972",
|
||||||
|
"revisionCreateTime": "2020-09-14T16:08:05.063Z",
|
||||||
|
"revisionId": "1",
|
||||||
|
"moderationResult":{
|
||||||
|
"moderationState": "Approved"
|
||||||
|
},
|
||||||
|
"state": "Active"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
#[derive(Debug,serde::Deserialize,serde::Serialize)]
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct AssetResponse{
|
||||||
|
pub assetId:String,//u64 wrapped in quotes wohoo!!
|
||||||
|
pub assetType:AssetType,
|
||||||
|
pub creationContext:CreationContext,
|
||||||
|
pub description:String,
|
||||||
|
pub displayName:String,
|
||||||
|
pub path:String,
|
||||||
|
pub revisionCreateTime:chrono::DateTime<chrono::Utc>,
|
||||||
|
pub revisionId:String,//u64
|
||||||
|
pub moderationResult:ModerationResult,
|
||||||
|
pub icon:Option<String>,
|
||||||
|
pub previews:Option<Vec<Preview>>,
|
||||||
|
}
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct GetAssetVersionRequest{
|
||||||
|
pub asset_id:u64,
|
||||||
|
pub version:u64,
|
||||||
|
}
|
||||||
#[allow(nonstandard_style,dead_code)]
|
#[allow(nonstandard_style,dead_code)]
|
||||||
pub struct GetAssetRequest{
|
pub struct GetAssetRequest{
|
||||||
pub asset_id:u64,
|
pub asset_id:u64,
|
||||||
@ -278,17 +328,17 @@ impl CloudContext{
|
|||||||
|
|
||||||
Ok(resp.json::<RobloxOperation>().await.map_err(UpdateError::Reqwest)?)
|
Ok(resp.json::<RobloxOperation>().await.map_err(UpdateError::Reqwest)?)
|
||||||
}
|
}
|
||||||
pub async fn get_asset(&self,config:GetAssetRequest)->Result<Vec<u8>,GetError>{
|
pub async fn get_asset_info(&self,config:GetAssetInfoRequest)->Result<AssetResponse,GetError>{
|
||||||
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/").map_err(GetError::ParseError)?;
|
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}",config.asset_id);
|
||||||
//url borrow scope
|
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||||
{
|
|
||||||
let mut query=url.query_pairs_mut();//borrow here
|
Ok(self.get(url).await.map_err(GetError::Reqwest)?
|
||||||
query.append_pair("ID",config.asset_id.to_string().as_str());
|
.error_for_status().map_err(GetError::Reqwest)?
|
||||||
if let Some(version)=config.version{
|
.json::<AssetResponse>().await.map_err(GetError::Reqwest)?)
|
||||||
query.append_pair("version",version.to_string().as_str());
|
}
|
||||||
}
|
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 resp=self.get(url).await.map_err(GetError::Reqwest)?;
|
let url=reqwest::Url::parse(raw_url.as_str()).map_err(GetError::ParseError)?;
|
||||||
|
|
||||||
let body=self.get(url).await.map_err(GetError::Reqwest)?
|
let body=self.get(url).await.map_err(GetError::Reqwest)?
|
||||||
.error_for_status().map_err(GetError::Reqwest)?
|
.error_for_status().map_err(GetError::Reqwest)?
|
||||||
@ -300,6 +350,16 @@ impl CloudContext{
|
|||||||
Err(e)=>Err(e),
|
Err(e)=>Err(e),
|
||||||
}.map_err(GetError::IO)
|
}.map_err(GetError::IO)
|
||||||
}
|
}
|
||||||
|
pub async fn get_asset(&self,config:GetAssetRequest)->Result<Vec<u8>,GetError>{
|
||||||
|
let version=match config.version{
|
||||||
|
Some(version)=>version,
|
||||||
|
None=>self.get_asset_info(GetAssetInfoRequest{asset_id:config.asset_id}).await?.revisionId.parse().unwrap(),
|
||||||
|
};
|
||||||
|
self.get_asset_version(GetAssetVersionRequest{
|
||||||
|
asset_id:config.asset_id,
|
||||||
|
version,
|
||||||
|
}).await
|
||||||
|
}
|
||||||
pub async fn get_asset_versions(&self,config:AssetVersionsRequest)->Result<AssetVersionsResponse,AssetVersionsError>{
|
pub async fn get_asset_versions(&self,config:AssetVersionsRequest)->Result<AssetVersionsResponse,AssetVersionsError>{
|
||||||
let raw_url=format!("https://apis.roblox.com/assets/v1/assets/{}/versions",config.asset_id);
|
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)?;
|
let url=reqwest::Url::parse(raw_url.as_str()).map_err(AssetVersionsError::ParseError)?;
|
||||||
|
25
src/main.rs
25
src/main.rs
@ -1,6 +1,6 @@
|
|||||||
use std::{io::Read,path::PathBuf};
|
use std::{io::Read,path::PathBuf};
|
||||||
use clap::{Args,Parser,Subcommand};
|
use clap::{Args,Parser,Subcommand};
|
||||||
use anyhow::Result as AResult;
|
use anyhow::{anyhow,Result as AResult};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use rbx_asset::cloud::{ApiKey,CloudContext};
|
use rbx_asset::cloud::{ApiKey,CloudContext};
|
||||||
use rbx_asset::cookie::{Cookie,CookieContext,AssetVersion,InventoryItem};
|
use rbx_asset::cookie::{Cookie,CookieContext,AssetVersion,InventoryItem};
|
||||||
@ -119,9 +119,9 @@ struct CreateAssetMediaSubcommand{
|
|||||||
input_file:PathBuf,
|
input_file:PathBuf,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
asset_type:AssetType,
|
asset_type:AssetType,
|
||||||
#[arg(long)]
|
#[arg(long,group="creator",required=true)]
|
||||||
creator_user_id:u64,
|
creator_user_id:Option<u64>,
|
||||||
#[arg(long)]
|
#[arg(long,group="creator",required=true)]
|
||||||
creator_group_id:Option<u64>,
|
creator_group_id:Option<u64>,
|
||||||
/// Expected price limits how much robux can be spent to create the asset (defaults to 0)
|
/// Expected price limits how much robux can be spent to create the asset (defaults to 0)
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
@ -413,8 +413,11 @@ async fn main()->AResult<()>{
|
|||||||
subcommand.api_key_envvar,
|
subcommand.api_key_envvar,
|
||||||
subcommand.api_key_file,
|
subcommand.api_key_file,
|
||||||
).await?,
|
).await?,
|
||||||
creator_user_id:subcommand.creator_user_id,
|
creator:match (subcommand.creator_user_id,subcommand.creator_group_id){
|
||||||
creator_group_id:subcommand.creator_group_id,
|
(Some(user_id),None)=>rbx_asset::cloud::Creator::userId(user_id.to_string()),
|
||||||
|
(None,Some(group_id))=>rbx_asset::cloud::Creator::groupId(group_id.to_string()),
|
||||||
|
other=>Err(anyhow!("Invalid creator {other:?}"))?,
|
||||||
|
},
|
||||||
input_file:subcommand.input_file,
|
input_file:subcommand.input_file,
|
||||||
asset_type:subcommand.asset_type.cloud(),
|
asset_type:subcommand.asset_type.cloud(),
|
||||||
model_name:subcommand.model_name,
|
model_name:subcommand.model_name,
|
||||||
@ -568,8 +571,7 @@ struct CreateAssetMediaConfig{
|
|||||||
model_name:String,
|
model_name:String,
|
||||||
description:String,
|
description:String,
|
||||||
input_file:PathBuf,
|
input_file:PathBuf,
|
||||||
creator_user_id:u64,
|
creator:rbx_asset::cloud::Creator,
|
||||||
creator_group_id:Option<u64>,
|
|
||||||
expected_price:Option<u64>,
|
expected_price:Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,11 +582,8 @@ async fn create_asset_media(config:CreateAssetMediaConfig)->AResult<()>{
|
|||||||
displayName:config.model_name,
|
displayName:config.model_name,
|
||||||
description:config.description,
|
description:config.description,
|
||||||
creationContext:rbx_asset::cloud::CreationContext{
|
creationContext:rbx_asset::cloud::CreationContext{
|
||||||
creator:rbx_asset::cloud::Creator{
|
creator:config.creator,
|
||||||
userId:config.creator_user_id,
|
expectedPrice:Some(config.expected_price.unwrap_or(0)),
|
||||||
groupId:config.creator_group_id.unwrap_or(0),
|
|
||||||
},
|
|
||||||
expectedPrice:config.expected_price.unwrap_or(0),
|
|
||||||
}
|
}
|
||||||
},tokio::fs::read(config.input_file).await?).await?;
|
},tokio::fs::read(config.input_file).await?).await?;
|
||||||
println!("CreateResponse={:?}",resp);
|
println!("CreateResponse={:?}",resp);
|
||||||
|
Loading…
Reference in New Issue
Block a user