Skip to main content

parse_book_source/
model.rs

1//! 领域类型(纯数据,无 IO、无规则逻辑)。
2
3use serde::{Deserialize, Serialize};
4use std::collections::BTreeMap;
5
6/// 一个 explore 入口(运行时):展示标题 + 取页变量。由入口加载(`Engine::explore_entries`)
7/// 从静态/动态入口源产生,供 UI 选择;取页时与 base/page/pageSize 合并后运行 `explore.page`。
8///
9/// 入口身份是「标题 + 变量」而非固定 URL——取页 URL 由 `explore.page.request` 用这些变量与
10/// `{{page}}` 模板生成。
11#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
12pub struct ExploreEntry {
13    pub title: String,
14    pub vars: BTreeMap<String, String>,
15}
16
17/// 目录条目(章节;`is_volume` 为 true 时表示卷标题,不是可阅读章节)。
18#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
19pub struct Chapter {
20    pub title: String,
21    pub url: String,
22    #[serde(default)]
23    pub is_volume: bool,
24}
25
26/// 卷标记(分卷元数据):卷标题 + 其首章在扁平章节列表中的索引。
27#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
28pub struct Volume {
29    pub title: String,
30    pub first_chapter_index: usize,
31}
32
33/// 解析后的目录:扁平章节列表 + 平行卷元数据(卷不进入章节序列)。
34#[derive(Debug, Clone, Default, PartialEq, Eq)]
35pub struct Toc {
36    pub chapters: Vec<Chapter>,
37    pub volumes: Vec<Volume>,
38}
39
40/// 书籍详情。
41#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
42pub struct BookInfo {
43    pub name: String,
44    pub author: String,
45    pub cover: String,
46    pub intro: String,
47    pub kind: String,
48    pub last_chapter: String,
49    pub toc_url: String,
50    pub word_count: String,
51}
52
53/// 搜索/浏览结果中的一本书(书籍详情 + 入口 URL)。
54#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
55pub struct BookListItem {
56    #[serde(flatten)]
57    pub info: BookInfo,
58    pub book_url: String,
59}
60
61/// 搜索/浏览**一页**的结果:书列表 + 可选边界信号。`explore`/`search` 的返回类型。
62///
63/// - `total_pages`(`render-dual-source`):精确总页数,进度「第 N / M 页」;
64/// - `has_more`(`list-has-more`):是否还有下一页,UI 据此到头停翻。
65///
66/// 二者书源未配或取不到则为 `None`(UI 不限制 / 不显示)。
67#[derive(Debug, Clone, Default, PartialEq, Eq)]
68pub struct BookList {
69    pub items: Vec<BookListItem>,
70    pub total_pages: Option<u32>,
71    pub has_more: Option<bool>,
72}
73
74impl BookList {
75    /// 仅书列表、无边界信号(非 render / 未配规则的现状路径)。
76    pub fn new(items: Vec<BookListItem>) -> Self {
77        Self {
78            items,
79            total_pages: None,
80            has_more: None,
81        }
82    }
83}