pub mod backend;
#[cfg(feature = "browser")]
pub mod browser;
pub mod cookie;
pub mod engine;
pub mod error;
pub mod eval;
pub mod fetch;
#[cfg(feature = "js-host")]
pub mod host;
#[cfg(feature = "js")]
mod js;
pub mod model;
pub mod source;
#[cfg(feature = "js-host")]
pub mod state;
mod transform;
pub mod verify;
mod xpath;
pub use engine::Engine;
pub use error::{BookSourceError, ConfigError, EvalError, FetchError, Result};
pub use fetch::{FetchRequest, FetchResponse, Fetcher, ReqwestFetcher, is_challenge};
pub use model::{BookInfo, BookListItem, Chapter, Toc, Volume};
pub use source::{BookSource, Category, FetchMode, UrlOrRule};
pub use verify::{Check, CheckStatus, DiagnoseReport, VerifyReport, diagnose, verify_sample};
#[cfg(feature = "browser")]
pub use browser::{
AuthDecision, BrowserCookie, BrowserFetcher, BrowserOptions, BrowserUi, Clearance,
EscalatingFetcher, LoginCriteria, LoginOutcome, LoginSignal, detect_browser,
};
#[cfg(test)]
pub(crate) mod testutil {
#![allow(dead_code)]
use crate::source::BookSource;
use std::io::{Read, Write};
use std::net::TcpListener;
pub(crate) fn book_source(base: &str) -> BookSource {
serde_json::from_value(serde_json::json!({
"schema": "trnovel-booksource/v2",
"name": "t",
"url": base,
"bookInfo": {},
"toc": {"list": {"via": "raw"}, "name": {"via": "raw"}, "url": {"via": "raw"}},
"content": {"value": {"via": "raw"}}
}))
.expect("minimal book source")
}
pub(crate) fn spawn_echo_server() -> (String, std::thread::JoinHandle<()>) {
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let base = format!("http://{}", listener.local_addr().unwrap());
let handle = std::thread::spawn(move || {
if let Ok((mut stream, _)) = listener.accept() {
let mut buf = [0u8; 8192];
let n = stream.read(&mut buf).unwrap_or(0);
let body = buf[..n].to_vec();
let head = format!(
"HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: {}\r\nConnection: close\r\n\r\n",
body.len()
);
let _ = stream.write_all(head.as_bytes());
let _ = stream.write_all(&body);
let _ = stream.flush();
}
});
(base, handle)
}
pub(crate) fn spawn_fixed_server(
raw_response: String,
) -> (String, std::thread::JoinHandle<()>) {
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let base = format!("http://{}", listener.local_addr().unwrap());
let handle = std::thread::spawn(move || {
if let Ok((mut stream, _)) = listener.accept() {
let mut buf = [0u8; 4096];
let _ = stream.read(&mut buf);
let _ = stream.write_all(raw_response.as_bytes());
let _ = stream.flush();
}
});
(base, handle)
}
}