1
+ use crate :: infra:: http:: { body_or_err, RequestBuilderExt } ;
2
+ use crate :: infra:: json;
3
+ use crate :: infra:: result:: IntoResult ;
4
+ use crate :: openapi;
5
+ use anyhow:: Result ;
6
+ use serde:: { Deserialize , Serialize } ;
7
+ use crate :: api:: post:: Post ;
8
+ use crate :: api:: user:: User ;
9
+
10
+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
11
+ pub struct PostCommentEntry {
12
+ #[ serde( rename = "Id" ) ]
13
+ pub id : usize ,
14
+ #[ serde( rename = "Body" ) ]
15
+ pub content : String ,
16
+ #[ serde( rename = "Author" ) ]
17
+ pub user_name : String ,
18
+ #[ serde( rename = "AuthorUrl" ) ]
19
+ pub user_home_url : String ,
20
+ #[ serde( rename = "FaceUrl" ) ]
21
+ pub avatar_url : String ,
22
+ #[ serde( rename = "Floor" ) ]
23
+ pub floor : usize ,
24
+ #[ serde( rename = "DateAdded" ) ]
25
+ pub create_time : String ,
26
+ }
27
+
28
+ impl Post {
29
+ pub async fn get_comment_list ( & self , post_id : usize ) -> Result < Vec < PostCommentEntry > > {
30
+ let blog_app = User :: new ( self . pat . to_owned ( ) ) . get_info ( ) . await ?. blog_app ;
31
+ let client = reqwest:: Client :: new ( ) ;
32
+
33
+ let req = {
34
+ let url = openapi ! ( "https://api.cnblogs.com/api/blogs/{}/posts/{}/comments" , blog_app, post_id) ;
35
+ client. get ( url) . pat_auth ( & self . pat )
36
+ } ;
37
+ let resp = req. send ( ) . await ?;
38
+
39
+ let entry_vec = {
40
+ let body = body_or_err ( resp) . await ?;
41
+ json:: deserialize :: < Vec < PostCommentEntry > > ( & body) ?
42
+ } ;
43
+
44
+ entry_vec. into_ok ( )
45
+ }
46
+ }
0 commit comments