From 131e9998e9e019e21e66dfb7d305b83839690431 Mon Sep 17 00:00:00 2001 From: 17ms <79069176+17ms@users.noreply.github.com> Date: Fri, 2 Jun 2023 22:20:52 +0300 Subject: [PATCH] linting, cleaning & renaming --- Cargo.toml | 4 +--- src/board.rs | 2 +- src/downloader.rs | 7 +++++-- src/main.rs | 12 ++++-------- src/thread.rs | 4 ++-- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1332c65..870f8f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,8 @@ [package] -name = "rusty-downloader" +name = "dlrs" version = "0.2.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] clap = "3.1.18" regex = "1.5.6" diff --git a/src/board.rs b/src/board.rs index f197e07..bd0c930 100644 --- a/src/board.rs +++ b/src/board.rs @@ -3,7 +3,7 @@ use serde_json::Value; type Result = std::result::Result>; pub fn parse_url(url: &str) -> (String, String) { - let url_split: Vec<&str> = url.split("/").collect(); + let url_split: Vec<&str> = url.split('/').collect(); let board_name = url_split.get(url_split.len() - 2).unwrap(); ( diff --git a/src/downloader.rs b/src/downloader.rs index 485341d..4186571 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -2,7 +2,10 @@ use colored::Colorize; use futures::{stream, StreamExt}; use reqwest::Client; use serde_json::Value; -use std::{path::PathBuf, process::exit}; +use std::{ + path::{Path, PathBuf}, + process::exit, +}; use tokio::{fs::File, io::AsyncWriteExt}; type Result = std::result::Result>; @@ -10,7 +13,7 @@ type Result = std::result::Result>; pub async fn get_imagelist( json_url: &str, board_name: &str, - output_path: &PathBuf, + output_path: &Path, ) -> Result> { let req_body_raw = match reqwest::get(json_url).await { Ok(n) => n, diff --git a/src/main.rs b/src/main.rs index 77a1184..5580694 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ use clap::{Arg, ArgGroup, Command}; use colored::Colorize; use regex::Regex; use std::{path::PathBuf, process::exit}; -use tokio; type Result = std::result::Result>; @@ -17,10 +16,7 @@ enum Mode { } fn parse_cli_args() -> Result<(PathBuf, String, Mode)> { - let matches = Command::new("Rust-powered image downloader for 4chan") - .version("0.2.0") - .author("Arttu Einistö ") - .about("Minimal asynchronous image downloader for 4chan threads/boards") + let matches = Command::new("dlrs") .arg( Arg::new("output") .short('o') @@ -62,7 +58,7 @@ fn parse_cli_args() -> Result<(PathBuf, String, Mode)> { let target = match re.is_match(target_match) { true => target_match, false => { - eprintln!("{}", format!("Error: Invalid URL format").bold().red()); + eprintln!("{}", "Error: Invalid URL format".to_string().bold().red()); exit(0x0100); } }; @@ -71,7 +67,7 @@ fn parse_cli_args() -> Result<(PathBuf, String, Mode)> { false => Mode::Board, }; - Ok((path, String::from(target), mode)) + Ok((path, target.to_string(), mode)) } #[tokio::main] @@ -110,7 +106,7 @@ async fn main() -> Result<()> { let mut filecount: usize = 0; for url in &thread_data { println!("{}", format!("Parsing JSON from {}", url).bold().blue()); - let img_data = downloader::get_imagelist(&url, &board_name, &path).await?; + let img_data = downloader::get_imagelist(url, &board_name, &path).await?; let total_amt = downloader::get_images(&img_data).await?; filecount += total_amt; } diff --git a/src/thread.rs b/src/thread.rs index 14d240a..b39de8d 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -1,6 +1,6 @@ pub fn parse_url(url: &str) -> (String, String) { - let url_split: Vec<&str> = url.split("/").collect(); - let thread_id = url_split.get(url_split.len() - 1).unwrap(); + let url_split: Vec<&str> = url.split('/').collect(); + let thread_id = url_split.last().unwrap(); let board_name = url_split.get(url_split.len() - 3).unwrap(); (