The crate root held the wire types, Directory with its refresher and reloader, and every /v1 handler. It is now the module list and the re-exports ipx and the directory's main use, so their paths are as before: wire.rs Listing, FeedPage, SnapshotEntry, ... and MAX_SNAPSHOT directory.rs Directory, Shared, the refresher and the reloader api.rs the router, the token check and the /v1 handlers Directory's fields and methods are pub(crate) for the handlers beside it. Its two tests that read those fields went with it, on a scratch Directory of their own; the API tests stay with the API. Every definition and doc comment line of the old lib.rs is in exactly one of the new files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
3.3 KiB
Rust
100 lines
3.3 KiB
Rust
//! 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<String>,
|
|
pub image: Option<String>,
|
|
/// Apple's category and the subcategory within it, from the feed's own iTunes category.
|
|
pub category: Option<String>,
|
|
pub subcategory: Option<String>,
|
|
/// 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<String>,
|
|
/// Why its last check failed, in words, when it did.
|
|
pub failing: Option<String>,
|
|
pub items: Vec<Item>,
|
|
}
|
|
|
|
/// 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<String>,
|
|
pub link: Option<String>,
|
|
/// Unix seconds.
|
|
pub published: Option<i64>,
|
|
/// Seconds.
|
|
pub duration: Option<i64>,
|
|
/// As the feed sent it, unsanitized.
|
|
pub description: Option<String>,
|
|
}
|
|
|
|
/// 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<String>,
|
|
}
|
|
|
|
/// 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<String>,
|
|
pub title: Option<String>,
|
|
/// 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;
|