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:
2026-11-16 22:23:06 +00:00
parent 2671d13489
commit c0998f1ac7
26 changed files with 1282 additions and 30 deletions

View 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;
}