Refacto get_root_folder_read_library_items.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use std::io::Read;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
|
||||
@@ -4,8 +4,6 @@ use tokio::fs::File;
|
||||
use tokio_util::codec::{BytesCodec, FramedRead};
|
||||
use futures_util::stream::StreamExt;
|
||||
use lumiere_application::video::service::VideoService;
|
||||
use lumiere_domain::video::error::VideoError;
|
||||
use lumiere_domain::video::model::library_item::LibraryItem;
|
||||
use crate::video::model::LibraryItemDto;
|
||||
|
||||
#[get("/download")]
|
||||
|
||||
@@ -6,6 +6,8 @@ use uuid::Uuid;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::fs::DirEntry;
|
||||
use lumiere_domain::video::model::video::VideoFormat::{AVI, MKV, MP4, WEBM};
|
||||
use crate::video::video_format_detector::get_content_type;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct VideoAdapter {
|
||||
@@ -24,13 +26,21 @@ impl VideoAdapter {
|
||||
.map_err(|_| VideoError::FolderBrowsingTechnicalIssue)?;
|
||||
|
||||
root_folder_files.into_iter()
|
||||
.map(|file_entry|
|
||||
file_entry.map_err(|_| VideoError::FolderBrowsingTechnicalIssue)
|
||||
.and_then(Self::map_file_into_library_raw_item)
|
||||
)
|
||||
.flat_map(Result::ok)
|
||||
.filter(Self::file_is_video_or_folder)
|
||||
.map(Self::map_file_into_library_raw_item)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn file_is_video_or_folder(file_entry: &DirEntry) -> bool {
|
||||
if file_entry.path().is_dir() {
|
||||
true
|
||||
} else {
|
||||
let content_type = get_content_type(&file_entry.path());
|
||||
matches!(content_type, AVI | MKV | MP4 | WEBM)
|
||||
}
|
||||
}
|
||||
|
||||
fn map_file_into_library_raw_item(file: DirEntry) -> Result<LibraryRawItem, VideoError> {
|
||||
let item_type = if file.path().is_dir() {
|
||||
LibraryItemType::FOLDER
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
use crate::server_mode::ServerMode;
|
||||
use crate::server_mode::ServerMode::Mocked;
|
||||
use diesel::SqliteConnection;
|
||||
use log::{debug, info};
|
||||
use rusqlite::Connection;
|
||||
use std::env;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use lumiere_application::configuration::service::ConfigurationService;
|
||||
use lumiere_application::user::service::UserService;
|
||||
use lumiere_application::video::service::VideoService;
|
||||
@@ -13,11 +7,12 @@ use lumiere_infrastructure::common::database_connection::DatabaseConnection;
|
||||
use lumiere_infrastructure::common::database_initialisation::initialise_database_tables;
|
||||
use lumiere_infrastructure::configuration::adapter::ConfigurationSqliteAdapter;
|
||||
use lumiere_infrastructure::configuration::repository::ConfigurationSqliteRepository;
|
||||
use lumiere_infrastructure::user::adapter::UserSqliteAdapter;
|
||||
use lumiere_infrastructure::user::diesel_adapter::UserDieselAdapter;
|
||||
use lumiere_infrastructure::user::diesel_repository::UserDieselRepository;
|
||||
use lumiere_infrastructure::user::repository::UserSqliteRepository;
|
||||
use lumiere_infrastructure::video::adapter::VideoAdapter;
|
||||
use rusqlite::Connection;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub struct ApplicationContext {
|
||||
pub database_connection: Arc<Mutex<Connection>>,
|
||||
|
||||
@@ -5,24 +5,12 @@ use crate::application_context::ApplicationContext;
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use dotenv::dotenv;
|
||||
use log::info;
|
||||
use rustls::ServerConfig;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Error};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use lumiere_exposition::init;
|
||||
use lumiere_infrastructure::video::video_format_detector::get_content_type;
|
||||
use tokio_cron_scheduler::{Job, JobScheduler};
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
// let path_str = "/home/florian/Videos/AirFly/GH010015.MP4";
|
||||
// let path = Path::new(path_str);
|
||||
// let file_type = get_content_type(&path);
|
||||
// let file_content_type = map_to_content_type(&file_type);
|
||||
// println!("file_type={file_content_type}");
|
||||
// ()
|
||||
dotenv().ok();
|
||||
unsafe { env::set_var("RUST_LOG", "debug"); }
|
||||
check_all_variables_are_set();
|
||||
|
||||
Reference in New Issue
Block a user