forked from StrafesNET/asset-tool
end_version for download_history + catch download error and write versions.json
This commit is contained in:
parent
e5322ad711
commit
5574c34045
34
src/main.rs
34
src/main.rs
@ -28,6 +28,8 @@ struct Cli{
|
||||
//TODO: read the versions.json file instead of doing this
|
||||
#[arg(long)]
|
||||
start_version:Option<u64>,
|
||||
#[arg(long)]
|
||||
end_version:Option<u64>,
|
||||
|
||||
//decompile options
|
||||
#[arg(long)]
|
||||
@ -137,6 +139,7 @@ async fn main()->AResult<()>{
|
||||
|
||||
match cli.command{
|
||||
Commands::DownloadHistory=>download_history(DownloadHistoryConfig{
|
||||
end_version:cli.end_version,
|
||||
start_version:cli.start_version.unwrap_or(0),
|
||||
output_folder:cli.output.unwrap(),
|
||||
cookie:cookie.unwrap(),
|
||||
@ -352,6 +355,7 @@ async fn download_asset_version(client:&reqwest::Client,cookie:&str,asset_id_str
|
||||
}
|
||||
|
||||
struct DownloadHistoryConfig{
|
||||
end_version:Option<u64>,
|
||||
start_version:u64,
|
||||
output_folder:std::path::PathBuf,
|
||||
cookie:String,
|
||||
@ -371,9 +375,19 @@ async fn download_history(config:DownloadHistoryConfig)->AResult<()>{
|
||||
let mut asset_list=Vec::new();
|
||||
loop{
|
||||
let mut page=download_page(&client,config.cookie.as_str(),config.asset_id,cursor).await?;
|
||||
let client=&client;
|
||||
let cookie=config.cookie.clone();
|
||||
let asset_id_str=asset_id_string.clone();
|
||||
let output_folder=config.output_folder.clone();
|
||||
let data=&page.data;
|
||||
let join_set=&mut join_set;
|
||||
let error_catcher=||async move{
|
||||
let mut cancel_paging=false;
|
||||
for asset_version in &page.data{
|
||||
for asset_version in data{
|
||||
let version_number=asset_version.assetVersionNumber;
|
||||
if config.end_version.is_some_and(|v|v<version_number){
|
||||
continue;
|
||||
}
|
||||
if version_number<config.start_version{
|
||||
cancel_paging=true;
|
||||
continue;//don't trust roblox returned order
|
||||
@ -382,9 +396,9 @@ async fn download_history(config:DownloadHistoryConfig)->AResult<()>{
|
||||
join_set.join_next().await.unwrap()??;
|
||||
}
|
||||
let client=client.clone();
|
||||
let cookie=config.cookie.clone();
|
||||
let asset_id_str=asset_id_string.clone();
|
||||
let output_folder=config.output_folder.clone();
|
||||
let cookie=cookie.clone();
|
||||
let asset_id_str=asset_id_str.clone();
|
||||
let output_folder=output_folder.clone();
|
||||
join_set.spawn(async move{
|
||||
let resp=download_asset_version(&client,cookie.as_str(),asset_id_str.as_str(),version_number.to_string().as_str()).await?;
|
||||
let contents=match maybe_gzip_decode(std::io::Cursor::new(resp.bytes().await?))?{
|
||||
@ -392,7 +406,7 @@ async fn download_history(config:DownloadHistoryConfig)->AResult<()>{
|
||||
ReaderType::Raw(readable)=>read_readable(readable)?,
|
||||
};
|
||||
|
||||
let mut path=output_folder;
|
||||
let mut path=output_folder.clone();
|
||||
path.set_file_name(format!("{}_v{}.rbxl",config.asset_id,version_number));
|
||||
|
||||
tokio::fs::write(path,contents).await?;
|
||||
@ -400,6 +414,16 @@ async fn download_history(config:DownloadHistoryConfig)->AResult<()>{
|
||||
Ok::<_,anyhow::Error>(())
|
||||
});
|
||||
}
|
||||
Ok::<_,anyhow::Error>(cancel_paging)
|
||||
};
|
||||
let cancel_paging=match error_catcher().await{
|
||||
Ok(cancel)=>cancel,
|
||||
Err(e)=>{
|
||||
println!("download error: {}",e);
|
||||
//cancel download and write versions
|
||||
true
|
||||
},
|
||||
};
|
||||
if page.nextPageCursor.is_none()||cancel_paging{
|
||||
for asset_version in page.data.into_iter(){
|
||||
if config.start_version<=asset_version.assetVersionNumber{
|
||||
|
Loading…
Reference in New Issue
Block a user