forked from StrafesNET/asset-tool
builds
This commit is contained in:
parent
cc7e445498
commit
d53efd7441
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1166,7 +1166,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rbx_asset"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"flate2",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rbx_asset"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
publish = ["strafesnet"]
|
||||
|
||||
|
@ -103,17 +103,17 @@ pub struct GetAssetRequest{
|
||||
pub version:Option<u64>,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum DownloadError{
|
||||
pub enum GetError{
|
||||
ParseError(url::ParseError),
|
||||
Reqwest(reqwest::Error),
|
||||
IO(std::io::Error)
|
||||
}
|
||||
impl std::fmt::Display for DownloadError{
|
||||
impl std::fmt::Display for GetError{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for DownloadError{}
|
||||
impl std::error::Error for GetError{}
|
||||
|
||||
pub struct AssetVersionsRequest{
|
||||
pub asset_id:u64,
|
||||
@ -267,8 +267,8 @@ impl RobloxContext{
|
||||
|
||||
Ok(resp.json::<AssetResponse>().await.map_err(UpdateError::Reqwest)?)
|
||||
}
|
||||
pub async fn get_asset(&self,config:GetAssetRequest)->Result<Vec<u8>,DownloadError>{
|
||||
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/").map_err(DownloadError::ParseError)?;
|
||||
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)?;
|
||||
//url borrow scope
|
||||
{
|
||||
let mut query=url.query_pairs_mut();//borrow here
|
||||
@ -277,15 +277,15 @@ impl RobloxContext{
|
||||
query.append_pair("version",version.to_string().as_str());
|
||||
}
|
||||
}
|
||||
let resp=self.get(url).await.map_err(DownloadError::Reqwest)?;
|
||||
let resp=self.get(url).await.map_err(GetError::Reqwest)?;
|
||||
|
||||
let body=resp.bytes().await.map_err(DownloadError::Reqwest)?;
|
||||
let body=resp.bytes().await.map_err(GetError::Reqwest)?;
|
||||
|
||||
match maybe_gzip_decode(&mut std::io::Cursor::new(body)){
|
||||
Ok(ReaderType::GZip(readable))=>read_readable(readable),
|
||||
Ok(ReaderType::Raw(readable))=>read_readable(readable),
|
||||
Err(e)=>Err(e),
|
||||
}.map_err(DownloadError::IO)
|
||||
}.map_err(GetError::IO)
|
||||
}
|
||||
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);
|
||||
|
358
src/main.rs
358
src/main.rs
@ -25,8 +25,10 @@ enum Commands{
|
||||
DownloadGroupInventoryJson(DownloadGroupInventoryJsonSubcommand),
|
||||
CreateAsset(CreateAssetSubcommand),
|
||||
UploadAsset(UpdateAssetSubcommand),
|
||||
UploadPlace(UpdatePlaceSubcommand),
|
||||
Compile(CompileSubcommand),
|
||||
CompileUpload(CompileUploadSubcommand),
|
||||
CompileUploadAsset(CompileUploadAssetSubcommand),
|
||||
CompileUploadPlace(CompileUploadPlaceSubcommand),
|
||||
Decompile(DecompileSubcommand),
|
||||
DecompileHistoryIntoGit(DecompileHistoryIntoGitSubcommand),
|
||||
DownloadAndDecompileHistoryIntoGit(DownloadAndDecompileHistoryIntoGitSubcommand),
|
||||
@ -36,10 +38,12 @@ enum Commands{
|
||||
struct DownloadHistorySubcommand{
|
||||
#[arg(long)]
|
||||
asset_id:AssetID,
|
||||
#[arg(long)]
|
||||
cookie_type:CookieType,
|
||||
#[arg(long)]
|
||||
cookie:String,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_envvar:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
output_folder:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
@ -51,10 +55,12 @@ struct DownloadHistorySubcommand{
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct DownloadSubcommand{
|
||||
#[arg(long)]
|
||||
cookie_type:CookieType,
|
||||
#[arg(long)]
|
||||
cookie:String,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_envvar:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
output_folder:Option<PathBuf>,
|
||||
#[arg(required=true)]
|
||||
@ -62,10 +68,12 @@ struct DownloadSubcommand{
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct DownloadGroupInventoryJsonSubcommand{
|
||||
#[arg(long)]
|
||||
cookie_type:CookieType,
|
||||
#[arg(long)]
|
||||
cookie:String,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_envvar:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
output_folder:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
@ -73,10 +81,12 @@ struct DownloadGroupInventoryJsonSubcommand{
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct CreateAssetSubcommand{
|
||||
#[arg(long)]
|
||||
cookie_type:CookieType,
|
||||
#[arg(long)]
|
||||
cookie:String,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_envvar:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
model_name:String,
|
||||
#[arg(long)]
|
||||
@ -85,19 +95,32 @@ struct CreateAssetSubcommand{
|
||||
input_file:PathBuf,
|
||||
#[arg(long)]
|
||||
group:Option<u64>,
|
||||
#[arg(long)]
|
||||
free_model:Option<bool>,
|
||||
#[arg(long)]
|
||||
allow_comments:Option<bool>,
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct UpdateAssetSubcommand{
|
||||
#[arg(long)]
|
||||
asset_id:AssetID,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_envvar:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
cookie_type:CookieType,
|
||||
input_file:PathBuf,
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct UpdatePlaceSubcommand{
|
||||
#[arg(long)]
|
||||
cookie:String,
|
||||
place_id:u64,
|
||||
#[arg(long)]
|
||||
universe_id:u64,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_envvar:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
input_file:PathBuf,
|
||||
}
|
||||
@ -113,17 +136,38 @@ struct CompileSubcommand{
|
||||
template:Option<PathBuf>,
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct CompileUploadSubcommand{
|
||||
struct CompileUploadAssetSubcommand{
|
||||
#[arg(long)]
|
||||
asset_id:AssetID,
|
||||
#[arg(long)]
|
||||
cookie_type:CookieType,
|
||||
#[arg(long)]
|
||||
cookie:String,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_envvar:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
input_file:PathBuf,
|
||||
#[arg(long)]
|
||||
group:Option<u64>,
|
||||
input_folder:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
style:Option<Style>,
|
||||
#[arg(long)]
|
||||
template:Option<PathBuf>,
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct CompileUploadPlaceSubcommand{
|
||||
#[arg(long)]
|
||||
place_id:u64,
|
||||
#[arg(long)]
|
||||
universe_id:u64,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_envvar:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
input_file:PathBuf,
|
||||
#[arg(long)]
|
||||
input_folder:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
@ -148,10 +192,12 @@ struct DecompileSubcommand{
|
||||
}
|
||||
#[derive(Args)]
|
||||
struct DownloadDecompileSubcommand{
|
||||
#[arg(long)]
|
||||
cookie_type:CookieType,
|
||||
#[arg(long)]
|
||||
cookie:String,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_envvar:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_file:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
output_folder:Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
@ -188,10 +234,12 @@ struct DecompileHistoryIntoGitSubcommand{
|
||||
struct DownloadAndDecompileHistoryIntoGitSubcommand{
|
||||
#[arg(long)]
|
||||
asset_id:AssetID,
|
||||
#[arg(long)]
|
||||
cookie_type:CookieType,
|
||||
#[arg(long)]
|
||||
cookie:String,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_literal:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_envvar:Option<String>,
|
||||
#[arg(long,group="api_key",required=true)]
|
||||
api_key_file:Option<PathBuf>,
|
||||
//currently output folder must be the current folder due to git2 limitations
|
||||
//output_folder:cli.output.unwrap(),
|
||||
#[arg(long)]
|
||||
@ -208,16 +256,6 @@ struct DownloadAndDecompileHistoryIntoGitSubcommand{
|
||||
write_scripts:Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone,clap::ValueEnum)]
|
||||
enum ApiKeyLocation{
|
||||
///String literal
|
||||
Literal,
|
||||
///Read an environment variable
|
||||
Environment,
|
||||
///Read a file
|
||||
File,
|
||||
}
|
||||
|
||||
#[derive(Clone,Copy,Debug,clap::ValueEnum)]
|
||||
enum Style{
|
||||
Rox,
|
||||
@ -243,13 +281,21 @@ async fn main()->AResult<()>{
|
||||
end_version:subcommand.end_version,
|
||||
start_version:subcommand.start_version.unwrap_or(0),
|
||||
output_folder:subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
|
||||
cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
||||
api_key:ApiKey::from_args(
|
||||
subcommand.api_key_literal,
|
||||
subcommand.api_key_envvar,
|
||||
subcommand.api_key_file,
|
||||
).await?.get(),
|
||||
asset_id:subcommand.asset_id,
|
||||
}).await,
|
||||
Commands::Download(subcommand)=>{
|
||||
let output_folder=subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap());
|
||||
download_list(
|
||||
Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
||||
ApiKey::from_args(
|
||||
subcommand.api_key_literal,
|
||||
subcommand.api_key_envvar,
|
||||
subcommand.api_key_file,
|
||||
).await?.get(),
|
||||
subcommand.asset_ids.into_iter().map(|asset_id|{
|
||||
let mut path=output_folder.clone();
|
||||
path.push(asset_id.to_string());
|
||||
@ -259,7 +305,11 @@ async fn main()->AResult<()>{
|
||||
},
|
||||
Commands::DownloadDecompile(subcommand)=>{
|
||||
download_decompile(DownloadDecompileConfig{
|
||||
cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
||||
api_key:ApiKey::from_args(
|
||||
subcommand.api_key_literal,
|
||||
subcommand.api_key_envvar,
|
||||
subcommand.api_key_file,
|
||||
).await?.get(),
|
||||
asset_id:subcommand.asset_id,
|
||||
output_folder:subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
|
||||
style:subcommand.style.rox(),
|
||||
@ -269,37 +319,73 @@ async fn main()->AResult<()>{
|
||||
}).await
|
||||
},
|
||||
Commands::DownloadGroupInventoryJson(subcommand)=>download_group_inventory_json(
|
||||
Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
||||
ApiKey::from_args(
|
||||
subcommand.api_key_literal,
|
||||
subcommand.api_key_envvar,
|
||||
subcommand.api_key_file,
|
||||
).await?.get(),
|
||||
subcommand.group,
|
||||
subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
|
||||
).await,
|
||||
Commands::CreateAsset(subcommand)=>create(CreateConfig{
|
||||
cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
||||
api_key:ApiKey::from_args(
|
||||
subcommand.api_key_literal,
|
||||
subcommand.api_key_envvar,
|
||||
subcommand.api_key_file,
|
||||
).await?.get(),
|
||||
group:subcommand.group,
|
||||
input_file:subcommand.input_file,
|
||||
model_name:subcommand.model_name,
|
||||
description:subcommand.description.unwrap_or_else(||String::with_capacity(0)),
|
||||
free_model:subcommand.free_model.unwrap_or(false),
|
||||
allow_comments:subcommand.allow_comments.unwrap_or(false),
|
||||
}).await,
|
||||
Commands::UploadAsset(subcommand)=>upload_list(
|
||||
Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
||||
vec![(subcommand.asset_id,subcommand.input_file)]
|
||||
).await,
|
||||
Commands::UploadAsset(subcommand)=>upload_asset(UploadAssetConfig{
|
||||
api_key:ApiKey::from_args(
|
||||
subcommand.api_key_literal,
|
||||
subcommand.api_key_envvar,
|
||||
subcommand.api_key_file,
|
||||
).await?.get(),
|
||||
asset_id:subcommand.asset_id,
|
||||
input_file:subcommand.input_file,
|
||||
}).await,
|
||||
Commands::UploadPlace(subcommand)=>upload_place(UploadPlaceConfig{
|
||||
api_key:ApiKey::from_args(
|
||||
subcommand.api_key_literal,
|
||||
subcommand.api_key_envvar,
|
||||
subcommand.api_key_file,
|
||||
).await?.get(),
|
||||
place_id:subcommand.place_id,
|
||||
universe_id:subcommand.universe_id,
|
||||
input_file:subcommand.input_file,
|
||||
}).await,
|
||||
Commands::Compile(subcommand)=>compile(CompileConfig{
|
||||
input_folder:subcommand.input_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
|
||||
output_file:subcommand.output_file,
|
||||
template:subcommand.template,
|
||||
style:subcommand.style.map(|s|s.rox()),
|
||||
}).await,
|
||||
Commands::CompileUpload(subcommand)=>compile_upload(CompileUploadConfig{
|
||||
Commands::CompileUploadAsset(subcommand)=>compile_upload_asset(CompileUploadAssetConfig{
|
||||
input_folder:subcommand.input_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
|
||||
template:subcommand.template,
|
||||
style:subcommand.style.map(|s|s.rox()),
|
||||
cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
||||
group:subcommand.group,
|
||||
api_key:ApiKey::from_args(
|
||||
subcommand.api_key_literal,
|
||||
subcommand.api_key_envvar,
|
||||
subcommand.api_key_file,
|
||||
).await?.get(),
|
||||
asset_id:subcommand.asset_id,
|
||||
}).await,
|
||||
Commands::CompileUploadPlace(subcommand)=>compile_upload_place(CompileUploadPlaceConfig{
|
||||
input_folder:subcommand.input_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
|
||||
template:subcommand.template,
|
||||
style:subcommand.style.map(|s|s.rox()),
|
||||
api_key:ApiKey::from_args(
|
||||
subcommand.api_key_literal,
|
||||
subcommand.api_key_envvar,
|
||||
subcommand.api_key_file,
|
||||
).await?.get(),
|
||||
place_id:subcommand.place_id,
|
||||
universe_id:subcommand.universe_id,
|
||||
}).await,
|
||||
Commands::Decompile(subcommand)=>decompile(DecompileConfig{
|
||||
style:subcommand.style.rox(),
|
||||
input_file:subcommand.input_file,
|
||||
@ -321,7 +407,11 @@ async fn main()->AResult<()>{
|
||||
Commands::DownloadAndDecompileHistoryIntoGit(subcommand)=>download_and_decompile_history_into_git(DownloadAndDecompileHistoryConfig{
|
||||
git_committer_name:subcommand.git_committer_name,
|
||||
git_committer_email:subcommand.git_committer_email,
|
||||
cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
|
||||
api_key:ApiKey::from_args(
|
||||
subcommand.api_key_literal,
|
||||
subcommand.api_key_envvar,
|
||||
subcommand.api_key_file,
|
||||
).await?.get(),
|
||||
asset_id:subcommand.asset_id,
|
||||
output_folder:std::env::current_dir()?,
|
||||
style:subcommand.style.rox(),
|
||||
@ -332,30 +422,33 @@ async fn main()->AResult<()>{
|
||||
}
|
||||
}
|
||||
|
||||
struct Cookie(String);
|
||||
impl Cookie{
|
||||
async fn from_type(cookie_type:CookieType,cookie_string:String)->AResult<Self>{
|
||||
Ok(Self(format!(".ROBLOSECURITY={}",match cookie_type{
|
||||
CookieType::Literal=>cookie_string,
|
||||
CookieType::Environment=>std::env::var(cookie_string)?,
|
||||
CookieType::File=>tokio::fs::read_to_string(cookie_string).await?,
|
||||
})))
|
||||
struct ApiKey(String);
|
||||
impl ApiKey{
|
||||
fn get(self)->String{
|
||||
self.0
|
||||
}
|
||||
async fn from_args(literal:Option<String>,environment:Option<String>,file:Option<PathBuf>)->AResult<Self>{
|
||||
let api_key=match (literal,environment,file){
|
||||
(Some(api_key_literal),None,None)=>api_key_literal,
|
||||
(None,Some(api_key_environment),None)=>std::env::var(api_key_environment)?,
|
||||
(None,None,Some(api_key_file))=>tokio::fs::read_to_string(api_key_file).await?,
|
||||
_=>Err(anyhow::Error::msg("Illegal api key argument triple"))?,
|
||||
};
|
||||
Ok(Self(api_key))
|
||||
}
|
||||
}
|
||||
|
||||
struct CreateConfig{
|
||||
cookie:String,
|
||||
api_key:String,
|
||||
model_name:String,
|
||||
description:String,
|
||||
input_file:PathBuf,
|
||||
group:Option<u64>,
|
||||
free_model:bool,
|
||||
allow_comments:bool,
|
||||
}
|
||||
|
||||
///This is hardcoded to create models atm
|
||||
async fn create(config:CreateConfig)->AResult<()>{
|
||||
let resp=RobloxContext::new(config.cookie)
|
||||
let resp=RobloxContext::new(config.api_key)
|
||||
.create_asset(rbx_asset::context::CreateAssetRequest{
|
||||
assetType:rbx_asset::context::AssetType::Model,
|
||||
displayName:config.model_name,
|
||||
@ -372,29 +465,33 @@ async fn create(config:CreateConfig)->AResult<()>{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn upload_list(cookie:String,asset_id_file_map:AssetIDFileMap)->AResult<()>{
|
||||
let context=RobloxContext::new(cookie);
|
||||
//this is calling map on the vec because the closure produces an iterator of futures
|
||||
futures::stream::iter(asset_id_file_map.into_iter()
|
||||
.map(|(asset_id,file)|{
|
||||
let context=&context;
|
||||
async move{
|
||||
Ok((asset_id,context.update_asset(rbx_asset::context::UpdateAssetRequest{
|
||||
assetId:asset_id,
|
||||
struct UploadAssetConfig{
|
||||
api_key:String,
|
||||
asset_id:u64,
|
||||
input_file:PathBuf,
|
||||
}
|
||||
async fn upload_asset(config:UploadAssetConfig)->AResult<()>{
|
||||
let context=RobloxContext::new(config.api_key);
|
||||
context.update_asset(rbx_asset::context::UpdateAssetRequest{
|
||||
assetId:config.asset_id,
|
||||
displayName:None,
|
||||
description:None,
|
||||
},tokio::fs::read(file).await?).await?))
|
||||
},tokio::fs::read(config.input_file).await?).await?;
|
||||
Ok(())
|
||||
}
|
||||
}))
|
||||
.buffer_unordered(CONCURRENT_REQUESTS)
|
||||
.for_each(|b:AResult<_>|async{
|
||||
match b{
|
||||
Ok((asset_id,body))=>{
|
||||
println!("asset_id={} UploadResponse={:?}",asset_id,body);
|
||||
},
|
||||
Err(e)=>eprintln!("ul error: {}",e),
|
||||
|
||||
struct UploadPlaceConfig{
|
||||
api_key:String,
|
||||
place_id:u64,
|
||||
universe_id:u64,
|
||||
input_file:PathBuf,
|
||||
}
|
||||
}).await;
|
||||
async fn upload_place(config:UploadPlaceConfig)->AResult<()>{
|
||||
let context=RobloxContext::new(config.api_key);
|
||||
context.update_place(rbx_asset::context::UpdatePlaceRequest{
|
||||
placeId:config.place_id,
|
||||
universeId:config.universe_id,
|
||||
},tokio::fs::read(config.input_file).await?).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -404,7 +501,7 @@ async fn download_list(cookie:String,asset_id_file_map:AssetIDFileMap)->AResult<
|
||||
.map(|(asset_id,file)|{
|
||||
let context=&context;
|
||||
async move{
|
||||
Ok((file,context.download(rbx_asset::context::GetAssetRequest{asset_id,version:None}).await?))
|
||||
Ok((file,context.get_asset(rbx_asset::context::GetAssetRequest{asset_id,version:None}).await?))
|
||||
}
|
||||
}))
|
||||
.buffer_unordered(CONCURRENT_REQUESTS)
|
||||
@ -451,7 +548,7 @@ async fn get_version_history(context:&RobloxContext,asset_id:AssetID)->AResult<V
|
||||
let mut cursor:Option<String>=None;
|
||||
let mut asset_list=Vec::new();
|
||||
loop{
|
||||
let mut page=context.history_page(rbx_asset::context::AssetVersionsRequest{asset_id,cursor}).await?;
|
||||
let mut page=context.get_asset_versions(rbx_asset::context::AssetVersionsRequest{asset_id,cursor}).await?;
|
||||
asset_list.append(&mut page.data);
|
||||
if page.nextPageCursor.is_none(){
|
||||
break;
|
||||
@ -467,7 +564,7 @@ struct DownloadHistoryConfig{
|
||||
end_version:Option<u64>,
|
||||
start_version:u64,
|
||||
output_folder:PathBuf,
|
||||
cookie:String,
|
||||
api_key:String,
|
||||
asset_id:AssetID,
|
||||
}
|
||||
|
||||
@ -508,7 +605,7 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
|
||||
None=>Err(anyhow::Error::msg("Cannot continue from versions.json - there are no previous versions"))?,
|
||||
}
|
||||
}
|
||||
let context=RobloxContext::new(config.cookie);
|
||||
let context=RobloxContext::new(config.api_key);
|
||||
|
||||
//limit concurrent downloads
|
||||
let mut join_set=tokio::task::JoinSet::new();
|
||||
@ -516,7 +613,7 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
|
||||
//poll paged list of all asset versions
|
||||
let mut cursor:Option<String>=None;
|
||||
loop{
|
||||
let mut page=context.history_page(rbx_asset::context::AssetVersionsRequest{asset_id:config.asset_id,cursor}).await?;
|
||||
let mut page=context.get_asset_versions(rbx_asset::context::AssetVersionsRequest{asset_id:config.asset_id,cursor}).await?;
|
||||
let context=&context;
|
||||
let output_folder=config.output_folder.clone();
|
||||
let data=&page.data;
|
||||
@ -546,7 +643,7 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{
|
||||
let mut path=output_folder.clone();
|
||||
path.push(format!("{}_v{}.rbxl",config.asset_id,version_number));
|
||||
join_set.spawn(async move{
|
||||
let file=context.download(rbx_asset::context::GetAssetRequest{asset_id:config.asset_id,version:Some(version_number)}).await?;
|
||||
let file=context.get_asset(rbx_asset::context::GetAssetRequest{asset_id:config.asset_id,version:Some(version_number)}).await?;
|
||||
|
||||
tokio::fs::write(path,file).await?;
|
||||
|
||||
@ -641,7 +738,7 @@ async fn decompile(config:DecompileConfig)->AResult<()>{
|
||||
}
|
||||
|
||||
struct DownloadDecompileConfig{
|
||||
cookie:String,
|
||||
api_key:String,
|
||||
asset_id:AssetID,
|
||||
style:rox_compiler::Style,
|
||||
output_folder:PathBuf,
|
||||
@ -651,8 +748,8 @@ struct DownloadDecompileConfig{
|
||||
}
|
||||
|
||||
async fn download_decompile(config:DownloadDecompileConfig)->AResult<()>{
|
||||
let context=RobloxContext::new(config.cookie);
|
||||
let file=context.download(rbx_asset::context::GetAssetRequest{asset_id:config.asset_id,version:None}).await?;
|
||||
let context=RobloxContext::new(config.api_key);
|
||||
let file=context.get_asset(rbx_asset::context::GetAssetRequest{asset_id:config.asset_id,version:None}).await?;
|
||||
|
||||
let dom=load_dom(std::io::Cursor::new(file))?;
|
||||
let context=rox_compiler::DecompiledContext::from_dom(dom);
|
||||
@ -809,7 +906,7 @@ async fn decompile_history_into_git(config:DecompileHistoryConfig)->AResult<()>{
|
||||
}
|
||||
|
||||
struct DownloadAndDecompileHistoryConfig{
|
||||
cookie:String,
|
||||
api_key:String,
|
||||
asset_id:AssetID,
|
||||
git_committer_name:String,
|
||||
git_committer_email:String,
|
||||
@ -821,7 +918,7 @@ struct DownloadAndDecompileHistoryConfig{
|
||||
}
|
||||
|
||||
async fn download_and_decompile_history_into_git(config:DownloadAndDecompileHistoryConfig)->AResult<()>{
|
||||
let context=RobloxContext::new(config.cookie);
|
||||
let context=RobloxContext::new(config.api_key);
|
||||
|
||||
//poll paged list of all asset versions
|
||||
let asset_list=get_version_history(&context,config.asset_id).await?;
|
||||
@ -834,7 +931,7 @@ async fn download_and_decompile_history_into_git(config:DownloadAndDecompileHist
|
||||
.map(|asset_version|{
|
||||
let context=context.clone();
|
||||
tokio::task::spawn(async move{
|
||||
let file=context.download(rbx_asset::context::GetAssetRequest{asset_id,version:Some(asset_version.assetVersionNumber)}).await?;
|
||||
let file=context.get_asset(rbx_asset::context::GetAssetRequest{asset_id,version:Some(asset_version.assetVersionNumber)}).await?;
|
||||
let dom=load_dom(std::io::Cursor::new(file))?;
|
||||
Ok::<_,anyhow::Error>((asset_version,rox_compiler::DecompiledContext::from_dom(dom)))
|
||||
})
|
||||
@ -888,15 +985,14 @@ async fn compile(config:CompileConfig)->AResult<()>{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct CompileUploadConfig{
|
||||
struct CompileUploadAssetConfig{
|
||||
input_folder:PathBuf,
|
||||
template:Option<PathBuf>,
|
||||
style:Option<rox_compiler::Style>,
|
||||
cookie:String,
|
||||
group:Option<u64>,
|
||||
api_key:String,
|
||||
asset_id:AssetID,
|
||||
}
|
||||
async fn compile_upload(config:CompileUploadConfig)->AResult<()>{
|
||||
async fn compile_upload_asset(config:CompileUploadAssetConfig)->AResult<()>{
|
||||
let mut dom=match config.template{
|
||||
//mr dom doesn't like tokio files
|
||||
Some(template_path)=>load_dom(std::io::BufReader::new(std::fs::File::open(template_path)?))?,
|
||||
@ -913,14 +1009,44 @@ async fn compile_upload(config:CompileUploadConfig)->AResult<()>{
|
||||
rbx_binary::to_writer(std::io::Cursor::new(&mut data),&dom,dom.root().children())?;
|
||||
|
||||
//upload it
|
||||
let context=RobloxContext::new(config.cookie);
|
||||
context.upload(rbx_asset::context::UpdateAssetRequest{
|
||||
assetid:config.asset_id,
|
||||
name:None,
|
||||
let context=RobloxContext::new(config.api_key);
|
||||
context.update_asset(rbx_asset::context::UpdateAssetRequest{
|
||||
assetId:config.asset_id,
|
||||
displayName:None,
|
||||
description:None,
|
||||
ispublic:None,
|
||||
allowComments:None,
|
||||
groupId:config.group,
|
||||
},data).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct CompileUploadPlaceConfig{
|
||||
input_folder:PathBuf,
|
||||
template:Option<PathBuf>,
|
||||
style:Option<rox_compiler::Style>,
|
||||
api_key:String,
|
||||
place_id:u64,
|
||||
universe_id:u64,
|
||||
}
|
||||
async fn compile_upload_place(config:CompileUploadPlaceConfig)->AResult<()>{
|
||||
let mut dom=match config.template{
|
||||
//mr dom doesn't like tokio files
|
||||
Some(template_path)=>load_dom(std::io::BufReader::new(std::fs::File::open(template_path)?))?,
|
||||
None=>rbx_dom_weak::WeakDom::new(rbx_dom_weak::InstanceBuilder::new("DataModel")),
|
||||
};
|
||||
|
||||
rox_compiler::compile(rox_compiler::CompileConfig{
|
||||
input_folder:config.input_folder,
|
||||
style:config.style,
|
||||
},&mut dom).await?;
|
||||
|
||||
//make a binary file in a buffer in memory
|
||||
let mut data=Vec::new();
|
||||
rbx_binary::to_writer(std::io::Cursor::new(&mut data),&dom,dom.root().children())?;
|
||||
|
||||
//upload it
|
||||
let context=RobloxContext::new(config.api_key);
|
||||
context.update_place(rbx_asset::context::UpdatePlaceRequest{
|
||||
universeId:config.universe_id,
|
||||
placeId:config.place_id,
|
||||
},data).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user