mendia_types/
lib.rs

1pub mod schema;
2
3use diesel::prelude::*;
4use serde::{Deserialize, Serialize};
5use ts_rs::TS;
6
7#[derive(TS, Serialize, Deserialize, Insertable, Queryable, Debug, Clone)]
8#[diesel(table_name = schema::movies)]
9#[ts(export)]
10pub struct Movie {
11    pub title: String,
12    pub year: i32,
13    pub size: i64,
14    pub hash: String,
15    pub tmdb_id: Option<i64>,
16    pub audio_languages: Option<String>,
17    pub subtitle_languages: Option<String>,
18    pub resolution: Option<String>,
19    pub dynamic_range: Option<String>,
20    pub bitrate: Option<i64>,
21    pub user: Option<String>,
22}
23
24#[derive(Insertable, Queryable)]
25#[diesel(table_name = schema::users)]
26pub struct User {
27    pub name: String,
28    pub hash: String,
29    pub salt: String,
30}
31
32#[derive(TS, Serialize, Deserialize, Debug, Clone)]
33#[ts(export)]
34pub struct LoginCredentials {
35    pub username: String,
36    pub password: String,
37}
38
39#[derive(TS, Serialize, Deserialize, Debug, Clone)]
40#[ts(export)]
41pub struct PushMovies {
42    pub username: String,
43    pub api_key: String,
44    pub movies: Vec<Movie>,
45}
46
47#[derive(TS, Serialize, Deserialize, Debug, Clone)]
48#[ts(export)]
49pub struct Session {
50    pub username: String,
51    pub api_key: String,
52}
53
54#[derive(TS, Serialize, Deserialize, Debug, Clone)]
55#[ts(export)]
56pub struct InvalidData {
57    pub data: String,
58    pub error_msg: String,
59}
60
61#[derive(TS, Serialize, Deserialize, Debug, Clone)]
62#[ts(export)]
63pub struct LoginFailed {
64    pub reason: String,
65}
66
67#[derive(TS, Serialize, Deserialize, Debug, Clone)]
68#[ts(export)]
69pub struct PushMoviesResult {
70    pub success: bool,
71    pub reason: String,
72}
73
74#[derive(TS, Serialize, Deserialize, Debug, Clone)]
75#[serde(tag = "type")]
76#[ts(export)]
77/// Event sent from backend to frontend
78pub enum BackendEvent {
79    NotImplemented { command: String },
80    InvalidData(InvalidData),
81    LoginFailed(LoginFailed),
82    Session(Session),
83    Movies { movies: Vec<Movie> },
84    PushMoviesResult(PushMoviesResult),
85}
86
87#[derive(TS, Serialize, Deserialize, Debug, Clone)]
88#[serde(tag = "type")]
89#[ts(export)]
90/// Event sent from frontend to backend
91pub enum FrontendEvent {
92    LoginCredentials(LoginCredentials),
93    GetMovies { user: String },
94    PushMovies(PushMovies),
95}