start version argument

This commit is contained in:
Quaternions 2024-01-12 16:27:31 -08:00
parent eb20f8056d
commit 1b3a8be142

View File

@ -25,6 +25,8 @@ struct Cli{
cookie_env:Option<String>,
#[arg(long)]
cookie_file:Option<std::path::PathBuf>,
#[arg(long)]
start_version:Option<u64>,
//decompile options
#[arg(long)]
@ -134,6 +136,7 @@ async fn main()->AResult<()>{
match cli.command{
Commands::DownloadHistory=>download_history(DownloadHistoryConfig{
start_version:cli.start_version.unwrap_or(0),
output_folder:cli.output.unwrap(),
cookie:cookie.unwrap(),
asset_id:cli.asset_id.unwrap(),
@ -348,6 +351,7 @@ async fn download_asset_version(client:&reqwest::Client,cookie:&str,asset_id_str
}
struct DownloadHistoryConfig{
start_version:u64,
output_folder:std::path::PathBuf,
cookie:String,
asset_id:AssetID,
@ -364,8 +368,13 @@ async fn download_history(config:DownloadHistoryConfig)->AResult<()>{
let mut join_handles=Vec::new();
loop{
let mut page=download_page(&client,config.cookie.as_str(),config.asset_id,cursor).await?;
let mut cancel_paging=false;
for asset_version in &page.data{
let version_number=asset_version.assetVersionNumber;
if version_number<config.start_version{
cancel_paging=true;
continue;//don't trust roblox returned order
}
let client=client.clone();
let cookie=config.cookie.clone();
let asset_id_str=asset_id_string.clone();
@ -385,9 +394,15 @@ async fn download_history(config:DownloadHistoryConfig)->AResult<()>{
Ok::<_,anyhow::Error>(())
}));
}
asset_list.append(&mut page.data);
if page.nextPageCursor.is_none(){
if page.nextPageCursor.is_none()||cancel_paging{
for asset_version in page.data.into_iter(){
if config.start_version<=asset_version.assetVersionNumber{
asset_list.push(asset_version);
}
}
break;
}else{
asset_list.append(&mut page.data);
}
cursor=page.nextPageCursor;
}