]> Untitled Git - lemmy.git/blob - crates/api_common/src/site.rs
Adding typescript generation for API. Fixes #2824 (#2827)
[lemmy.git] / crates / api_common / src / site.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommentId, CommunityId, LanguageId, PersonId, PostId},
4   source::{instance::Instance, language::Language, tagline::Tagline},
5   ListingType,
6   ModlogActionType,
7   RegistrationMode,
8   SearchType,
9   SortType,
10 };
11 use lemmy_db_views::structs::{
12   CommentView,
13   CustomEmojiView,
14   LocalUserView,
15   PostView,
16   RegistrationApplicationView,
17   SiteView,
18 };
19 use lemmy_db_views_actor::structs::{
20   CommunityBlockView,
21   CommunityFollowerView,
22   CommunityModeratorView,
23   CommunityView,
24   PersonBlockView,
25   PersonView,
26 };
27 use lemmy_db_views_moderator::structs::{
28   AdminPurgeCommentView,
29   AdminPurgeCommunityView,
30   AdminPurgePersonView,
31   AdminPurgePostView,
32   ModAddCommunityView,
33   ModAddView,
34   ModBanFromCommunityView,
35   ModBanView,
36   ModFeaturePostView,
37   ModHideCommunityView,
38   ModLockPostView,
39   ModRemoveCommentView,
40   ModRemoveCommunityView,
41   ModRemovePostView,
42   ModTransferCommunityView,
43 };
44 use serde::{Deserialize, Serialize};
45 use serde_with::skip_serializing_none;
46 #[cfg(feature = "full")]
47 use ts_rs::TS;
48
49 #[skip_serializing_none]
50 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
51 #[cfg_attr(feature = "full", derive(TS))]
52 #[cfg_attr(feature = "full", ts(export))]
53 pub struct Search {
54   pub q: String,
55   pub community_id: Option<CommunityId>,
56   pub community_name: Option<String>,
57   pub creator_id: Option<PersonId>,
58   pub type_: Option<SearchType>,
59   pub sort: Option<SortType>,
60   pub listing_type: Option<ListingType>,
61   pub page: Option<i64>,
62   pub limit: Option<i64>,
63   pub auth: Option<Sensitive<String>>,
64 }
65
66 #[derive(Debug, Serialize, Deserialize, Clone)]
67 #[cfg_attr(feature = "full", derive(TS))]
68 #[cfg_attr(feature = "full", ts(export))]
69 pub struct SearchResponse {
70   pub type_: SearchType,
71   pub comments: Vec<CommentView>,
72   pub posts: Vec<PostView>,
73   pub communities: Vec<CommunityView>,
74   pub users: Vec<PersonView>,
75 }
76
77 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
78 #[cfg_attr(feature = "full", derive(TS))]
79 #[cfg_attr(feature = "full", ts(export))]
80 pub struct ResolveObject {
81   pub q: String,
82   pub auth: Sensitive<String>,
83 }
84
85 #[skip_serializing_none]
86 #[derive(Debug, Serialize, Deserialize, Default)]
87 #[cfg_attr(feature = "full", derive(TS))]
88 #[cfg_attr(feature = "full", ts(export))]
89 // TODO Change this to an enum
90 pub struct ResolveObjectResponse {
91   pub comment: Option<CommentView>,
92   pub post: Option<PostView>,
93   pub community: Option<CommunityView>,
94   pub person: Option<PersonView>,
95 }
96
97 #[skip_serializing_none]
98 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
99 #[cfg_attr(feature = "full", derive(TS))]
100 #[cfg_attr(feature = "full", ts(export))]
101 pub struct GetModlog {
102   pub mod_person_id: Option<PersonId>,
103   pub community_id: Option<CommunityId>,
104   pub page: Option<i64>,
105   pub limit: Option<i64>,
106   pub type_: Option<ModlogActionType>,
107   pub other_person_id: Option<PersonId>,
108   pub auth: Option<Sensitive<String>>,
109 }
110
111 #[derive(Debug, Serialize, Deserialize, Clone)]
112 #[cfg_attr(feature = "full", derive(TS))]
113 #[cfg_attr(feature = "full", ts(export))]
114 pub struct GetModlogResponse {
115   pub removed_posts: Vec<ModRemovePostView>,
116   pub locked_posts: Vec<ModLockPostView>,
117   pub featured_posts: Vec<ModFeaturePostView>,
118   pub removed_comments: Vec<ModRemoveCommentView>,
119   pub removed_communities: Vec<ModRemoveCommunityView>,
120   pub banned_from_community: Vec<ModBanFromCommunityView>,
121   pub banned: Vec<ModBanView>,
122   pub added_to_community: Vec<ModAddCommunityView>,
123   pub transferred_to_community: Vec<ModTransferCommunityView>,
124   pub added: Vec<ModAddView>,
125   pub admin_purged_persons: Vec<AdminPurgePersonView>,
126   pub admin_purged_communities: Vec<AdminPurgeCommunityView>,
127   pub admin_purged_posts: Vec<AdminPurgePostView>,
128   pub admin_purged_comments: Vec<AdminPurgeCommentView>,
129   pub hidden_communities: Vec<ModHideCommunityView>,
130 }
131
132 #[skip_serializing_none]
133 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
134 #[cfg_attr(feature = "full", derive(TS))]
135 #[cfg_attr(feature = "full", ts(export))]
136 pub struct CreateSite {
137   pub name: String,
138   pub sidebar: Option<String>,
139   pub description: Option<String>,
140   pub icon: Option<String>,
141   pub banner: Option<String>,
142   pub enable_downvotes: Option<bool>,
143   pub enable_nsfw: Option<bool>,
144   pub community_creation_admin_only: Option<bool>,
145   pub require_email_verification: Option<bool>,
146   pub application_question: Option<String>,
147   pub private_instance: Option<bool>,
148   pub default_theme: Option<String>,
149   pub default_post_listing_type: Option<ListingType>,
150   pub legal_information: Option<String>,
151   pub application_email_admins: Option<bool>,
152   pub hide_modlog_mod_names: Option<bool>,
153   pub discussion_languages: Option<Vec<LanguageId>>,
154   pub slur_filter_regex: Option<String>,
155   pub actor_name_max_length: Option<i32>,
156   pub rate_limit_message: Option<i32>,
157   pub rate_limit_message_per_second: Option<i32>,
158   pub rate_limit_post: Option<i32>,
159   pub rate_limit_post_per_second: Option<i32>,
160   pub rate_limit_register: Option<i32>,
161   pub rate_limit_register_per_second: Option<i32>,
162   pub rate_limit_image: Option<i32>,
163   pub rate_limit_image_per_second: Option<i32>,
164   pub rate_limit_comment: Option<i32>,
165   pub rate_limit_comment_per_second: Option<i32>,
166   pub rate_limit_search: Option<i32>,
167   pub rate_limit_search_per_second: Option<i32>,
168   pub federation_enabled: Option<bool>,
169   pub federation_debug: Option<bool>,
170   pub federation_worker_count: Option<i32>,
171   pub captcha_enabled: Option<bool>,
172   pub captcha_difficulty: Option<String>,
173   pub allowed_instances: Option<Vec<String>>,
174   pub blocked_instances: Option<Vec<String>>,
175   pub taglines: Option<Vec<String>>,
176   pub registration_mode: Option<RegistrationMode>,
177   pub auth: Sensitive<String>,
178 }
179
180 #[skip_serializing_none]
181 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
182 #[cfg_attr(feature = "full", derive(TS))]
183 #[cfg_attr(feature = "full", ts(export))]
184 pub struct EditSite {
185   pub name: Option<String>,
186   pub sidebar: Option<String>,
187   pub description: Option<String>,
188   pub icon: Option<String>,
189   pub banner: Option<String>,
190   pub enable_downvotes: Option<bool>,
191   pub enable_nsfw: Option<bool>,
192   pub community_creation_admin_only: Option<bool>,
193   pub require_email_verification: Option<bool>,
194   pub application_question: Option<String>,
195   pub private_instance: Option<bool>,
196   pub default_theme: Option<String>,
197   pub default_post_listing_type: Option<ListingType>,
198   pub legal_information: Option<String>,
199   pub application_email_admins: Option<bool>,
200   pub hide_modlog_mod_names: Option<bool>,
201   pub discussion_languages: Option<Vec<LanguageId>>,
202   pub slur_filter_regex: Option<String>,
203   pub actor_name_max_length: Option<i32>,
204   pub rate_limit_message: Option<i32>,
205   pub rate_limit_message_per_second: Option<i32>,
206   pub rate_limit_post: Option<i32>,
207   pub rate_limit_post_per_second: Option<i32>,
208   pub rate_limit_register: Option<i32>,
209   pub rate_limit_register_per_second: Option<i32>,
210   pub rate_limit_image: Option<i32>,
211   pub rate_limit_image_per_second: Option<i32>,
212   pub rate_limit_comment: Option<i32>,
213   pub rate_limit_comment_per_second: Option<i32>,
214   pub rate_limit_search: Option<i32>,
215   pub rate_limit_search_per_second: Option<i32>,
216   pub federation_enabled: Option<bool>,
217   pub federation_debug: Option<bool>,
218   pub federation_worker_count: Option<i32>,
219   pub captcha_enabled: Option<bool>,
220   pub captcha_difficulty: Option<String>,
221   pub allowed_instances: Option<Vec<String>>,
222   pub blocked_instances: Option<Vec<String>>,
223   pub taglines: Option<Vec<String>>,
224   pub registration_mode: Option<RegistrationMode>,
225   pub reports_email_admins: Option<bool>,
226   pub auth: Sensitive<String>,
227 }
228
229 #[skip_serializing_none]
230 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
231 #[cfg_attr(feature = "full", derive(TS))]
232 #[cfg_attr(feature = "full", ts(export))]
233 pub struct GetSite {
234   pub auth: Option<Sensitive<String>>,
235 }
236
237 #[derive(Debug, Serialize, Deserialize, Clone)]
238 #[cfg_attr(feature = "full", derive(TS))]
239 #[cfg_attr(feature = "full", ts(export))]
240 pub struct SiteResponse {
241   pub site_view: SiteView,
242 }
243
244 #[skip_serializing_none]
245 #[derive(Debug, Serialize, Deserialize, Clone)]
246 #[cfg_attr(feature = "full", derive(TS))]
247 #[cfg_attr(feature = "full", ts(export))]
248 pub struct GetSiteResponse {
249   pub site_view: SiteView,
250   pub admins: Vec<PersonView>,
251   pub online: usize,
252   pub version: String,
253   pub my_user: Option<MyUserInfo>,
254   pub all_languages: Vec<Language>,
255   pub discussion_languages: Vec<LanguageId>,
256   pub taglines: Vec<Tagline>,
257   pub custom_emojis: Vec<CustomEmojiView>,
258 }
259
260 #[derive(Debug, Serialize, Deserialize, Clone)]
261 #[cfg_attr(feature = "full", derive(TS))]
262 #[cfg_attr(feature = "full", ts(export))]
263 pub struct GetFederatedInstances {}
264
265 #[skip_serializing_none]
266 #[derive(Debug, Serialize, Deserialize, Clone)]
267 #[cfg_attr(feature = "full", derive(TS))]
268 #[cfg_attr(feature = "full", ts(export))]
269 pub struct GetFederatedInstancesResponse {
270   pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
271 }
272
273 #[derive(Debug, Serialize, Deserialize, Clone)]
274 #[cfg_attr(feature = "full", derive(TS))]
275 #[cfg_attr(feature = "full", ts(export))]
276 pub struct MyUserInfo {
277   pub local_user_view: LocalUserView,
278   pub follows: Vec<CommunityFollowerView>,
279   pub moderates: Vec<CommunityModeratorView>,
280   pub community_blocks: Vec<CommunityBlockView>,
281   pub person_blocks: Vec<PersonBlockView>,
282   pub discussion_languages: Vec<LanguageId>,
283 }
284
285 #[derive(Debug, Serialize, Deserialize, Clone)]
286 #[cfg_attr(feature = "full", derive(TS))]
287 #[cfg_attr(feature = "full", ts(export))]
288 pub struct LeaveAdmin {
289   pub auth: Sensitive<String>,
290 }
291
292 #[derive(Debug, Serialize, Deserialize, Clone)]
293 #[cfg_attr(feature = "full", derive(TS))]
294 #[cfg_attr(feature = "full", ts(export))]
295 pub struct FederatedInstances {
296   pub linked: Vec<Instance>,
297   pub allowed: Vec<Instance>,
298   pub blocked: Vec<Instance>,
299 }
300
301 #[skip_serializing_none]
302 #[derive(Debug, Serialize, Deserialize, Clone)]
303 #[cfg_attr(feature = "full", derive(TS))]
304 #[cfg_attr(feature = "full", ts(export))]
305 pub struct PurgePerson {
306   pub person_id: PersonId,
307   pub reason: Option<String>,
308   pub auth: Sensitive<String>,
309 }
310
311 #[skip_serializing_none]
312 #[derive(Debug, Serialize, Deserialize, Clone)]
313 #[cfg_attr(feature = "full", derive(TS))]
314 #[cfg_attr(feature = "full", ts(export))]
315 pub struct PurgeCommunity {
316   pub community_id: CommunityId,
317   pub reason: Option<String>,
318   pub auth: Sensitive<String>,
319 }
320
321 #[skip_serializing_none]
322 #[derive(Debug, Serialize, Deserialize, Clone)]
323 #[cfg_attr(feature = "full", derive(TS))]
324 #[cfg_attr(feature = "full", ts(export))]
325 pub struct PurgePost {
326   pub post_id: PostId,
327   pub reason: Option<String>,
328   pub auth: Sensitive<String>,
329 }
330
331 #[skip_serializing_none]
332 #[derive(Debug, Serialize, Deserialize, Clone)]
333 #[cfg_attr(feature = "full", derive(TS))]
334 #[cfg_attr(feature = "full", ts(export))]
335 pub struct PurgeComment {
336   pub comment_id: CommentId,
337   pub reason: Option<String>,
338   pub auth: Sensitive<String>,
339 }
340
341 #[derive(Serialize, Deserialize)]
342 #[cfg_attr(feature = "full", derive(TS))]
343 #[cfg_attr(feature = "full", ts(export))]
344 pub struct PurgeItemResponse {
345   pub success: bool,
346 }
347
348 #[skip_serializing_none]
349 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
350 #[cfg_attr(feature = "full", derive(TS))]
351 #[cfg_attr(feature = "full", ts(export))]
352 pub struct ListRegistrationApplications {
353   /// Only shows the unread applications (IE those without an admin actor)
354   pub unread_only: Option<bool>,
355   pub page: Option<i64>,
356   pub limit: Option<i64>,
357   pub auth: Sensitive<String>,
358 }
359
360 #[derive(Debug, Serialize, Deserialize, Clone)]
361 #[cfg_attr(feature = "full", derive(TS))]
362 #[cfg_attr(feature = "full", ts(export))]
363 pub struct ListRegistrationApplicationsResponse {
364   pub registration_applications: Vec<RegistrationApplicationView>,
365 }
366
367 #[skip_serializing_none]
368 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
369 #[cfg_attr(feature = "full", derive(TS))]
370 #[cfg_attr(feature = "full", ts(export))]
371 pub struct ApproveRegistrationApplication {
372   pub id: i32,
373   pub approve: bool,
374   pub deny_reason: Option<String>,
375   pub auth: Sensitive<String>,
376 }
377
378 #[derive(Debug, Serialize, Deserialize, Clone)]
379 #[cfg_attr(feature = "full", derive(TS))]
380 #[cfg_attr(feature = "full", ts(export))]
381 pub struct RegistrationApplicationResponse {
382   pub registration_application: RegistrationApplicationView,
383 }
384
385 #[derive(Debug, Serialize, Deserialize, Clone)]
386 #[cfg_attr(feature = "full", derive(TS))]
387 #[cfg_attr(feature = "full", ts(export))]
388 pub struct GetUnreadRegistrationApplicationCount {
389   pub auth: Sensitive<String>,
390 }
391
392 #[derive(Debug, Serialize, Deserialize, Clone)]
393 #[cfg_attr(feature = "full", derive(TS))]
394 #[cfg_attr(feature = "full", ts(export))]
395 pub struct GetUnreadRegistrationApplicationCountResponse {
396   pub registration_applications: i64,
397 }