mendia-api 1.9.0

Shared WebSocket protocol types for the Mendia ecosystem
Documentation
# mendia-api

Shared WebSocket protocol types for the [mendia ecosystem](https://crates.io/crates/mendia).

This crate defines the JSON message types exchanged between the mendia server and its clients. It is the single source of truth for the wire format.

## Types

All messages are serialized as JSON with a `"type"` discriminator field (via `#[serde(tag = "type")]`).

### Client → Server (`MendiaRequest`)

| Variant            | Fields                          | Description                             |
| ------------------ | ------------------------------- | --------------------------------------- |
| `LoginCredentials` | `username`, `password`          | Authenticate; must be the first message |
| `GetMovies`        | `user`                          | Request the full movie list             |
| `PushMovies`       | `username`, `api_key`, `movies` | Add new movies to the collection        |
| `GetTMDbApiKey`    | `username`, `api_key`           | Retrieve the server's TMDb API key      |

### Server → Client (`MendiaReply`)

| Variant               | Fields                | Description                                                         |
| --------------------- | --------------------- | ------------------------------------------------------------------- |
| `Session`             | `username`, `api_key` | Login successful; `api_key` must be included in subsequent commands |
| `LoginFailed`         | `reason`              | Authentication failed                                               |
| `Movies`              | `movies`              | Response to `GetMovies`                                             |
| `PushMoviesResult`    | `success`, `reason`   | Result of a `PushMovies` command                                    |
| `GetTMDbApiKeyResult` | `tmdb_api_key`        | Server's TMDb API key (optional)                                    |
| `InvalidData`         | `data`, `error_msg`   | Sent when a message cannot be parsed                                |
| `NotImplemented`      | `command`             | Sent for unrecognised command types                                 |

### `Movie`

The wire-format movie record used in `PushMovies` and `Movies` replies:

| Field                | Type     | Description                                                           |
| -------------------- | -------- | --------------------------------------------------------------------- |
| `title`              | `String` | Movie title                                                           |
| `year`               | `i32`    | Release year                                                          |
| `size`               | `i64`    | File size in bytes                                                    |
| `hash`               | `String` | MD5 hash of the file (for deduplication)                              |
| `tmdb_id`            | `i32`    | TMDb movie ID                                                         |
| `audio_languages`    | `String` | Comma-separated ISO 639 language codes                                |
| `subtitle_languages` | `String` | Comma-separated ISO 639 language codes                                |
| `resolution`         | `String` | e.g. `"1920x1080"`                                                    |
| `dynamic_range`      | `String` | `"SDR"`, `"HDR / HDR10"`, `"HDR / HDR10+"`, or `"HDR / Dolby Vision"` |
| `bitrate`            | `i32`    | Bitrate in bits/s                                                     |

## TypeScript bindings

TypeScript type definitions are generated from this crate via [ts-rs](https://crates.io/crates/ts-rs) and included in the [mendia npm package](https://www.npmjs.com/package/mendia).

## Ecosystem

| Crate                                                     | Description                                                         |
| --------------------------------------------------------- | ------------------------------------------------------------------- |
| [mendia]https://crates.io/crates/mendia                 | WebSocket server                                                    |
| **mendia-api**                                            | This package — shared protocol types                                |
| [mendia-scraper]https://crates.io/crates/mendia-scraper | CLI client that scans local media files and publishes to the server |
| [mendia (npm)]https://www.npmjs.com/package/mendia      | Web frontend                                                        |