Skip to main content

mendia_api/
lib.rs

1use serde::{Deserialize, Serialize};
2use ts_rs::TS;
3
4/// Wire-format movie record shared between the Mendia server and client.
5///
6/// All fields are required and non-optional — the scraper always provides them.
7/// The server maps this to its internal `db::Movie` (which adds `user` and
8/// wraps nullable fields in `Option`) when persisting to the database.
9#[derive(TS, Serialize, Deserialize, Debug, Clone)]
10#[ts(export)]
11pub struct Movie {
12    pub title: String,
13    pub year: i32,
14    pub size: i64,
15    pub hash: String,
16    pub tmdb_id: i32,
17    pub audio_languages: String,
18    pub subtitle_languages: String,
19    pub resolution: String,
20    pub dynamic_range: String,
21    pub bitrate: i32,
22    pub user: String,
23}
24
25#[derive(TS, Serialize, Deserialize, Debug, Clone)]
26#[ts(export)]
27pub struct LoginCredentials {
28    pub username: String,
29    pub password: String,
30}
31
32#[derive(TS, Serialize, Deserialize, Debug, Clone)]
33#[ts(export)]
34pub struct PushMovies {
35    pub username: String,
36    pub api_key: String,
37    pub movies: Vec<Movie>,
38    /// When `true` the server skips Telegram notifications for this push.
39    /// Useful for initial DB population or re-syncs where notifications
40    /// would be excessive.
41    #[serde(default)]
42    pub silent: bool,
43}
44
45#[derive(TS, Serialize, Deserialize, Debug, Clone)]
46#[ts(export)]
47pub struct GetTMDbApiKey {
48    pub username: String,
49    pub api_key: String,
50}
51
52#[derive(TS, Serialize, Deserialize, Debug, Clone)]
53#[ts(export)]
54pub struct GetTMDbApiKeyResult {
55    pub tmdb_api_key: Option<String>,
56}
57
58#[derive(TS, Serialize, Deserialize, Debug, Clone)]
59#[ts(export)]
60pub struct Session {
61    pub username: String,
62    pub api_key: String,
63}
64
65#[derive(TS, Serialize, Deserialize, Debug, Clone)]
66#[ts(export)]
67pub struct InvalidData {
68    pub data: String,
69    pub error_msg: String,
70}
71
72#[derive(TS, Serialize, Deserialize, Debug, Clone)]
73#[ts(export)]
74pub struct LoginFailed {
75    pub reason: String,
76}
77
78#[derive(TS, Serialize, Deserialize, Debug, Clone)]
79#[ts(export)]
80pub struct PushMoviesResult {
81    pub success: bool,
82    pub reason: String,
83}
84
85/// Event sent from backend to frontend (and received by the scraper client).
86#[derive(TS, Serialize, Deserialize, Debug, Clone)]
87#[serde(tag = "type")]
88#[ts(export)]
89pub enum MendiaReply {
90    NotImplemented { command: String },
91    InvalidData(InvalidData),
92    LoginFailed(LoginFailed),
93    Session(Session),
94    Movies { movies: Vec<Movie> },
95    PushMoviesResult(PushMoviesResult),
96    GetTMDbApiKeyResult(GetTMDbApiKeyResult),
97}
98
99/// Event sent from frontend/scraper to backend.
100#[derive(TS, Serialize, Deserialize, Debug, Clone)]
101#[serde(tag = "type")]
102#[ts(export)]
103pub enum MendiaRequest {
104    LoginCredentials(LoginCredentials),
105    GetMovies { user: String },
106    PushMovies(PushMovies),
107    GetTMDbApiKey(GetTMDbApiKey),
108}