1use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
2use serde::{ Deserialize, Serialize };
3
4#[derive(Debug, Clone, Deserialize, Serialize)]
6pub struct NoteListArchiveData {
7 #[serde(rename = "noteIds")]
9 pub note_ids: Option<Vec<String>>,
10}
11
12#[derive(Debug, Clone, Deserialize, Serialize)]
16pub struct PrivateNoteArc {
17 pub oid: u64,
18 pub status: u8,
19 pub oid_type: u8,
20 pub aid: u64,
21
22 pub bvid: Option<String>,
24 pub pic: Option<String>,
25 pub desc: Option<String>,
26}
27
28#[derive(Debug, Clone, Deserialize, Serialize)]
30pub struct PrivateNoteItem {
31 pub title: String,
32 pub summary: String,
33 pub mtime: String,
34 pub arc: PrivateNoteArc,
35 pub note_id: u64,
36 pub audit_status: u8,
37 pub web_url: String,
38 pub note_id_str: String,
39 pub message: String,
40 pub forbid_note_entrance: Option<bool>,
41 pub likes: u64,
42 pub has_like: bool,
43}
44
45#[derive(Debug, Clone, Deserialize, Serialize)]
47pub struct PrivateNoteListData {
48 pub list: Option<Vec<PrivateNoteItem>>,
49 pub page: Option<NotePage>,
50}
51
52#[derive(Debug, Clone, Deserialize, Serialize)]
56pub struct PublicNoteAuthor {
57 pub mid: u64,
58 pub name: String,
59 pub face: String,
60 pub level: u8,
61 pub vip_info: serde_json::Value,
62 pub pendant: serde_json::Value,
63}
64
65#[derive(Debug, Clone, Deserialize, Serialize)]
67pub struct PublicNoteItem {
68 pub cvid: u64,
69 pub title: String,
70 pub summary: String,
71 pub pubtime: String,
72 pub web_url: String,
73 pub message: String,
74 pub author: PublicNoteAuthor,
75 pub likes: u64,
76 pub has_like: bool,
77}
78
79#[derive(Debug, Clone, Deserialize, Serialize)]
81pub struct NotePage {
82 pub total: u32,
83 pub size: u32,
84 pub num: u32,
85}
86
87#[derive(Debug, Clone, Deserialize, Serialize)]
89pub struct PublicNoteListArchiveData {
90 pub list: Option<Vec<PublicNoteItem>>,
91 pub page: Option<NotePage>,
92 pub show_public_note: bool,
93 pub message: String,
94}
95
96#[derive(Debug, Clone, Deserialize, Serialize)]
100pub struct PublicNoteListUserData {
101 pub list: Option<Vec<PublicNoteItem>>,
102 pub page: Option<NotePage>,
103}
104
105impl BpiClient {
106 pub async fn note_list_archive(
114 &self,
115 oid: u64
116 ) -> Result<BpiResponse<NoteListArchiveData>, BpiError> {
117 self
118 .get("https://api.bilibili.com/x/note/list/archive")
119 .query(
120 &[
121 ("oid", oid),
122 ("oid_type", 0),
123 ]
124 )
125 .send_bpi("查询稿件私有笔记").await
126 }
127
128 pub async fn note_list_user_private(
140 &self,
141 pn: u32,
142 ps: u32
143 ) -> Result<BpiResponse<PrivateNoteListData>, BpiError> {
144 self
145 .get("https://api.bilibili.com/x/note/list")
146 .query(
147 &[
148 ("pn", pn),
149 ("ps", ps),
150 ]
151 )
152 .send_bpi("查询用户私有笔记").await
153 }
154
155 pub async fn note_list_public_archive(
168 &self,
169 oid: u64,
170 pn: u32,
171 ps: u32
172 ) -> Result<BpiResponse<PublicNoteListArchiveData>, BpiError> {
173 self
174 .get("https://api.bilibili.com/x/note/publish/list/archive")
175 .query(
176 &[
177 ("oid", oid.to_string()),
178 ("oid_type", (0).to_string()),
179 ("pn", pn.to_string()),
180 ("ps", ps.to_string()),
181 ]
182 )
183 .send_bpi("查询稿件公开笔记").await
184 }
185
186 pub async fn note_list_public_user(
198 &self,
199 pn: u32,
200 ps: u32
201 ) -> Result<BpiResponse<PublicNoteListUserData>, BpiError> {
202 self
203 .get("https://api.bilibili.com/x/note/publish/list/user")
204 .query(
205 &[
206 ("pn", pn),
207 ("ps", ps),
208 ]
209 )
210 .send_bpi("查询用户公开笔记").await
211 }
212}
213
214#[cfg(test)]
215mod tests {
216 use super::*;
217 use tracing::info;
218
219 #[tokio::test]
220 async fn test_note_list_archive() {
221 let bpi = BpiClient::new();
222 let oid = 676931260;
224 let resp = bpi.note_list_archive(oid).await;
225
226 info!("{:?}", resp);
227 assert!(resp.is_ok());
228
229 let resp_data = resp.unwrap();
230 info!("code: {}", resp_data.code);
231 if let Some(data) = resp_data.data {
232 info!("note ids: {:?}", data.note_ids);
233 }
234 }
235
236 #[tokio::test]
237 async fn test_note_list_user_private() {
238 let bpi = BpiClient::new();
239 let resp = bpi.note_list_user_private(1, 10).await;
240
241 info!("{:?}", resp);
242 assert!(resp.is_ok());
243
244 let resp_data = resp.unwrap();
245 resp_data.data
246 .as_ref()
247 .and_then(|data| data.list.as_ref())
248 .and_then(|list| {
249 info!("first note item: {:?}", list.first());
250 Some(())
251 });
252 }
253
254 #[tokio::test]
255 async fn test_note_list_public_archive() {
256 let bpi = BpiClient::new();
257 let oid = 338677252;
259 let resp = bpi.note_list_public_archive(oid, 1, 10).await;
260
261 info!("{:?}", resp);
262 assert!(resp.is_ok());
263
264 let resp_data = resp.unwrap();
265 info!("code: {}", resp_data.code);
266 if let Some(data) = resp_data.data {
267 info!("show_public_note: {}", data.show_public_note);
268 }
269 }
270
271 #[tokio::test]
272 async fn test_note_list_public_user() {
273 let bpi = BpiClient::new();
274 let resp = bpi.note_list_public_user(1, 10).await;
275
276 info!("{:?}", resp);
277 assert!(resp.is_ok());
278
279 let resp_data = resp.unwrap();
280 info!("code: {}", resp_data.code);
281 if let Some(data) = resp_data.data {
282 info!("total public notes: {}", data.page.as_ref().unwrap().total);
283 }
284 }
285}