1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
pub mod config;

pub use config::Config;

#[derive(Debug)]
pub(crate) struct Empty;

impl<'de> serde::Deserialize<'de> for Empty {
    fn deserialize<D: serde::Deserializer<'de>>(_: D) -> Result<Empty, D::Error> {
        Ok(Empty)
    }
}

impl From<Empty> for crate::Result<()> {
    fn from(_: Empty) -> Self {
        Ok(())
    }
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Account {
    pub url: String,
    pub name: String,
    pub host: String,
    pub avatar: Option<Avatar>,
    pub id: u32,
    pub host_redundancy_allowed: Option<bool>,
    pub following_count: u32,
    pub followers_count: u32,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub updated_at: chrono::DateTime<chrono::offset::Utc>,
    pub display_name: String,
    pub description: Option<String>,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountSummary {
    pub avatar: Option<Avatar>,
    pub display_name: String,
    pub host: String,
    pub id: u32,
    pub name: String,
    pub url: String,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Avatar {
    pub path: String,
    pub created_at: Option<chrono::DateTime<chrono::offset::Utc>>,
    pub updated_at: Option<chrono::DateTime<chrono::offset::Utc>>,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Video {
    pub account: AccountSummary,
    pub blacklisted: Option<bool>,
    pub blacklisted_reason: Option<String>,
    pub category: Category,
    pub channel: ChannelSummary,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub description: Option<String>,
    pub dislikes: u32,
    pub duration: u32,
    pub embed_path: String,
    pub id: u32,
    pub is_like: Option<bool>,
    pub is_local: bool,
    pub language: Language,
    pub license: Option<License>,
    pub likes: u32,
    pub name: String,
    pub nsfw: bool,
    pub originally_published_at: Option<chrono::DateTime<chrono::offset::Utc>>,
    pub preview_path: String,
    pub privacy: Privacy,
    pub published_at: chrono::DateTime<chrono::offset::Utc>,
    pub scheduled_update: Option<ScheduledUpdate>,
    pub state: Option<State>,
    pub thumbnail_path: String,
    pub update_at: Option<chrono::DateTime<chrono::offset::Utc>>,
    pub user_history: Option<UserHistory>,
    pub uuid: String,
    pub views: u32,
    pub wait_transcoding: Option<bool>,
}

#[derive(Debug, serde::Deserialize)]
pub struct Category {
    pub id: Option<u32>,
    pub label: String,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChannelSummary {
    pub avatar: Option<Avatar>,
    pub display_name: String,
    pub host: Option<String>,
    pub id: u32,
    pub name: String,
    pub url: Option<String>,
}

#[derive(Debug, serde::Deserialize)]
pub struct Language {
    pub id: Option<String>,
    pub label: String,
}

#[derive(Debug, serde::Deserialize)]
pub struct License {
    pub id: u32,
    pub label: String,
}

#[derive(Debug, serde::Deserialize)]
pub struct Privacy {
    pub id: u32,
    pub label: String,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct ScheduledUpdate {
    update_at: String,
    privacy: u32,
}

#[derive(Debug, serde::Deserialize)]
pub struct State {
    pub id: u32,
    pub label: String,
}

#[derive(Debug, serde::Deserialize)]
pub struct UserHistory {
    current_time: u32,
}

#[derive(Debug, serde::Deserialize)]
pub(crate) struct OauthClient {
    pub client_id: String,
    pub client_secret: String,
}

#[derive(Clone, Debug, serde::Deserialize)]
pub struct Token {
    pub access_token: String,
    pub token_type: String,
    pub expires_in: u32,
    pub refresh_token: String,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Data {
    NewUser(NewUser),
}

#[derive(Debug, serde::Deserialize)]
pub struct NewUser {
    pub account: AccountId,
    pub id: u32,
}

#[derive(Debug, serde::Deserialize)]
pub struct AccountId {
    pub id: u32,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct User {
    pub id: u32,
    pub username: String,
    pub email: String,
    pub plugin_auth: Option<String>,
    pub theme: String,
    pub email_verified: Option<bool>,
    pub nsfw_policy: String,
    pub web_torrent_enabled: bool,
    pub auto_play_video: bool,
    pub role: Role,
    pub role_label: String,
    pub video_quota: i64,
    pub video_quota_daily: i64,
    pub no_instance_config_warning_modal: bool,
    pub no_welcome_modal: bool,
    pub blocked: bool,
    pub blocked_reason: Option<String>,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub account: Account,
    pub video_channels: Vec<Channel>,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Channel {
    pub description: Option<String>,
    pub display_name: String,
    pub is_local: bool,
}

#[derive(Debug, serde_repr::Deserialize_repr, serde_repr::Serialize_repr)]
#[repr(u8)]
pub enum Role {
    Admin = 0,
    Moderator = 1,
    User = 2,
}

impl Default for Role {
    fn default() -> Self {
        Self::User
    }
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Import {
    pub id: u32,
    pub target_url: String,
    pub magnet_uri: Option<String>,
    pub torrent_name: Option<String>,
    pub state: State,
    pub error: Option<String>,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub updated_at: chrono::DateTime<chrono::offset::Utc>,
    pub video: Video,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Quota {
    pub video_quota_used: u64,
    pub video_quota_used_daily: u64,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Rating {
    pub video_id: u32,
    pub rating: String,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Abuse {
    pub id: u32,
    pub reason: String,
    #[serde(default)]
    pub predefined_reasons: Vec<AbusePredefinedReason>,
    pub reporter_account: Account,
    pub state: AbuseState,
    pub moderation_comment: String,
    pub video: VideoInfo,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
}

#[derive(Debug, serde_repr::Deserialize_repr, serde_repr::Serialize_repr)]
#[repr(u8)]
pub enum AbuseState {
    Pending = 1,
    Rejected = 2,
    Accepted = 3,
}

#[derive(Debug, serde::Deserialize)]
pub struct VideoInfo {
    pub id: u32,
    pub uuid: String,
    pub name: String,
    pub channel: Option<ChannelSummary>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum AbusePredefinedReason {
    ViolentOrAbusive,
    HatefulOrAbusive,
    SpamOrMisleading,
    Privacy,
    Rights,
    ServerRules,
    Thumbnails,
    Captions,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Subscription {
    pub avatar: Option<Avatar>,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub description: Option<String>,
    pub display_name: String,
    pub followers_count: u32,
    pub following_count: u32,
    pub host: String,
    pub host_redundancy_allowed: Option<bool>,
    pub id: u32,
    pub is_local: bool,
    pub name: String,
    pub owner_account: Option<Account>,
    pub support: Option<String>,
    pub updated_at: chrono::DateTime<chrono::offset::Utc>,
    pub url: String,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Notification {
    account: Option<AccountSummary>,
    //pub actor_follow: Option<>,
    pub comment: Option<CommentSummary>,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub id: u32,
    pub read: bool,
    pub r#type: UserNotificationType,
    pub updated_at: chrono::DateTime<chrono::offset::Utc>,
    pub video: Option<VideoInfo>,
    //pub video_abuse: Option<>,
    //pub video_blacklist: Option<>,
    //pub video_import: Option<>,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CommentSummary {
    pub account: AccountSummary,
    pub id: u32,
    pub thread_id: u32,
    pub video: VideoInfo,
}

#[derive(Debug, serde_repr::Deserialize_repr, serde_repr::Serialize_repr)]
#[repr(u8)]
pub enum UserNotificationType {
    NewVideoFromSubscription = 1,
    NewCommentOnMyVideo = 2,
    NewAbuseForModerators = 3,
    BlacklistOnMyVideo = 4,
    UnblacklistOnMyVideo = 5,
    MyVideoPublished = 6,
    MyVideoImportSuccess = 7,
    MyVideoImportError = 8,
    NewUserRegistration = 9,
    NewFollow = 10,
    CommentMention = 11,
    VideoAutoBlacklistForModerators = 12,
    NewInstanceFollower = 13,
    AutoInstanceFollowing = 14,
}

#[derive(Debug, serde::Deserialize)]
pub(crate) struct Description {
    pub description: String,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum NewContent {
    Abuse(NewAbuse),
    AbuseMessage(NewAbuseMessage),
    Video(NewVideo),
    #[serde(rename = "videoChannel")]
    Channel(NewChannel),
    Comment(Comment),
    #[serde(rename = "videoPlaylist")]
    Playlist(NewPlaylist),
    #[serde(rename = "videoPlaylistElement")]
    PlaylistElement(NewPlaylistElement),
}

#[derive(Debug, serde::Deserialize)]
pub struct NewAbuse {
    pub id: u32,
}

#[derive(Debug, serde::Deserialize)]
pub struct NewAbuseMessage {
    pub id: u32,
}

#[derive(Debug, serde::Deserialize)]
pub struct NewVideo {
    pub id: u32,
    pub uuid: String,
}

#[derive(Debug, serde::Deserialize)]
pub struct NewChannel {
    pub id: u32,
}

#[derive(Debug, serde::Deserialize)]
pub struct NewPlaylist {
    pub id: u32,
    pub uuid: String,
}

#[derive(Debug, serde::Deserialize)]
pub struct NewPlaylistElement {
    pub id: u32,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Live {
    pub rtmp_url: String,
    pub stream_key: String,
    pub save_replay: bool,
    pub permanent_live: bool,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Caption {
    pub caption_path: String,
    pub language: Language,
}

#[derive(Debug, serde::Deserialize)]
pub struct Thread {
    pub comment: Comment,
    pub children: Vec<Comment>,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Comment {
    pub account: Option<Account>,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub id: u32,
    pub in_reply_to_comment_id: Option<u32>,
    pub text: String,
    pub thread_id: u32,
    pub total_replies: u32,
    pub total_replies_from_video_author: u32,
    pub is_deleted: bool,
    pub deleted_at: Option<chrono::DateTime<chrono::offset::Utc>>,
    pub updated_at: chrono::DateTime<chrono::offset::Utc>,
    pub url: String,
    pub video_id: u32,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Playlist {
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub description: Option<String>,
    pub display_name: String,
    pub id: u32,
    pub is_local: bool,
    pub owner_account: AccountSummary,
    pub privacy: Privacy,
    pub thumbnail_path: Option<String>,
    pub r#type: PlaylistType,
    pub updated_at: chrono::DateTime<chrono::offset::Utc>,
    pub uuid: String,
    pub video_channel: Option<ChannelSummary>,
    pub videos_length: u32,
}

#[derive(Debug, serde::Deserialize)]
pub struct PlaylistType {
    pub id: PlaylistId,
    pub label: String,
}

#[derive(Debug, serde_repr::Deserialize_repr)]
#[repr(u8)]
pub enum PlaylistId {
    Regular = 1,
    WatchLater = 2,
}

#[derive(Debug, serde::Deserialize)]
pub struct Ownership {
    pub id: String,
}

#[derive(Debug, serde::Deserialize)]
pub struct Redundancy {
    pub id: u32,
    pub name: String,
    pub url: String,
    pub uuid: String,
    pub redundancies: Redundancies,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Redundancies {
    pub files: Vec<FileRedundancyInformation>,
    pub streaming_playlists: Vec<FileRedundancyInformation>,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FileRedundancyInformation {
    pub id: u32,
    pub file_url: String,
    pub strategy: Strategy,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub updated_at: chrono::DateTime<chrono::offset::Utc>,
    pub expires_on: chrono::DateTime<chrono::offset::Utc>,
    pub size: u64,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum Strategy {
    Manual,
    MostViews,
    Trending,
    RecentlyAdded,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AbuseMessage {
    pub id: u32,
    pub message: String,
    pub by_moderator: bool,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub account: AccountSummary,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VideoBlacklist {
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub description: String,
    pub dislikes: u32,
    pub duration: u32,
    pub id: u32,
    pub likes: u32,
    pub name: String,
    pub nfsw: bool,
    pub uuid: String,
    pub video_id: u32,
    pub views: u32,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BlockedServer {
    pub by_account: Account,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub blocked_server: Server,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Server {
    pub host: String,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BlockedAccount {
    pub by_account: Account,
    pub blocked_account: Account,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct AccountName {
    pub account_name: String,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Follow {
    pub id: u32,
    pub score: u32,
    pub state: FollowState,
    pub follower: Account,
    pub following: Account,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub updated_at: chrono::DateTime<chrono::offset::Utc>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum FollowState {
    Pending,
    Accepted,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Plugin {
    pub name: String,
    pub r#type: u32,
    pub latest_version: String,
    pub version: String,
    pub enabled: bool,
    pub uninstalled: bool,
    pub peertube_engine: String,
    pub description: String,
    pub homepage: String,
    //pub settings: (),
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub updated_at: chrono::DateTime<chrono::offset::Utc>,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AvailablePlugin {
    pub npm_name: String,
    pub description: String,
    pub homepage: String,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub updated_at: chrono::DateTime<chrono::offset::Utc>,
    pub popularity: f32,
    pub latest_version: String,
    pub installed: bool,
    pub name: String,
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PublicSettings {
    //pub public_settings: (),
}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RegisteredSettings {}

#[derive(Debug, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Job {
    pub id: u32,
    pub state: JobState,
    pub r#type: JobType,
    pub data: (),
    pub error: Option<()>,
    pub created_at: chrono::DateTime<chrono::offset::Utc>,
    pub finished_on: chrono::DateTime<chrono::offset::Utc>,
    pub processed_on: chrono::DateTime<chrono::offset::Utc>,
}

#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum JobState {
    #[serde(rename = "")]
    All,
    Active,
    Completed,
    Failed,
    Waiting,
    Delayed,
}

impl std::fmt::Display for JobState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let s = match self {
            Self::All => "",
            Self::Active => "active",
            Self::Completed => "completed",
            Self::Failed => "failed",
            Self::Waiting => "waiting",
            Self::Delayed => "delayed",
        };

        f.write_str(&s)
    }
}

#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum JobType {
    ActivitypubFollow,
    ActivitypubHttpBroadcast,
    ActivitypubHttpFetcher,
    ActivitypubHttpUnicast,
    Email,
    VideoTranscoding,
    VideoFileImport,
    VideoImport,
    VideosViews,
    ActivitypubRefresher,
    VideoRedundancy,
    VideoLiveEnding,
}