| 1 | use std::fmt::Display; |
| 2 | use serde::{Deserialize, Serialize}; |
| 3 | use serde_repr::{Deserialize_repr, Serialize_repr}; |
| 4 | |
| 5 | |
| 6 | #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] |
| 7 | pub struct ResultFile { |
| 8 | id: i32, |
| 9 | pub source_file: String, |
| 10 | pub filename: String, |
| 11 | pub length: Option<f64>, |
| 12 | pub onset: Option<Vec<f64>>, |
| 13 | } |
| 14 | |
| 15 | impl Display for ResultFile { |
| 16 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 17 | write!( |
| 18 | f, |
| 19 | "{{ id: {}, source_file: {}, filename: {}, length: {:?}, onset: {:?} }}", |
| 20 | self.id, self.source_file, self.filename, self.length, self.onset |
| 21 | ) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | #[derive(Serialize, Deserialize)] |
| 26 | #[derive(Debug)] |
| 27 | pub enum Status { |
| 28 | #[serde(rename = "downloading")] |
| 29 | Downloading, |
| 30 | #[serde(rename = "splitting")] |
| 31 | Split, |
| 32 | #[serde(rename = "done")] |
| 33 | Done, |
| 34 | } |
| 35 | |
| 36 | #[derive(Serialize, Deserialize)] |
| 37 | #[derive(Debug)] |
| 38 | pub struct AudioFile { |
| 39 | pub id: i32, |
| 40 | pub name: String, |
| 41 | pub status: Status, |
| 42 | pub results: Option<Vec<ResultFile>>, |
| 43 | } |
| 44 | |
| 45 | #[derive(Serialize, Deserialize)] |
| 46 | pub struct AudioFileResponse { |
| 47 | pub code: i32, |
| 48 | pub message: String, |
| 49 | pub audio_file: AudioFile, |
| 50 | } |
| 51 | |
| 52 | #[derive(Serialize_repr, Deserialize_repr)] |
| 53 | #[repr(u8)] |
| 54 | #[derive(Debug)] |
| 55 | pub enum TauriResponse { |
| 56 | Error = 0, |
| 57 | Success = 1, |
| 58 | } |
| 59 | |
| 60 | #[derive(Serialize)] |
| 61 | pub struct PreparePlayerResponse { |
| 62 | pub status: TauriResponse, |
| 63 | pub message: String, |
| 64 | pub audio_file_name: Option<String>, |
| 65 | } |