summaryrefslogblamecommitdiff
path: root/src/commands/download.rs
blob: b0efdc20c3d52cbdc98cdf0fd21d085b11846bd4 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                     
                        
                                                                                               
 


                                                                                              

                                                 
                                                                             
 
                                                      
      


          
                   




                                                                                                                                              
 







                                                    
      
 
                     
 















                                                                                                                          
use crate::{modrinth::Version, files::download_file};
#[allow(unused_imports)]
use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input};

pub async fn download(_config: Cfg, _input: Input) -> Result<(), Box<dyn std::error::Error>> {
    println!("NO IMPLEMENTATION FOR DOWNLOAD YET");
    /*
    let list = get_current_list(config.clone())?;

    let links = userlist_get_all_downloads(config.clone(), list.clone().id)?;

    download_links(config, input, list, links).await?;
    */
    Ok(())
}

#[allow(dead_code)]
async fn download_links(_config: Cfg, _input: Input, _current_list: List, _links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> {
    println!("NO DL IMPLEMENTATION FOR DOWNLOAD YET");
    //TODO copy dl from update if possible
    /*
    let dl_path = String::from(&current_list.download_folder);

    if input.clean {
        let dl_path = &current_list.download_folder;
        println!("Cleaning {}", dl_path);
        for entry in std::fs::read_dir(dl_path)? {
            let entry = entry?;
            std::fs::remove_file(entry.path())?;
        }
    }
    */

    Ok(String::new())
}

pub async fn download_versions(current_list: List, versions: Vec<Version>) -> Result<String, Box<dyn std::error::Error>> {

    let dl_path = String::from(&current_list.download_folder);

    for ver in versions {
        let primary_file = ver.files.into_iter().find(|file| file.primary).unwrap();
        let mut splitname: Vec<&str> = primary_file.filename.split('.').collect();
        let extension = splitname.pop().ok_or("NO_FILE_EXTENSION")?;
        let filename = format!("{}.mr{}.{}", splitname.join("."), ver.id, extension);
        download_file(primary_file.url, current_list.clone().download_folder, filename).await?;
    }

    Ok(dl_path)
}