Protobuf beside JSON in ipx's, the directory's and ipx-play's APIs (#465); ipx's build touches crates/play (#466)
A client sending Accept: application/x-protobuf gets protobuf, and one sending Content-Type: application/x-protobuf may send its body so; JSON stays the default, so the page, the TUI and older iOS builds see nothing new. ipx's own calls to the directory and ipx-play now go in protobuf. The handlers are untouched. A new crate, ipx-wire, holds the .proto files (compiled by protox in build.rs, so no protoc anywhere) and one layer, negotiate, that converts JSON at the edge through prost-reflect, by a table of each route's messages. Writing prost structs beside every serde one would have doubled each type and every handler. Protobuf cannot tell absent from empty or from null, and the PATCH bodies depend on that: an Option<Vec> left out leaves the list, an empty one clears it, and null clears a folder. So a list in a body is a one-field message (absent or present), and null-to-clear is a google.protobuf.Value. Numbers in a Value come back whole, or 3.0 would not read as a usize. Debug builds convert every JSON answer strictly and answer 500 for a field missing from the .proto or a route missing from a table; the cargo tests and the browser suite (125 tests) ran clean that way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
94
crates/wire/proto/directory.proto
Normal file
94
crates/wire/proto/directory.proto
Normal file
@@ -0,0 +1,94 @@
|
||||
// ipx-directory's API under /v1 (crates/directory/src/wire.rs), each message named after the Rust
|
||||
// struct it mirrors. A field added there goes here too; debug builds refuse an answer with a field
|
||||
// missing here. A message whose only field is `repeated items` is a JSON array.
|
||||
syntax = "proto3";
|
||||
package directory;
|
||||
|
||||
// GET /v1/me.
|
||||
message Me {
|
||||
string name = 1;
|
||||
// "ro", "rw" or "rwa".
|
||||
string access = 2;
|
||||
}
|
||||
|
||||
message Listing {
|
||||
string id = 1;
|
||||
string url = 2;
|
||||
optional string title = 3;
|
||||
optional string image = 4;
|
||||
optional string category = 5;
|
||||
optional string subcategory = 6;
|
||||
bool podcast = 7;
|
||||
int64 subscribers = 8;
|
||||
}
|
||||
|
||||
// GET /v1/feeds, GET /v1/popular.
|
||||
message Listings {
|
||||
repeated Listing items = 1;
|
||||
}
|
||||
|
||||
message Item {
|
||||
string guid = 1;
|
||||
optional string title = 2;
|
||||
optional string link = 3;
|
||||
optional int64 published = 4;
|
||||
optional int64 duration = 5;
|
||||
optional string description = 6;
|
||||
}
|
||||
|
||||
// GET /v1/feeds/{id}, POST /v1/feeds/{id}/refresh: a Listing's fields and these.
|
||||
message FeedPage {
|
||||
string id = 1;
|
||||
string url = 2;
|
||||
optional string title = 3;
|
||||
optional string image = 4;
|
||||
optional string category = 5;
|
||||
optional string subcategory = 6;
|
||||
bool podcast = 7;
|
||||
int64 subscribers = 8;
|
||||
optional string description = 9;
|
||||
optional string failing = 10;
|
||||
repeated Item items = 11;
|
||||
}
|
||||
|
||||
message SnapshotEntry {
|
||||
string url = 1;
|
||||
int64 subscribers = 2;
|
||||
optional string category = 3;
|
||||
}
|
||||
|
||||
// POST /v1/snapshot, the body.
|
||||
message Snapshot {
|
||||
repeated SnapshotEntry items = 1;
|
||||
}
|
||||
|
||||
// POST /v1/snapshot, the answer.
|
||||
message SnapshotResult {
|
||||
uint64 accepted = 1;
|
||||
uint64 refused_private = 2;
|
||||
uint64 refused_blocked = 3;
|
||||
uint64 refused_invalid = 4;
|
||||
}
|
||||
|
||||
message Instance {
|
||||
string name = 1;
|
||||
int64 feeds = 2;
|
||||
int64 subscribers = 3;
|
||||
}
|
||||
|
||||
// GET /v1/instances.
|
||||
message Instances {
|
||||
repeated Instance items = 1;
|
||||
}
|
||||
|
||||
message Blocked {
|
||||
string id = 1;
|
||||
optional string url = 2;
|
||||
optional string title = 3;
|
||||
int64 at = 4;
|
||||
}
|
||||
|
||||
// GET /v1/blocked.
|
||||
message BlockedList {
|
||||
repeated Blocked items = 1;
|
||||
}
|
||||
494
crates/wire/proto/ipx.proto
Normal file
494
crates/wire/proto/ipx.proto
Normal file
@@ -0,0 +1,494 @@
|
||||
// ipx's API under /api (crates/ipx/src/web.rs), the same answers its JSON gives, each message named
|
||||
// after the Rust struct it mirrors where there is one (web/src/types.ts mirrors the same). A field
|
||||
// added in Rust goes here too: debug builds refuse an answer with a field missing here.
|
||||
//
|
||||
// How the JSON maps (crates/wire/src/lib.rs):
|
||||
// * A field name is the JSON key.
|
||||
// * A Rust Option is `optional`, or a message; so is a field with a serde default, which an absent
|
||||
// field must leave to Rust.
|
||||
// * A message whose only field is `repeated ... items` is a JSON array, top-level or as a field.
|
||||
// An Option<Vec> in a body is one (Words), so leaving a list alone and emptying it differ.
|
||||
// * A body field that takes null to clear it is a google.protobuf.Value: absent leaves it, null
|
||||
// clears it, a value sets it.
|
||||
// * An answer of JSON null is an empty message.
|
||||
syntax = "proto3";
|
||||
package ipx;
|
||||
|
||||
import "google/protobuf/struct.proto";
|
||||
import "directory.proto";
|
||||
|
||||
// A list of words, as an Option<Vec<String>> in a body: absent, or this.
|
||||
message Words {
|
||||
repeated string items = 1;
|
||||
}
|
||||
|
||||
// ---- signing in, and you ----
|
||||
|
||||
// POST /api/login, the body.
|
||||
message Credentials {
|
||||
string name = 1;
|
||||
string password = 2;
|
||||
}
|
||||
|
||||
// POST /api/login, the answer.
|
||||
message SignedIn {
|
||||
string name = 1;
|
||||
bool admin = 2;
|
||||
}
|
||||
|
||||
message Theme {
|
||||
string name = 1;
|
||||
string mode = 2;
|
||||
}
|
||||
|
||||
// GET /api/me.
|
||||
message Me {
|
||||
string name = 1;
|
||||
bool admin = 2;
|
||||
optional string sign_out = 3;
|
||||
repeated string blocked = 4;
|
||||
int64 deadair_saved = 5;
|
||||
optional Theme theme = 6;
|
||||
string version = 7;
|
||||
bool typesafe_key_set = 8;
|
||||
// "server" or "own".
|
||||
string signals = 9;
|
||||
uint64 signal_days = 10;
|
||||
}
|
||||
|
||||
// PATCH /api/me, the body.
|
||||
message MePatch {
|
||||
Words blocked = 1;
|
||||
google.protobuf.Value typesafe_key = 2;
|
||||
}
|
||||
|
||||
message ApiToken {
|
||||
int64 id = 1;
|
||||
string name = 2;
|
||||
int64 created = 3;
|
||||
optional int64 last_used = 4;
|
||||
}
|
||||
|
||||
// GET /api/tokens.
|
||||
message ApiTokens {
|
||||
repeated ApiToken items = 1;
|
||||
}
|
||||
|
||||
// POST /api/tokens, the body.
|
||||
message NewToken {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
// POST /api/tokens, the answer: the only time the token is shown.
|
||||
message MadeToken {
|
||||
int64 id = 1;
|
||||
string name = 2;
|
||||
string token = 3;
|
||||
}
|
||||
|
||||
// POST /api/push/devices, the body.
|
||||
message PushDevice {
|
||||
string token = 1;
|
||||
optional bool sandbox = 2;
|
||||
}
|
||||
|
||||
// ---- feeds ----
|
||||
|
||||
message FailingRow {
|
||||
string reason = 1;
|
||||
optional string new_url = 2;
|
||||
}
|
||||
|
||||
message FeedRow {
|
||||
string id = 1;
|
||||
string url = 2;
|
||||
optional string title = 3;
|
||||
optional string image = 4;
|
||||
optional string folder = 5;
|
||||
optional string category = 6;
|
||||
optional string feed_category = 7;
|
||||
repeated string keywords = 8;
|
||||
repeated string blocked = 9;
|
||||
bool deadair = 10;
|
||||
int64 deadair_pause = 11;
|
||||
bool allow_explicit = 12;
|
||||
bool auto_download = 13;
|
||||
optional uint64 max_new_per_check = 14;
|
||||
optional string group = 15;
|
||||
bool orphaned = 16;
|
||||
bool managed = 17;
|
||||
optional string schedule = 18;
|
||||
optional uint64 schedule_mins = 19;
|
||||
uint64 every_mins = 20;
|
||||
optional int64 last_checked = 21;
|
||||
optional int64 next_check = 22;
|
||||
optional string last_error = 23;
|
||||
optional FailingRow failing = 24;
|
||||
int64 entries = 25;
|
||||
int64 downloaded = 26;
|
||||
int64 unread = 27;
|
||||
int64 subscribers = 28;
|
||||
bool pinned = 29;
|
||||
bool kept = 30;
|
||||
bool hide_from_all = 31;
|
||||
bool hide_from_signals = 32;
|
||||
bool private = 33;
|
||||
bool private_by_address = 34;
|
||||
}
|
||||
|
||||
// GET /api/feeds.
|
||||
message FeedRows {
|
||||
repeated FeedRow items = 1;
|
||||
}
|
||||
|
||||
// POST /api/feeds, the body.
|
||||
message NewFeed {
|
||||
string url = 1;
|
||||
optional string folder = 2;
|
||||
repeated string keywords = 3;
|
||||
optional bool allow_explicit = 4;
|
||||
}
|
||||
|
||||
// POST /api/feeds, the answer.
|
||||
message AddedFeed {
|
||||
string id = 1;
|
||||
bool existing = 2;
|
||||
}
|
||||
|
||||
// PATCH /api/feeds/{id}, the body: what is there changes, what is not is left.
|
||||
message FeedPatch {
|
||||
optional string url = 1;
|
||||
google.protobuf.Value schedule = 2;
|
||||
google.protobuf.Value folder = 3;
|
||||
google.protobuf.Value category = 4;
|
||||
Words keywords = 5;
|
||||
Words blocked = 6;
|
||||
optional bool allow_explicit = 7;
|
||||
optional bool auto_download = 8;
|
||||
google.protobuf.Value max_new_per_check = 9;
|
||||
optional bool pinned = 10;
|
||||
optional bool kept = 11;
|
||||
optional bool hide_from_all = 12;
|
||||
optional bool hide_from_signals = 13;
|
||||
google.protobuf.Value deadair = 14;
|
||||
optional int64 deadair_pause = 15;
|
||||
optional bool private = 16;
|
||||
}
|
||||
|
||||
// POST /api/feeds/{id}/download-latest, the body.
|
||||
message HowMany {
|
||||
optional int64 count = 1;
|
||||
}
|
||||
|
||||
// POST /api/feeds/{id}/download-latest, the answer.
|
||||
message Queued {
|
||||
uint64 queued = 1;
|
||||
}
|
||||
|
||||
// POST /api/feeds/{id}/read-all, POST /api/read-all.
|
||||
message Marked {
|
||||
uint64 marked = 1;
|
||||
}
|
||||
|
||||
// POST /api/fetch, the body.
|
||||
message FetchBody {
|
||||
optional string feed = 1;
|
||||
optional bool force = 2;
|
||||
}
|
||||
|
||||
// POST /api/opml, the body.
|
||||
message OpmlBody {
|
||||
string xml = 1;
|
||||
}
|
||||
|
||||
// POST /api/opml, the answer.
|
||||
message OpmlImported {
|
||||
uint64 added = 1;
|
||||
uint64 already = 2;
|
||||
}
|
||||
|
||||
// ---- items ----
|
||||
|
||||
message EncRow {
|
||||
int64 id = 1;
|
||||
optional int64 deadair = 2;
|
||||
optional bool deadair_pending = 3;
|
||||
string feed_id = 4;
|
||||
string guid = 5;
|
||||
string url = 6;
|
||||
optional string mime = 7;
|
||||
optional int64 length = 8;
|
||||
optional string path = 9;
|
||||
string state = 10;
|
||||
optional string last_error = 11;
|
||||
}
|
||||
|
||||
// GET /api/entries/{feed_id}/{guid}.
|
||||
message EntryRow {
|
||||
string guid = 1;
|
||||
string feed_id = 2;
|
||||
optional string title = 3;
|
||||
optional string link = 4;
|
||||
optional int64 published = 5;
|
||||
optional string description = 6;
|
||||
optional string markdown = 7;
|
||||
optional string markdown_html = 8;
|
||||
bool read = 9;
|
||||
bool flagged = 10;
|
||||
optional string image = 11;
|
||||
optional int64 duration = 12;
|
||||
optional int64 episode = 13;
|
||||
optional int64 season = 14;
|
||||
int64 position = 15;
|
||||
repeated EncRow enclosures = 16;
|
||||
}
|
||||
|
||||
// GET /api/entries, /api/feeds/{id}/entries, /api/signals/{id}/entries.
|
||||
message EntryPage {
|
||||
int64 total = 1;
|
||||
repeated EntryRow entries = 2;
|
||||
}
|
||||
|
||||
// POST /api/entries/{feed_id}/{guid}/flags, the body. The answer is the feed's FeedRow, or an
|
||||
// empty one when the feed is not yours.
|
||||
message Flags {
|
||||
optional bool read = 1;
|
||||
optional bool flagged = 2;
|
||||
}
|
||||
|
||||
// POST /api/entries/{feed_id}/{guid}/position, the body.
|
||||
message Position {
|
||||
int64 secs = 1;
|
||||
optional int64 duration = 2;
|
||||
optional int64 deadair = 3;
|
||||
}
|
||||
|
||||
// POST /api/entries/{feed_id}/{guid}/share, the body.
|
||||
message ShareBody {
|
||||
optional int64 enc = 1;
|
||||
}
|
||||
|
||||
// POST /api/entries/{feed_id}/{guid}/share, the answer.
|
||||
message ShareLink {
|
||||
optional string url = 1;
|
||||
optional string why = 2;
|
||||
}
|
||||
|
||||
// ---- Signals ----
|
||||
|
||||
message SignalRow {
|
||||
int64 id = 1;
|
||||
string name = 2;
|
||||
repeated string keywords = 3;
|
||||
optional string description = 4;
|
||||
optional string icon = 5;
|
||||
int64 items = 6;
|
||||
int64 unread = 7;
|
||||
}
|
||||
|
||||
// GET /api/signals.
|
||||
message SignalRows {
|
||||
repeated SignalRow items = 1;
|
||||
}
|
||||
|
||||
// POST /api/signals and PATCH /api/signals/{id}, the body.
|
||||
message SignalBody {
|
||||
optional string name = 1;
|
||||
Words keywords = 2;
|
||||
google.protobuf.Value description = 3;
|
||||
google.protobuf.Value icon = 4;
|
||||
}
|
||||
|
||||
// POST /api/signals, the answer.
|
||||
message SignalId {
|
||||
int64 id = 1;
|
||||
}
|
||||
|
||||
// POST /api/signals/icon, the body. Each candidate is [icon, label].
|
||||
message IconAsk {
|
||||
string name = 1;
|
||||
repeated string keywords = 2;
|
||||
optional string description = 3;
|
||||
repeated google.protobuf.ListValue candidates = 4;
|
||||
}
|
||||
|
||||
// POST /api/signals/icon, the answer.
|
||||
message Icon {
|
||||
string icon = 1;
|
||||
}
|
||||
|
||||
// ---- the directory ----
|
||||
|
||||
message PopularRow {
|
||||
string id = 1;
|
||||
optional string title = 2;
|
||||
optional string image = 3;
|
||||
int64 subscribers = 4;
|
||||
bool subscribed = 5;
|
||||
optional string feed = 6;
|
||||
optional string category = 7;
|
||||
optional string subcategory = 8;
|
||||
bool podcast = 9;
|
||||
}
|
||||
|
||||
// GET /api/popular, GET /api/directory.
|
||||
message PopularRows {
|
||||
repeated PopularRow items = 1;
|
||||
}
|
||||
|
||||
message ListedItem {
|
||||
string guid = 1;
|
||||
optional string title = 2;
|
||||
optional string link = 3;
|
||||
optional int64 published = 4;
|
||||
optional int64 duration = 5;
|
||||
optional string description = 6;
|
||||
}
|
||||
|
||||
// GET /api/directory/{id}.
|
||||
message Listed {
|
||||
optional string description = 1;
|
||||
optional string failing = 2;
|
||||
repeated ListedItem items = 3;
|
||||
bool can_admin = 4;
|
||||
}
|
||||
|
||||
// POST /api/popular/{id}, the answer.
|
||||
message FeedId {
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message BlockedRow {
|
||||
string id = 1;
|
||||
optional string title = 2;
|
||||
int64 at = 3;
|
||||
}
|
||||
|
||||
// GET /api/directory-admin.
|
||||
message DirAdmin {
|
||||
repeated directory.Instance instances = 1;
|
||||
repeated BlockedRow blocked = 2;
|
||||
}
|
||||
|
||||
// When the snapshot last went: a SnapshotResult's fields when it was taken, the error when not.
|
||||
message Shared {
|
||||
int64 at = 1;
|
||||
optional uint64 accepted = 2;
|
||||
optional uint64 refused_private = 3;
|
||||
optional uint64 refused_blocked = 4;
|
||||
optional uint64 refused_invalid = 5;
|
||||
optional string error = 6;
|
||||
}
|
||||
|
||||
// GET /api/directory-status.
|
||||
message DirStatus {
|
||||
bool configured = 1;
|
||||
optional string name = 2;
|
||||
optional string access = 3;
|
||||
optional string error = 4;
|
||||
optional Shared shared = 5;
|
||||
}
|
||||
|
||||
// ---- the server ----
|
||||
|
||||
// GET /api/status.
|
||||
message Status {
|
||||
uint64 feeds = 1;
|
||||
int64 pending = 2;
|
||||
int64 downloaded = 3;
|
||||
string version = 4;
|
||||
}
|
||||
|
||||
// GET /api/settings.
|
||||
message Settings {
|
||||
string schedule = 1;
|
||||
uint64 every_mins = 2;
|
||||
uint64 max_new_per_check = 3;
|
||||
repeated string media_types = 4;
|
||||
string download_dir = 5;
|
||||
double max_total_gb = 6;
|
||||
uint64 max_age_days = 7;
|
||||
uint64 art_cache_mb = 8;
|
||||
string directory_url = 9;
|
||||
bool directory_token_set = 10;
|
||||
bool directory_share = 11;
|
||||
string play_url = 12;
|
||||
bool play_token_set = 13;
|
||||
bool signals_on_server = 14;
|
||||
uint64 signal_days = 15;
|
||||
bool typesafe_server_key = 16;
|
||||
}
|
||||
|
||||
// PATCH /api/settings, the body.
|
||||
message SettingsPatch {
|
||||
optional string schedule = 1;
|
||||
optional uint64 max_new_per_check = 2;
|
||||
Words media_types = 3;
|
||||
optional double max_total_gb = 4;
|
||||
optional uint64 max_age_days = 5;
|
||||
optional uint64 art_cache_mb = 6;
|
||||
optional string directory_url = 7;
|
||||
optional string directory_token = 8;
|
||||
optional bool directory_share = 9;
|
||||
optional string play_url = 10;
|
||||
optional string play_token = 11;
|
||||
optional bool signals_on_server = 12;
|
||||
optional uint64 signal_days = 13;
|
||||
}
|
||||
|
||||
message Account {
|
||||
int64 id = 1;
|
||||
string name = 2;
|
||||
bool admin = 3;
|
||||
bool password = 4;
|
||||
optional int64 created = 5;
|
||||
optional int64 last_login = 6;
|
||||
}
|
||||
|
||||
// GET /api/users.
|
||||
message Accounts {
|
||||
repeated Account items = 1;
|
||||
}
|
||||
|
||||
// POST /api/users, the body.
|
||||
message NewUser {
|
||||
string name = 1;
|
||||
optional string password = 2;
|
||||
optional bool admin = 3;
|
||||
}
|
||||
|
||||
// PATCH /api/users/{id}, the body.
|
||||
message UserPatch {
|
||||
bool admin = 1;
|
||||
}
|
||||
|
||||
message LogLine {
|
||||
uint64 seq = 1;
|
||||
int64 ts = 2;
|
||||
string level = 3;
|
||||
string target = 4;
|
||||
string msg = 5;
|
||||
}
|
||||
|
||||
// GET /api/logs.
|
||||
message LogPage {
|
||||
repeated LogLine lines = 1;
|
||||
uint64 latest = 2;
|
||||
}
|
||||
|
||||
// POST /api/client, the body.
|
||||
message ClientEvent {
|
||||
string ev = 1;
|
||||
optional string msg = 2;
|
||||
optional string src = 3;
|
||||
optional uint32 line = 4;
|
||||
optional string feed = 5;
|
||||
optional int64 enclosure = 6;
|
||||
optional bool deadair = 7;
|
||||
optional uint64 ms = 8;
|
||||
optional string filter = 9;
|
||||
optional string trace = 10;
|
||||
optional string span = 11;
|
||||
optional uint64 start = 12;
|
||||
optional string state = 13;
|
||||
}
|
||||
25
crates/wire/proto/play.proto
Normal file
25
crates/wire/proto/play.proto
Normal file
@@ -0,0 +1,25 @@
|
||||
// ipx-play's API (crates/play/src/lib.rs), each message named after the Rust struct it mirrors.
|
||||
// A field added there goes here too; debug builds refuse an answer with a field missing here.
|
||||
syntax = "proto3";
|
||||
package play;
|
||||
|
||||
// POST /v1/shares, the body.
|
||||
message Episode {
|
||||
string feed_url = 1;
|
||||
string guid = 2;
|
||||
optional string feed_title = 3;
|
||||
optional string feed_image = 4;
|
||||
optional string title = 5;
|
||||
optional string description = 6;
|
||||
optional string link = 7;
|
||||
optional int64 published = 8;
|
||||
optional int64 duration = 9;
|
||||
string audio_url = 10;
|
||||
optional string mime = 11;
|
||||
}
|
||||
|
||||
// POST /v1/shares, the answer.
|
||||
message Shared {
|
||||
string id = 1;
|
||||
string url = 2;
|
||||
}
|
||||
Reference in New Issue
Block a user