download version history
This commit is contained in:
parent
bb32d30896
commit
1c16759ccc
63
Cargo.lock
generated
63
Cargo.lock
generated
@ -26,6 +26,21 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.5"
|
||||
@ -97,6 +112,7 @@ name = "asset-tool"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
"clap",
|
||||
"flate2",
|
||||
"futures",
|
||||
@ -203,6 +219,21 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.4.12"
|
||||
@ -602,6 +633,29 @@ dependencies = [
|
||||
"tokio-native-tls",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.59"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.3"
|
||||
@ -1631,6 +1685,15 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
|
@ -7,6 +7,7 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.75"
|
||||
chrono = { version = "0.4.31", features = ["serde"] }
|
||||
clap = { version = "4.4.2", features = ["derive"] }
|
||||
flate2 = "1.0.28"
|
||||
futures = "0.3.30"
|
||||
@ -16,7 +17,7 @@ rbx_binary = "0.7.1"
|
||||
rbx_dom_weak = "2.5.0"
|
||||
rbx_reflection_database = "0.2.7"
|
||||
rbx_xml = "0.13.1"
|
||||
reqwest = { version = "0.11.23", features = ["cookies"] }
|
||||
reqwest = { version = "0.11.23", features = ["cookies", "json"] }
|
||||
serde = { version = "1.0.195", features = ["derive"] }
|
||||
serde_json = "1.0.111"
|
||||
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread", "fs"] }
|
||||
|
139
src/main.rs
139
src/main.rs
@ -8,20 +8,6 @@ type AssetID=u64;
|
||||
type AssetIDFileMap=Vec<(AssetID,std::path::PathBuf)>;
|
||||
const CONCURRENT_REQUESTS:usize=8;
|
||||
|
||||
/// Parse a single key-value pair
|
||||
fn parse_key_val<T,U>(s:&str)->AResult<(T,U)>
|
||||
where
|
||||
T:std::str::FromStr,
|
||||
T::Err:std::error::Error+Send+Sync+'static,
|
||||
U:std::str::FromStr,
|
||||
U::Err:std::error::Error+Send+Sync+'static,
|
||||
{
|
||||
let pos=s
|
||||
.find('=')
|
||||
.ok_or_else(||anyhow::Error::msg(format!("invalid KEY=value: no `=` found in `{s}`")))?;
|
||||
Ok((s[..pos].parse()?,s[pos+1..].parse()?))
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author,version,about,long_about=None)]
|
||||
#[command(propagate_version = true)]
|
||||
@ -36,8 +22,8 @@ struct Cli{
|
||||
#[arg(long)]
|
||||
cookie_file:Option<std::path::PathBuf>,
|
||||
|
||||
#[arg(long,value_parser=parse_key_val::<AssetID,std::path::PathBuf>)]
|
||||
asset_id:Option<(AssetID,std::path::PathBuf)>,
|
||||
#[arg(long)]
|
||||
asset_id:Option<AssetID>,
|
||||
|
||||
#[arg(short,long)]
|
||||
input:Option<std::path::PathBuf>,
|
||||
@ -51,6 +37,7 @@ struct Cli{
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands{
|
||||
DownloadHistory,
|
||||
Download,
|
||||
Upload,
|
||||
Compile,
|
||||
@ -62,6 +49,24 @@ struct PathBufList{
|
||||
paths:Vec<std::path::PathBuf>
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct VersionPage{
|
||||
previousPageCursor:Option<String>,
|
||||
nextPageCursor:Option<String>,
|
||||
data:Vec<AssetVersion>,
|
||||
}
|
||||
#[derive(serde::Deserialize,serde::Serialize)]
|
||||
struct AssetVersion{
|
||||
Id:u64,
|
||||
assetId:AssetID,
|
||||
assetVersionNumber:u64,
|
||||
creatorType:String,
|
||||
creatorTargetId:u64,
|
||||
creatingUniverseId:Option<u64>,
|
||||
created:chrono::DateTime<chrono::Utc>,
|
||||
isPublished:bool,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main()->AResult<()>{
|
||||
let cli=Cli::parse();
|
||||
@ -85,8 +90,9 @@ async fn main()->AResult<()>{
|
||||
};
|
||||
|
||||
match cli.command{
|
||||
Commands::Download=>download_list(cookie.unwrap(),vec![cli.asset_id.unwrap()]).await,
|
||||
Commands::Upload=>upload_list(cookie.unwrap(),cli.group,vec![cli.asset_id.unwrap()]).await,
|
||||
Commands::DownloadHistory=>download_history(cookie.unwrap(),cli.asset_id.unwrap()).await,
|
||||
Commands::Download=>download_list(cookie.unwrap(),vec![(cli.asset_id.unwrap(),cli.output.unwrap())]).await,
|
||||
Commands::Upload=>upload_list(cookie.unwrap(),cli.group,vec![(cli.asset_id.unwrap(),cli.output.unwrap())]).await,
|
||||
Commands::Compile=>compile(cli.input.unwrap(),cli.output.unwrap()),
|
||||
Commands::Decompile=>decompile(cli.input.unwrap(),cli.output.unwrap()),
|
||||
}
|
||||
@ -210,6 +216,103 @@ async fn download_list(cookie:String,asset_id_file_map:AssetIDFileMap)->AResult<
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn download_history(cookie:String,asset_id:AssetID)->AResult<()>{
|
||||
let client=reqwest::Client::new();
|
||||
let asset_id_string=asset_id.to_string();
|
||||
|
||||
let mut cursor:Option<String>=None;
|
||||
let mut asset_list=Vec::new();
|
||||
loop{
|
||||
let mut url=reqwest::Url::parse(format!("https://develop.roblox.com/v1/assets/{}/saved-versions",asset_id).as_str())?;
|
||||
//url borrow scope
|
||||
{
|
||||
let mut query=url.query_pairs_mut();//borrow here
|
||||
//query.append_pair("sortOrder","Asc");
|
||||
//query.append_pair("limit","100");
|
||||
//query.append_pair("count","100");
|
||||
match &cursor{
|
||||
Some(next_page)=>{query.append_pair("cursor",next_page);}
|
||||
None=>(),
|
||||
}
|
||||
}
|
||||
println!("url={}",url);
|
||||
let resp=client.get(url)
|
||||
.header("Cookie",cookie.clone())
|
||||
.send().await?;
|
||||
println!("resp:{:?}",resp);
|
||||
match resp.json::<VersionPage>().await{
|
||||
Ok(mut page)=>{
|
||||
asset_list.append(&mut page.data);
|
||||
if page.nextPageCursor.is_none(){
|
||||
break;
|
||||
}
|
||||
cursor=page.nextPageCursor;
|
||||
},
|
||||
Err(e)=>panic!("error: {}",e),
|
||||
}
|
||||
}
|
||||
asset_list.sort_by(|a,b|a.assetVersionNumber.cmp(&b.assetVersionNumber));
|
||||
let mut path=std::path::PathBuf::new();
|
||||
path.set_file_name("versions.json");
|
||||
tokio::fs::write(path,serde_json::to_string(&asset_list)?).await?;
|
||||
|
||||
//download all versions
|
||||
futures::stream::iter(asset_list)
|
||||
.map(|asset_version|{
|
||||
let client=&client;
|
||||
let cookie=cookie.as_str();
|
||||
let asset_id_str=asset_id_string.as_str();
|
||||
async move{
|
||||
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v1/asset/")?;
|
||||
//url borrow scope
|
||||
{
|
||||
let mut query=url.query_pairs_mut();//borrow here
|
||||
query.append_pair("ID",asset_id_str);
|
||||
query.append_pair("version",asset_version.assetVersionNumber.to_string().as_str());
|
||||
}
|
||||
println!("url={}",url);
|
||||
let mut result=Err(anyhow::Error::msg("all requests failed"));
|
||||
for i in 1..=8{
|
||||
let resp=client.get(url.clone())
|
||||
.header("Cookie",cookie)
|
||||
.send().await?;
|
||||
|
||||
if !resp.status().is_success(){
|
||||
println!("request {} failed",i);
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut path=std::path::PathBuf::new();
|
||||
path.set_file_name(format!("{}_v{}.rbxl",asset_id,asset_version.assetVersionNumber));
|
||||
result=Ok((path,resp.bytes().await?));
|
||||
break;
|
||||
}
|
||||
result
|
||||
}
|
||||
})
|
||||
.buffer_unordered(CONCURRENT_REQUESTS)
|
||||
.for_each(|b:AResult<_>|async{
|
||||
match b{
|
||||
Ok((dest,body))=>{
|
||||
let contents=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),
|
||||
};
|
||||
match contents{
|
||||
Ok(data)=>match tokio::fs::write(dest,data).await{
|
||||
Err(e)=>eprintln!("fs error: {}",e),
|
||||
_=>(),
|
||||
},
|
||||
Err(e)=>eprintln!("gzip error: {}",e),
|
||||
};
|
||||
},
|
||||
Err(e)=>eprintln!("dl error: {}",e),
|
||||
}
|
||||
}).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn load_dom<R:Read+Seek>(input:&mut R)->AResult<rbx_dom_weak::WeakDom>{
|
||||
let mut first_8=[0u8;8];
|
||||
if let (Ok(()),Ok(()))=(std::io::Read::read_exact(input, &mut first_8),std::io::Seek::rewind(input)){
|
||||
|
Loading…
x
Reference in New Issue
Block a user