diff options
| author | A Farzat <a@farzat.xyz> | 2026-02-11 11:13:36 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2026-02-11 11:13:36 +0300 |
| commit | 2d9314aa3145ec7948341f38164e13c2a2d945ad (patch) | |
| tree | 29f69a0b89983fbeb2f0227698aab9dd884d9a54 /src/main.rs | |
| parent | 3321918c009e9d7a7a3c3c2a1f490bb91fefb2bc (diff) | |
| download | safaribooks-rs-2d9314aa3145ec7948341f38164e13c2a2d945ad.tar.gz safaribooks-rs-2d9314aa3145ec7948341f38164e13c2a2d945ad.zip | |
Add a login check
Try to access the profile page to see if the cookies work or not.
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 6981b8e..f79f191 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,14 +3,18 @@ mod config; mod cookies; mod display; mod http_client; +mod orly; use clap::Parser; use cli::Args; use cookies::CookieStore; use display::Display; use http_client::HttpClient; +use orly::check_login; +use reqwest::Client; -fn main() { +#[tokio::main] +async fn main() { let args = Args::parse(); let mut ui = Display::new(&args.bookid); @@ -40,12 +44,22 @@ fn main() { )); // Build the HTTP client with our cookies (no network calls yet). - let _client = match HttpClient::from_store(&store) { + let client = match HttpClient::from_store(&store) { Ok(c) => c, Err(e) => ui.error_and_exit(&format!("Failed to build HTTP client: {e}")), }; ui.info("HTTP client initialized with cookies (no requests performed)."); + // Check whether the cookies work (are we logged in?). + match check_login(&client).await { + Ok(true) => ui.info("Login confirmed..."), + Ok(false) => ui.error_and_exit( + "Logged out. Cookies could be stale or invalid.\n\ + Try refreshing your cookies.json and trying again.", + ), + Err(e) => ui.error_and_exit(&format!("Login check failed: {e}")), + }; + let output_dir = config::books_root().join(format!("(pending) ({})", args.bookid)); ui.set_output_dir(output_dir); |
