59 lines
1.7 KiB
Rust
59 lines
1.7 KiB
Rust
use std::fs::File;
|
|
use std::io::{Error, ErrorKind};
|
|
use uuid::Uuid;
|
|
use lumiere_domain::video::model::library_item::{LibraryItem, LibraryItemType, LibraryRawItem};
|
|
|
|
pub struct TokioVideoFile {
|
|
pub file: File
|
|
}
|
|
|
|
impl TokioVideoFile {
|
|
pub fn new(file_path: &String) -> Self {
|
|
Self {
|
|
file: File::open(file_path).expect(format!("Failed to open file {file_path}").as_str())
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
pub struct LibraryItemEntity {
|
|
pub id: Uuid,
|
|
pub name: String,
|
|
pub r#type: i8,
|
|
pub parent_folder_id: Option<Uuid>
|
|
}
|
|
|
|
impl LibraryItemEntity {
|
|
pub fn from_library_item(library_item: &LibraryItem) -> Self {
|
|
Self {
|
|
id: library_item.id.clone(),
|
|
name: library_item.name.clone(),
|
|
r#type: Self::map_type_to_i8(library_item.r#type)?,
|
|
parent_folder_id: None
|
|
}
|
|
}
|
|
|
|
fn map_type_to_i8(item_type: LibraryItemType) -> Result<i8, Error> {
|
|
match item_type {
|
|
LibraryItemType::VIDEO => Ok(0),
|
|
LibraryItemType::FOLDER => Ok(1)
|
|
}
|
|
}
|
|
|
|
fn map_type_from_i8(item_type_number: i8) -> Result<LibraryItemType, Error> {
|
|
match item_type_number {
|
|
0 => Ok(LibraryItemType::VIDEO),
|
|
1 => Ok(LibraryItemType::FOLDER),
|
|
unknown_value => Err(Error::new(ErrorKind::InvalidData, format!("Unknown library item type value from database: {unknown_value}")))
|
|
}
|
|
}
|
|
|
|
pub(crate) fn to_library_raw_item(self) -> Result<LibraryRawItem, Error> {
|
|
let library_item = LibraryRawItem {
|
|
id: Some(self.id.clone()),
|
|
name: self.name.clone(),
|
|
r#type: Self::map_type_from_i8(self.r#type)?
|
|
};
|
|
Ok(library_item)
|
|
}
|
|
} |