Replaced custom structs in favor of github tag version, removed unused dependencies

This commit is contained in:
Neshura 2023-12-19 22:08:23 +01:00
parent 9fa940f385
commit 5084da92fb
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
3 changed files with 22 additions and 163 deletions

View file

@ -1,13 +1,14 @@
use std::collections::HashMap;
use std::sync::{Arc};
use chrono::{DateTime, Duration, Timelike, Utc};
use lemmy_api_common::post::CreatePost;
use lemmy_db_schema::newtypes::{CommunityId, LanguageId};
use lemmy_db_schema::PostFeatureType;
use tokio::sync::{RwLock};
use crate::{jnovel, lemmy, Message, SharedData};
use crate::config::{Config, PostBody, SeriesConfig};
use crate::jnovel::PostInfo;
use crate::lemmy::{CustomCreatePost, Lemmy};
use crate::lemmy::{Lemmy};
use crate::post_history::SeriesHistory;
use tokio::time::sleep;
@ -231,7 +232,7 @@ async fn handle_series(
PostBody::Custom(text) => Some(text.clone()),
};
let post_data = CustomCreatePost {
let post_data = CreatePost {
name: post_lemmy_info.title,
community_id,
url: Some(post_lemmy_info.url),

View file

@ -1,15 +1,14 @@
use std::collections::HashMap;
use std::env;
use std::env::VarError;
use lemmy_api_common::community::{ListCommunities};
use lemmy_api_common::community::{ListCommunities, ListCommunitiesResponse};
use lemmy_api_common::lemmy_db_views::structs::PostView;
use lemmy_api_common::person::{Login, LoginResponse};
use lemmy_api_common::post::{GetPosts};
use lemmy_api_common::post::{CreatePost, FeaturePost, GetPosts, GetPostsResponse};
use lemmy_api_common::sensitive::Sensitive;
use lemmy_db_schema::newtypes::{CommunityId, InstanceId, LanguageId, PersonId, PostId};
use lemmy_db_schema::{ListingType, PostFeatureType, SubscribedType};
use lemmy_db_schema::newtypes::{CommunityId, PostId};
use lemmy_db_schema::{ListingType, PostFeatureType};
use reqwest::StatusCode;
use serde_derive::{Deserialize, Serialize};
use url::Url;
use crate::HTTP_CLIENT;
pub(crate) struct Credentials {
@ -73,7 +72,7 @@ pub(crate) async fn login(credentials: &Credentials, instance: &str) -> Result<L
}
impl Lemmy {
pub(crate) async fn post(&self, post: CustomCreatePost) -> Result<PostId, String> {
pub(crate) async fn post(&self, post: CreatePost) -> Result<PostId, String> {
let response = match HTTP_CLIENT
.post(format!("{}/api/v3/post", &self.instance))
.bearer_auth(&self.jwt_token.to_string())
@ -89,7 +88,7 @@ impl Lemmy {
Err(e) => return Err(format!("{}", e))
};
let json_data = match serde_json::from_str::<HashMap<&str, CustomPostView>>(&response) {
let json_data = match serde_json::from_str::<HashMap<&str, PostView>>(&response) {
Ok(mut data) => data.remove("post_view").expect("Element should be present"),
Err(e) => return Err(format!("{}", e))
};
@ -97,7 +96,7 @@ impl Lemmy {
Ok(json_data.post.id)
}
async fn feature(&self, params: CustomFeaturePost) -> Result<CustomPostView, String> {
async fn feature(&self, params: FeaturePost) -> Result<PostView, String> {
let response = match HTTP_CLIENT
.post(format!("{}/api/v3/post/feature", &self.instance))
.bearer_auth(&self.jwt_token.to_string())
@ -113,7 +112,7 @@ impl Lemmy {
Err(e) => return Err(format!("{}", e))
};
let json_data = match serde_json::from_str::<HashMap<&str, CustomPostView>>(&response) {
let json_data = match serde_json::from_str::<HashMap<&str, PostView>>(&response) {
Ok(mut data) => data.remove("post_view").expect("Element should be present"),
Err(e) => return Err(format!("{}", e))
};
@ -121,8 +120,8 @@ impl Lemmy {
Ok(json_data)
}
pub(crate) async fn unpin(&self, post_id: PostId, location: PostFeatureType) -> Result<CustomPostView, String> {
let pin_params = CustomFeaturePost {
pub(crate) async fn unpin(&self, post_id: PostId, location: PostFeatureType) -> Result<PostView, String> {
let pin_params = FeaturePost {
post_id,
featured: false,
feature_type: location,
@ -130,8 +129,8 @@ impl Lemmy {
self.feature(pin_params).await
}
pub(crate) async fn pin(&self, post_id: PostId, location: PostFeatureType) -> Result<CustomPostView, String> {
let pin_params = CustomFeaturePost {
pub(crate) async fn pin(&self, post_id: PostId, location: PostFeatureType) -> Result<PostView, String> {
let pin_params = FeaturePost {
post_id,
featured: true,
feature_type: location,
@ -139,7 +138,7 @@ impl Lemmy {
self.feature(pin_params).await
}
pub(crate) async fn get_community_pinned(&self, community: CommunityId) -> Result<Vec<CustomPostView>, String> {
pub(crate) async fn get_community_pinned(&self, community: CommunityId) -> Result<Vec<PostView>, String> {
let list_params = GetPosts {
community_id: Some(community),
type_: Some(ListingType::Local),
@ -161,7 +160,7 @@ impl Lemmy {
Err(e) => return Err(format!("{}", e))
};
let json_data: CustomGetPostsResponse = match serde_json::from_str(&response) {
let json_data: GetPostsResponse = match serde_json::from_str(&response) {
Ok(data) => data,
Err(e) => return Err(format!("{}", e))
};
@ -174,7 +173,7 @@ impl Lemmy {
)
}
pub(crate) async fn get_local_pinned(&self) -> Result<Vec<CustomPostView>, String> {
pub(crate) async fn get_local_pinned(&self) -> Result<Vec<PostView>, String> {
let list_params = GetPosts {
type_: Some(ListingType::Local),
..Default::default()
@ -195,7 +194,7 @@ impl Lemmy {
Err(e) => return Err(format!("{}", e))
};
let json_data: CustomGetPostsResponse = match serde_json::from_str(&response) {
let json_data: GetPostsResponse = match serde_json::from_str(&response) {
Ok(data) => data,
Err(e) => return Err(format!("{}", e))
};
@ -229,7 +228,7 @@ impl Lemmy {
Err(e) => return Err(format!("{}", e))
};
let json_data: CustomListCommunitiesResponse = match serde_json::from_str(&response) {
let json_data: ListCommunitiesResponse = match serde_json::from_str(&response) {
Ok(data) => data,
Err(e) => return Err(format!("{}", e))
};
@ -243,144 +242,3 @@ impl Lemmy {
Ok(communities)
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub(crate) struct CustomCreatePost {
pub(crate) name: String,
pub(crate) community_id: CommunityId,
pub(crate) url: Option<Url>,
pub(crate) body: Option<String>,
pub(crate) honeypot: Option<String>,
pub(crate) nsfw: Option<bool>,
pub(crate) language_id: Option<LanguageId>,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub(crate) struct CustomFeaturePost {
pub(crate) post_id: PostId,
pub(crate) featured: bool,
pub(crate) feature_type: PostFeatureType,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub(crate) struct CustomListCommunitiesResponse {
pub(crate) communities: Vec<CustomCommunityView>
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct CustomCommunityView {
pub(crate) community: CustomCommunity,
pub(crate) subscribed: SubscribedType,
pub(crate) blocked: bool,
pub(crate) counts: CustomCommunityAggregates
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct CustomCommunity {
pub(crate) actor_id: String,
pub(crate) banner: Option<String>,
pub(crate) deleted: bool,
pub(crate) description: Option<String>,
pub(crate) hidden: bool,
pub(crate) icon: Option<String>,
pub(crate) id: CommunityId,
pub(crate) instance_id: i32,
pub(crate) local: bool,
pub(crate) name: String,
pub(crate) nsfw: bool,
pub(crate) posting_restricted_to_mods: bool,
pub(crate) published: String,
pub(crate) removed: bool,
pub(crate) title: String,
pub(crate) updated: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct CustomCommunityAggregates {
pub(crate) comments: i64,
pub(crate) community_id: i32,
pub(crate) posts: i64,
pub(crate) published: String,
pub(crate) subscribers: i64,
pub(crate) users_active_day: i64,
pub(crate) users_active_half_year: i64,
pub(crate) users_active_month: i64,
pub(crate) users_active_week: i64,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct CustomPostView {
pub(crate) community: CustomCommunity,
pub(crate) counts: CustomPostAggregates,
pub(crate) creator: CustomPerson,
pub(crate) creator_banned_from_community: bool,
pub(crate) creator_blocked: bool,
pub(crate) creator_is_admin: bool,
pub(crate) creator_is_moderator: bool,
pub(crate) my_vote: Option<i16>,
pub(crate) post: CustomPost,
pub(crate) read: bool,
pub(crate) saved: bool,
pub(crate) subscribed: SubscribedType,
pub(crate) unread_comments: i64,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct CustomPostAggregates {
pub(crate) comments: i64,
pub(crate) downvotes: i64,
pub(crate) post_id: PostId,
pub(crate) published: String,
pub(crate) score: i64,
pub(crate) upvotes: i64,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct CustomPerson {
pub(crate) actor_id: String,
pub(crate) avatar: Option<String>,
pub(crate) ban_expires: Option<String>,
pub(crate) banned: bool,
pub(crate) banner: Option<String>,
pub(crate) bio: Option<String>,
pub(crate) bot_account: bool,
pub(crate) deleted: bool,
pub(crate) display_name: Option<String>,
pub(crate) id: PersonId,
pub(crate) instance_id : InstanceId,
pub(crate) local: bool,
pub(crate) matrix_user_id: Option<String>,
pub(crate) name: String,
pub(crate) published: String,
pub(crate) updated: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct CustomPost {
pub(crate) id: PostId,
pub(crate) name: String,
pub(crate) url: Option<String>,
pub(crate) body: Option<String>,
pub(crate) creator_id: PersonId,
pub(crate) community_id: CommunityId,
pub(crate) removed: bool,
pub(crate) locked: bool,
pub(crate) published: String,
pub(crate) updated: Option<String>,
pub(crate) deleted: bool,
pub(crate) nsfw: bool,
pub(crate) embed_title: Option<String>,
pub(crate) embed_description: Option<String>,
pub(crate) thumbnail_url: Option<String>,
pub(crate) ap_id: String,
pub(crate) local: bool,
pub(crate) embed_video_url: Option<String>,
pub(crate) language_id: LanguageId,
pub(crate) featured_community: bool,
pub(crate) featured_local: bool,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub(crate) struct CustomGetPostsResponse {
pub(crate) posts: Vec<CustomPostView>,
}

View file

@ -1,6 +1,6 @@
use std::ops::Deref;
use std::sync::{Arc};
use chrono::{Duration, Local, Utc};
use chrono::{Duration, Local};
use tokio::sync::{RwLock, RwLockReadGuard};
use tokio::time::sleep;
use crate::{SharedData};