Create a basic frontend and an endpoint to get video stream.
This commit is contained in:
@@ -7,8 +7,10 @@ use std::env;
|
||||
use std::fs;
|
||||
use std::fs::DirEntry;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use LibraryItemType::FOLDER;
|
||||
use lumiere_domain::video::model::library_item::LibraryItemType::VIDEO;
|
||||
use lumiere_domain::video::model::video::VideoFormat::{AVI, MKV, MP4, WEBM};
|
||||
use crate::video::model::LibraryItemEntity;
|
||||
use crate::video::model::{LibraryItemEntity, TokioVideoFile};
|
||||
use crate::video::repository::LibraryItemSqliteRepository;
|
||||
use crate::video::video_format_detector::get_content_type;
|
||||
|
||||
@@ -46,7 +48,7 @@ impl LibraryItemAdapter {
|
||||
|
||||
fn map_file_into_library_raw_item(file: DirEntry) -> Result<LibraryRawItem, VideoError> {
|
||||
let item_type = if file.path().is_dir() {
|
||||
LibraryItemType::FOLDER
|
||||
FOLDER
|
||||
} else {
|
||||
LibraryItemType::VIDEO
|
||||
};
|
||||
@@ -74,6 +76,12 @@ impl LibraryItemAdapter {
|
||||
database_items.iter()
|
||||
.any(|database_item| database_item.name == file_system_item.name)
|
||||
}
|
||||
|
||||
fn find_library_item_by_id(&self, library_item_id: Uuid) -> Result<Option<LibraryItem>, VideoError> {
|
||||
self.repository.find_by_id(library_item_id)
|
||||
.map_err(|_| VideoError::FileReadingTechnicalIssue)
|
||||
.map(|entity_opt| entity_opt.map(LibraryItemEntity::to_library_item))
|
||||
}
|
||||
}
|
||||
|
||||
impl VideoPort for LibraryItemAdapter {
|
||||
@@ -102,7 +110,28 @@ impl VideoPort for LibraryItemAdapter {
|
||||
}
|
||||
|
||||
fn get_video_stream(&self, video_id: Uuid) -> Result<Video, VideoError> {
|
||||
todo!()
|
||||
let video_item = self.find_library_item_by_id(video_id)?;
|
||||
|
||||
match video_item {
|
||||
None => Err(VideoError::VideoDoesNotExists),
|
||||
Some(video) => {
|
||||
match video.r#type {
|
||||
VIDEO => {
|
||||
let root_folder = env::var("ROOT_FOLDER").map_err(|_| VideoError::FolderBrowsingTechnicalIssue)?;
|
||||
let video_file_path = String::from(format!("{root_folder}/{}", video.name));
|
||||
let result = Video {
|
||||
id: video.id,
|
||||
name: video.name,
|
||||
format: AVI,
|
||||
file: Box::new(TokioVideoFile::new(&video_file_path).map_err(|_| VideoError::FileReadingTechnicalIssue)?)
|
||||
};
|
||||
|
||||
Ok(result)
|
||||
},
|
||||
FOLDER => Err(VideoError::VideoDoesNotExists)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn save(&self, library_item: &LibraryItem) -> Result<(), VideoError> {
|
||||
|
||||
Reference in New Issue
Block a user