This commit is contained in:
parent
3b5e65b350
commit
da4220e027
1 changed files with 25 additions and 8 deletions
33
src/lemmy.rs
33
src/lemmy.rs
|
@ -23,6 +23,15 @@ macro_rules! debug {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! info {
|
||||
($msg:tt) => {
|
||||
match connected_to_journal() {
|
||||
true => log::info!("[INFO] {}", $msg),
|
||||
false => println!("[INFO] {}", $msg),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! error {
|
||||
($msg:tt) => {
|
||||
match connected_to_journal() {
|
||||
|
@ -397,24 +406,32 @@ impl Lemmy {
|
|||
|
||||
let response: String = match self.get_data_query("/api/v3/post/list", &get_params).await {
|
||||
Some(data) => data,
|
||||
None => return None,
|
||||
None => {
|
||||
error!("Unable to query post list");
|
||||
return None
|
||||
},
|
||||
};
|
||||
let json_data: GetPostsResponse = match self.parse_json(&response).await {
|
||||
Some(data) => data,
|
||||
None => return None,
|
||||
None => {
|
||||
error!("Unable to parse post data");
|
||||
return None
|
||||
},
|
||||
};
|
||||
|
||||
if json_data.posts[0].post.name == post.name {
|
||||
Some(json_data.posts[0].post.id)
|
||||
} else {
|
||||
None
|
||||
for api_post in json_data.posts {
|
||||
if api_post.post.name == post.name {
|
||||
return Some(api_post.post.id);
|
||||
}
|
||||
}
|
||||
info!("Unable to find post {}", post.name);
|
||||
None
|
||||
}
|
||||
|
||||
async fn post_data_json<T: Serialize>(&self, route: &str, json: &T ) -> Option<String> {
|
||||
let res = HTTP_CLIENT
|
||||
.post(format!("{}{route}", &self.instance))
|
||||
.bearer_auth(&self.jwt_token.to_string())
|
||||
.bearer_auth(self.jwt_token.to_string())
|
||||
.json(&json)
|
||||
.send()
|
||||
.await;
|
||||
|
@ -424,7 +441,7 @@ impl Lemmy {
|
|||
async fn get_data_query<T: Serialize>(&self, route: &str, param: &T ) -> Option<String> {
|
||||
let res = HTTP_CLIENT
|
||||
.get(format!("{}{route}", &self.instance))
|
||||
.bearer_auth(&self.jwt_token.to_string())
|
||||
.bearer_auth(self.jwt_token.to_string())
|
||||
.query(¶m)
|
||||
.send()
|
||||
.await;
|
||||
|
|
Loading…
Add table
Reference in a new issue