X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fapi_common%2Fsrc%2Fsite.rs;h=a5b2afae297fccc7270210bbc7055fe99456751e;hb=HEAD;hp=99c7b4e8eb3cd6218040b594a91f4a278bd0058a;hpb=3053e14be7a47675b621e1c80aa88f4f0a5ce1ae;p=lemmy.git diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 99c7b4e8..a5b2afae 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -1,41 +1,32 @@ use crate::sensitive::Sensitive; use lemmy_db_schema::{ - newtypes::{CommunityId, PersonId}, - ListingType, - SearchType, - SortType, + newtypes::{CommentId, CommunityId, LanguageId, PersonId, PostId}, + source::{instance::Instance, language::Language, tagline::Tagline}, + ListingType, ModlogActionType, RegistrationMode, SearchType, SortType, }; use lemmy_db_views::structs::{ - CommentView, - LocalUserSettingsView, - PostView, - RegistrationApplicationView, - SiteView, + CommentView, CustomEmojiView, LocalUserView, PostView, RegistrationApplicationView, SiteView, }; use lemmy_db_views_actor::structs::{ - CommunityBlockView, - CommunityFollowerView, - CommunityModeratorView, - CommunityView, - PersonBlockView, - PersonViewSafe, + CommunityBlockView, CommunityFollowerView, CommunityModeratorView, CommunityView, + PersonBlockView, PersonView, }; use lemmy_db_views_moderator::structs::{ - ModAddCommunityView, - ModAddView, - ModBanFromCommunityView, - ModBanView, - ModHideCommunityView, - ModLockPostView, - ModRemoveCommentView, - ModRemoveCommunityView, - ModRemovePostView, - ModStickyPostView, - ModTransferCommunityView, + AdminPurgeCommentView, AdminPurgeCommunityView, AdminPurgePersonView, AdminPurgePostView, + ModAddCommunityView, ModAddView, ModBanFromCommunityView, ModBanView, ModFeaturePostView, + ModHideCommunityView, ModLockPostView, ModRemoveCommentView, ModRemoveCommunityView, + ModRemovePostView, ModTransferCommunityView, }; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; +#[cfg(feature = "full")] +use ts_rs::TS; +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Searches the site, given a query string, and some optional filters. pub struct Search { pub q: String, pub community_id: Option, @@ -50,42 +41,65 @@ pub struct Search { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The search response, containing lists of the return type possibilities +// TODO this should be redone as a list of tagged enums pub struct SearchResponse { - pub type_: String, + pub type_: SearchType, pub comments: Vec, pub posts: Vec, pub communities: Vec, - pub users: Vec, + pub users: Vec, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Does an apub fetch for an object. pub struct ResolveObject { + /// Can be the full url, or a shortened version like: !fediverse@lemmy.ml pub q: String, pub auth: Option>, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +// TODO Change this to an enum +/// The response of an apub object fetch. pub struct ResolveObjectResponse { pub comment: Option, pub post: Option, pub community: Option, - pub person: Option, + pub person: Option, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Fetches the modlog. pub struct GetModlog { pub mod_person_id: Option, pub community_id: Option, pub page: Option, pub limit: Option, + pub type_: Option, + pub other_person_id: Option, pub auth: Option>, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The modlog fetch response. +// TODO this should be redone as a list of tagged enums pub struct GetModlogResponse { pub removed_posts: Vec, pub locked_posts: Vec, - pub stickied_posts: Vec, + pub featured_posts: Vec, pub removed_comments: Vec, pub removed_communities: Vec, pub banned_from_community: Vec, @@ -93,10 +107,18 @@ pub struct GetModlogResponse { pub added_to_community: Vec, pub transferred_to_community: Vec, pub added: Vec, + pub admin_purged_persons: Vec, + pub admin_purged_communities: Vec, + pub admin_purged_posts: Vec, + pub admin_purged_comments: Vec, pub hidden_communities: Vec, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Creates a site. Should be done after first running lemmy. pub struct CreateSite { pub name: String, pub sidebar: Option, @@ -104,128 +126,315 @@ pub struct CreateSite { pub icon: Option, pub banner: Option, pub enable_downvotes: Option, - pub open_registration: Option, + pub enable_federated_downvotes: Option, pub enable_nsfw: Option, pub community_creation_admin_only: Option, pub require_email_verification: Option, - pub require_application: Option, pub application_question: Option, pub private_instance: Option, pub default_theme: Option, - pub default_post_listing_type: Option, + pub default_post_listing_type: Option, + pub legal_information: Option, + pub application_email_admins: Option, + pub hide_modlog_mod_names: Option, + pub discussion_languages: Option>, + pub slur_filter_regex: Option, + pub actor_name_max_length: Option, + pub rate_limit_message: Option, + pub rate_limit_message_per_second: Option, + pub rate_limit_post: Option, + pub rate_limit_post_per_second: Option, + pub rate_limit_register: Option, + pub rate_limit_register_per_second: Option, + pub rate_limit_image: Option, + pub rate_limit_image_per_second: Option, + pub rate_limit_comment: Option, + pub rate_limit_comment_per_second: Option, + pub rate_limit_search: Option, + pub rate_limit_search_per_second: Option, + pub federation_enabled: Option, + pub federation_debug: Option, + pub captcha_enabled: Option, + pub captcha_difficulty: Option, + pub allowed_instances: Option>, + pub blocked_instances: Option>, + pub taglines: Option>, + pub registration_mode: Option, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Edits a site. pub struct EditSite { pub name: Option, pub sidebar: Option, + /// A shorter, one line description of your site. pub description: Option, + /// A url for your site's icon. pub icon: Option, + /// A url for your site's banner. pub banner: Option, + /// Whether to enable downvotes. pub enable_downvotes: Option, - pub open_registration: Option, + /// Whether to allow downvotes from federated sites. + pub enable_federated_downvotes: Option, + /// Whether to enable NSFW. pub enable_nsfw: Option, + /// Limits community creation to admins only. pub community_creation_admin_only: Option, + /// Whether to require email verification. pub require_email_verification: Option, - pub require_application: Option, + /// Your application question form. This is in markdown, and can be many questions. pub application_question: Option, + /// Whether your instance is public, or private. pub private_instance: Option, + /// The default theme. Usually "browser" pub default_theme: Option, - pub default_post_listing_type: Option, + pub default_post_listing_type: Option, + /// An optional page of legal information + pub legal_information: Option, + /// Whether to email admins when receiving a new application. + pub application_email_admins: Option, + /// Whether to hide moderator names from the modlog. + pub hide_modlog_mod_names: Option, + /// A list of allowed discussion languages. + pub discussion_languages: Option>, + /// A regex string of items to filter. + pub slur_filter_regex: Option, + /// The max length of actor names. + pub actor_name_max_length: Option, + /// The number of messages allowed in a given time frame. + pub rate_limit_message: Option, + pub rate_limit_message_per_second: Option, + /// The number of posts allowed in a given time frame. + pub rate_limit_post: Option, + pub rate_limit_post_per_second: Option, + /// The number of registrations allowed in a given time frame. + pub rate_limit_register: Option, + pub rate_limit_register_per_second: Option, + /// The number of image uploads allowed in a given time frame. + pub rate_limit_image: Option, + pub rate_limit_image_per_second: Option, + /// The number of comments allowed in a given time frame. + pub rate_limit_comment: Option, + pub rate_limit_comment_per_second: Option, + /// The number of searches allowed in a given time frame. + pub rate_limit_search: Option, + pub rate_limit_search_per_second: Option, + /// Whether to enable federation. + pub federation_enabled: Option, + /// Enables federation debugging. + pub federation_debug: Option, + /// Whether to enable captchas for signups. + pub captcha_enabled: Option, + /// The captcha difficulty. Can be easy, medium, or hard + pub captcha_difficulty: Option, + /// A list of allowed instances. If none are set, federation is open. + pub allowed_instances: Option>, + /// A list of blocked instances. + pub blocked_instances: Option>, + /// A list of taglines shown at the top of the front page. + pub taglines: Option>, + pub registration_mode: Option, + /// Whether to email admins for new reports. + pub reports_email_admins: Option, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Fetches the site. pub struct GetSite { pub auth: Option>, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The response for a site. pub struct SiteResponse { pub site_view: SiteView, + pub taglines: Vec, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// An expanded response for a site. pub struct GetSiteResponse { - pub site_view: Option, // Because the site might not be set up yet - pub admins: Vec, - pub online: usize, + pub site_view: SiteView, + pub admins: Vec, pub version: String, pub my_user: Option, - pub federated_instances: Option, // Federation may be disabled + pub all_languages: Vec, + pub discussion_languages: Vec, + /// A list of taglines shown at the top of the front page. + pub taglines: Vec, + /// A list of custom emojis your site supports. + pub custom_emojis: Vec, +} + +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Fetches the federated instances for your site. +pub struct GetFederatedInstances { + pub auth: Option>, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// A response of federated instances. +pub struct GetFederatedInstancesResponse { + /// Optional, because federation may be disabled. + pub federated_instances: Option, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Your user info. pub struct MyUserInfo { - pub local_user_view: LocalUserSettingsView, + pub local_user_view: LocalUserView, pub follows: Vec, pub moderates: Vec, pub community_blocks: Vec, pub person_blocks: Vec, + pub discussion_languages: Vec, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Leaves the admin team. pub struct LeaveAdmin { pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] -pub struct GetSiteConfig { +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// A list of federated instances. +pub struct FederatedInstances { + pub linked: Vec, + pub allowed: Vec, + pub blocked: Vec, +} + +#[skip_serializing_none] +#[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Purges a person from the database. This will delete all content attached to that person. +pub struct PurgePerson { + pub person_id: PersonId, + pub reason: Option, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -pub struct GetSiteConfigResponse { - pub config_hjson: String, +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Purges a community from the database. This will delete all content attached to that community. +pub struct PurgeCommunity { + pub community_id: CommunityId, + pub reason: Option, + pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -pub struct SaveSiteConfig { - pub config_hjson: String, +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Purges a post from the database. This will delete all content attached to that post. +pub struct PurgePost { + pub post_id: PostId, + pub reason: Option, pub auth: Sensitive, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone)] -pub struct FederatedInstances { - pub linked: Vec, - pub allowed: Option>, - pub blocked: Option>, +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Purges a comment from the database. This will delete all content attached to that comment. +pub struct PurgeComment { + pub comment_id: CommentId, + pub reason: Option, + pub auth: Sensitive, } +#[derive(Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The response for purged items. +pub struct PurgeItemResponse { + pub success: bool, +} + +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Fetches a list of registration applications. pub struct ListRegistrationApplications { /// Only shows the unread applications (IE those without an admin actor) pub unread_only: Option, pub page: Option, pub limit: Option, - pub auth: String, + pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The list of registration applications. pub struct ListRegistrationApplicationsResponse { pub registration_applications: Vec, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Approves a registration application. pub struct ApproveRegistrationApplication { pub id: i32, pub approve: bool, pub deny_reason: Option, - pub auth: String, + pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The response of an action done to a registration application. pub struct RegistrationApplicationResponse { pub registration_application: RegistrationApplicationView, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// Gets a count of unread registration applications. pub struct GetUnreadRegistrationApplicationCount { - pub auth: String, + pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] +#[cfg_attr(feature = "full", derive(TS))] +#[cfg_attr(feature = "full", ts(export))] +/// The count of unread registration applications. pub struct GetUnreadRegistrationApplicationCountResponse { pub registration_applications: i64, }