initial
This commit is contained in:
42
src/main.rs
42
src/main.rs
@@ -14,7 +14,7 @@ type Client = ClientWithMiddleware;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let input = util::get_input("Enter search query: ");
|
||||
let config = util::args();
|
||||
let retry_policy = ExponentialBackoff::builder().build_with_max_retries(3);
|
||||
let client = ClientBuilder::new(
|
||||
reqwest::Client::builder()
|
||||
@@ -29,7 +29,13 @@ async fn main() {
|
||||
//("status[]", "completed"),
|
||||
// ("contentRating[]", "suggestive"),
|
||||
];
|
||||
let results = search(&client, &input, &filters).await;
|
||||
let limit = config.result_limit;
|
||||
let results = if let Some(query) = config.search {
|
||||
search(&client, &query, &filters, limit).await
|
||||
} else {
|
||||
let input = util::get_input("Enter search query: ");
|
||||
search(&client, &input, &filters, limit).await
|
||||
};
|
||||
let mut entries = vec![];
|
||||
for result in results.data.iter() {
|
||||
let mut entry = Entry::new(result.attributes.title.en.clone());
|
||||
@@ -63,17 +69,27 @@ async fn main() {
|
||||
.unwrap();
|
||||
let result = util::convert_to_sixel(&data);
|
||||
|
||||
entry.add_image(result)
|
||||
entry.set_image(result)
|
||||
}
|
||||
entries.push(entry);
|
||||
}
|
||||
let choice = select::select(&entries).unwrap();
|
||||
let choice = match select::select(&entries) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
eprintln!("ERROR: Failed to select: {:?}", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
let choice_id = &results.data[choice as usize].id;
|
||||
let bonus = loop {
|
||||
match util::get_input("Read bonus chapters? [y/n] : ").as_str() {
|
||||
"y" | "yes" => break true,
|
||||
"n" | "no" => break false,
|
||||
_ => continue,
|
||||
let bonus = if let Some(bonus) = config.bonus {
|
||||
bonus
|
||||
} else {
|
||||
loop {
|
||||
match util::get_input("Read bonus chapters? [y/n] : ").as_str() {
|
||||
"y" | "yes" => break true,
|
||||
"n" | "no" => break false,
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
};
|
||||
let mut chapters = match get_chapters(&client, choice_id).await {
|
||||
@@ -217,8 +233,12 @@ async fn get_chapters(client: &Client, id: &Id) -> Result<Vec<Chapter>, reqwest_
|
||||
Ok(result.data)
|
||||
}
|
||||
|
||||
async fn search(client: &Client, query: &str, filters: &[(&str, &str)]) -> SearchResult {
|
||||
let limit = 10;
|
||||
async fn search(
|
||||
client: &Client,
|
||||
query: &str,
|
||||
filters: &[(&str, &str)],
|
||||
limit: u32,
|
||||
) -> SearchResult {
|
||||
let params = [
|
||||
("title", query),
|
||||
("limit", &limit.to_string()),
|
||||
|
||||
Reference in New Issue
Block a user