//! What ipx servers and the directory send each other: listings, feed pages, snapshots and their results. use crate::config::Access; use serde::{Deserialize, Serialize}; /// A feed as the directory lists it. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Listing { /// The first 64 bits of the SHA-256 of its normalised address (`store::feed_id`). pub id: String, pub url: String, pub title: Option, pub image: Option, /// Apple's category and the subcategory within it, from the feed's own iTunes category. pub category: Option, pub subcategory: Option, /// Any audio or video in its latest items. pub podcast: bool, /// Summed over every instance's latest snapshot. pub subscribers: i64, } /// One feed's page: what it says it is, and its latest items. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct FeedPage { #[serde(flatten)] pub listing: Listing, /// The feed's own text, HTML as often as not, as it was sent: whoever shows it sanitizes it. pub description: Option, /// Why its last check failed, in words, when it did. pub failing: Option, pub items: Vec, } /// One of a feed's latest items: what it is, never its files. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Item { pub guid: String, pub title: Option, pub link: Option, /// Unix seconds. pub published: Option, /// Seconds. pub duration: Option, /// As the feed sent it, unsanitized. pub description: Option, } /// One feed in a snapshot: its address, and how many people on the sending server subscribe. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SnapshotEntry { pub url: String, pub subscribers: i64, /// The category the sending server's admin gave a feed that names none itself: used only /// while the feed names none. #[serde(default, skip_serializing_if = "Option::is_none")] pub category: Option, } /// What became of a snapshot's entries. #[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] pub struct SnapshotResult { pub accepted: usize, /// Addresses that look like they carry a subscriber's own access. pub refused_private: usize, /// Feeds an admin removed from the directory. pub refused_blocked: usize, /// Not an http(s) address. pub refused_invalid: usize, } /// Who a token belongs to and what it may do: `/v1/me`'s answer. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Me { pub name: String, pub access: Access, } /// A token whose snapshot the directory holds: how many feeds it gave, and how many people. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Instance { pub name: String, pub feeds: i64, pub subscribers: i64, } /// A feed an admin removed from the directory, which snapshots may not bring back. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Blocked { pub id: String, pub url: Option, pub title: Option, /// When it was blocked, Unix seconds. pub at: i64, } /// The most a snapshot may list: far more than one server's subscriptions, few enough that one /// request cannot hold the database for long. pub const MAX_SNAPSHOT: usize = 20_000;