aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 6981b8e0ef4059426812114f524a7d9bbbe87c62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
mod cli;
mod config;
mod cookies;
mod display;
mod http_client;

use clap::Parser;
use cli::Args;
use cookies::CookieStore;
use display::Display;
use http_client::HttpClient;

fn main() {
    let args = Args::parse();
    let mut ui = Display::new(&args.bookid);

    let cookies_path = config::cookies_file();
    if !cookies_path.exists() {
        ui.error_and_exit(
            "cookies.json not found.\n\
             This version requires an existing authenticated session.",
        );
    }

    // Load cookies
    let store = match CookieStore::load_from(&cookies_path) {
        Ok(c) => c,
        Err(e) => ui.error_and_exit(&format!("Failed to read cookies.json: {e}")),
    };

    if store.is_empty() {
        ui.error_and_exit("cookies.json is valid JSON but contains no cookies.");
    }

    let names = store.cookie_names();
    ui.info(&format!(
        "Loaded {} cookies: {}",
        store.len(),
        names.join(", ")
    ));

    // Build the HTTP client with our cookies (no network calls yet).
    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).");

    let output_dir = config::books_root().join(format!("(pending) ({})", args.bookid));

    ui.set_output_dir(output_dir);

    ui.info("Initialization complete.");
    ui.info("No network operations performed in this version.");
}