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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
use std::path::Path;
use async_trait::async_trait;
use chrono::NaiveDateTime;
use image::DynamicImage;
use url::Url;
use crate::Error;
#[must_use]
#[derive(Debug)]
pub struct UserInfo {
pub nickname: String,
}
#[must_use]
#[derive(Debug, Default)]
pub struct NovelInfo {
pub id: u32,
pub name: String,
pub author_name: String,
pub cover_url: Option<Url>,
pub introduction: Option<Vec<String>>,
pub word_count: Option<u32>,
pub finished: Option<bool>,
pub create_time: Option<NaiveDateTime>,
pub update_time: Option<NaiveDateTime>,
pub genre: Option<String>,
pub tags: Option<Vec<Tag>>,
}
impl PartialEq for NovelInfo {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
#[must_use]
#[derive(Debug)]
pub struct Tag {
pub id: Option<u16>,
pub name: String,
}
pub type VolumeInfos = Vec<VolumeInfo>;
#[must_use]
#[derive(Debug)]
pub struct VolumeInfo {
pub id: Option<u32>,
pub title: String,
pub chapter_infos: Vec<ChapterInfo>,
}
#[must_use]
#[derive(Debug)]
pub struct ChapterInfo {
pub identifier: Identifier,
pub title: String,
pub is_vip: Option<bool>,
pub accessible: Option<bool>,
pub is_valid: Option<bool>,
pub word_count: Option<u16>,
pub update_time: Option<NaiveDateTime>,
}
#[must_use]
#[derive(Debug)]
pub enum Identifier {
Id(u32),
Url(Url),
}
impl ToString for Identifier {
fn to_string(&self) -> String {
match self {
Identifier::Id(id) => id.to_string(),
Identifier::Url(url) => url.to_string(),
}
}
}
pub type ContentInfos = Vec<ContentInfo>;
#[must_use]
#[derive(Debug)]
pub enum ContentInfo {
Text(String),
Image(Url),
}
#[async_trait]
pub trait Client {
fn proxy(&mut self, proxy: Url);
fn no_proxy(&mut self);
fn cert<T>(&mut self, cert_path: T)
where
T: AsRef<Path>;
async fn add_cookie(&self, cookie_str: &str, url: &Url) -> Result<(), Error>;
async fn login<T, E>(&self, username: T, password: E) -> Result<(), Error>
where
T: AsRef<str> + Send + Sync,
E: AsRef<str> + Send + Sync;
async fn user_info(&self) -> Result<Option<UserInfo>, Error>;
async fn novel_info(&self, id: u32) -> Result<Option<NovelInfo>, Error>;
async fn volume_infos(&self, id: u32) -> Result<VolumeInfos, Error>;
async fn content_infos(&self, info: &ChapterInfo) -> Result<ContentInfos, Error>;
async fn image_info(&self, url: &Url) -> Result<DynamicImage, Error>;
async fn search_infos<T>(&self, text: T, page: u16, size: u16) -> Result<Vec<u32>, Error>
where
T: AsRef<str> + Send + Sync;
async fn favorite_infos(&self) -> Result<Vec<u32>, Error>;
}