Skip to main content

spoolframe_protocol/
plex.rs

1//! The session user's Plex account link, as clients may read it.
2//! Linking and unlinking are the web UI's (`<web_url>/profile`): a client
3//! only shows the state, and never sees the account's token.
4
5use serde::{Deserialize, Serialize};
6
7/// A linked Plex account: the user's watch state syncs with it.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
10pub struct PlexLink {
11    /// The Plex account's username and email, as plex.tv said when it was
12    /// linked; both `None` for a link the server's config file makes.
13    pub username: Option<String>,
14    pub email: Option<String>,
15    /// Linked by the server's config file, as the Plex servers' owner:
16    /// only that file can unlink it, not the web UI.
17    pub by_config: bool,
18    /// When it was linked (Unix seconds on the wire); `None` for the
19    /// config's.
20    // Read as none when left out, as a plain `Option` was.
21    #[serde(default, with = "spoolframe_types::serde_time::unix_seconds::option")]
22    pub linked_at: Option<std::time::SystemTime>,
23    /// The user's last sync run since the server started, if any.
24    pub last_sync: Option<PlexSyncSummary>,
25    /// A sync run of theirs is going on now.
26    pub syncing: bool,
27}
28
29/// What one sync run did.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
31#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
32pub struct PlexSyncSummary {
33    /// When it ended, Unix seconds.
34    pub at: i64,
35    /// The libraries synced.
36    pub libraries: u32,
37    /// Items whose state was taken from Plex, sent to Plex, left as they
38    /// were, and that failed.
39    pub pulled: u32,
40    pub pushed: u32,
41    pub skipped: u32,
42    pub failed: u32,
43}