Skip to content

Commit

Permalink
Add XenForo support and begin TUI work.
Browse files Browse the repository at this point in the history
  • Loading branch information
whispersilk committed Nov 25, 2022
1 parent 5ffbfaa commit 6423704
Show file tree
Hide file tree
Showing 15 changed files with 1,483 additions and 667 deletions.
79 changes: 79 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
async-trait = "0.1.58"
chrono = { version = "0.4", features = ["default", "serde"] }
clap = { version = "4.0.9", features = ["derive"] }
crossterm = "0.25.0"
futures = "0.3.0"
html2md = "0.2.13"
once_cell = "1.14"
Expand All @@ -20,3 +21,4 @@ rusqlite = { version = "0.28.0", features = ["bundled-full"] }
select = "0.5"
serde = "1.0.146"
tokio = { version = "1", features = ["full"] }
tui = "0.19.0"
4 changes: 3 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[command(author, version, about)]
pub(crate) struct Args {
#[arg(global = true, short, long, default_value = "fic_archive.db")]
pub db: String,
#[command(subcommand)]
pub command: Commands,
pub command: Option<Commands>,
}

#[derive(Debug, Subcommand)]
Expand Down
9 changes: 3 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use serde::ser::Serialize;

use std::time::Duration;

use crate::error::ArchiveError;
use crate::Result;

static CLIENT: once_cell::sync::OnceCell<Client> = once_cell::sync::OnceCell::new();

pub async fn get(url: &str) -> Result<Response, ArchiveError> {
pub async fn get(url: &str) -> Result<Response> {
let client: &Client =
CLIENT.get_or_init(|| Client::builder().cookie_store(true).build().unwrap());
let mut response = client.get(url).send().await?;
Expand Down Expand Up @@ -40,10 +40,7 @@ pub async fn get(url: &str) -> Result<Response, ArchiveError> {
}
}

pub async fn get_with_query<T: Serialize + ?Sized>(
url: &str,
query: &T,
) -> Result<Response, ArchiveError> {
pub async fn get_with_query<T: Serialize + ?Sized>(url: &str, query: &T) -> Result<Response> {
let client: &Client =
CLIENT.get_or_init(|| Client::builder().cookie_store(true).build().unwrap());
let mut response = client.get(url).query(query).send().await?;
Expand Down
8 changes: 8 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub enum ArchiveError {
Request(reqwest::Error),
Database(rusqlite::Error),
Parse(chrono::format::ParseError),
ParseInt(std::num::ParseIntError),
}

impl fmt::Display for ArchiveError {
Expand All @@ -32,6 +33,7 @@ impl fmt::Display for ArchiveError {
Self::Request(ref err) => err.fmt(f),
Self::Database(ref err) => err.fmt(f),
Self::Parse(ref err) => err.fmt(f),
Self::ParseInt(ref err) => err.fmt(f),
}
}
}
Expand Down Expand Up @@ -60,4 +62,10 @@ impl From<chrono::format::ParseError> for ArchiveError {
}
}

impl From<std::num::ParseIntError> for ArchiveError {
fn from(err: std::num::ParseIntError) -> ArchiveError {
Self::ParseInt(err)
}
}

impl Error for ArchiveError {}
Loading

0 comments on commit 6423704

Please sign in to comment.