From 36eec1e694d7efade26531f194548069be53e565 Mon Sep 17 00:00:00 2001 From: Florian THIERRY Date: Thu, 16 Jul 2026 22:27:12 +0200 Subject: [PATCH] Refacto get_root_folder_read_library_items. --- backend/domain/src/video/model/library_item.rs | 1 - backend/exposition/src/video/handler.rs | 2 -- backend/infrastructure/src/video/adapter.rs | 18 ++++++++++++++---- backend/launcher/src/application_context.rs | 11 +++-------- backend/launcher/src/main.rs | 16 ++-------------- 5 files changed, 19 insertions(+), 29 deletions(-) diff --git a/backend/domain/src/video/model/library_item.rs b/backend/domain/src/video/model/library_item.rs index b6b5846..f35ea9a 100644 --- a/backend/domain/src/video/model/library_item.rs +++ b/backend/domain/src/video/model/library_item.rs @@ -1,4 +1,3 @@ -use std::io::Read; use uuid::Uuid; #[derive(Clone, Copy)] diff --git a/backend/exposition/src/video/handler.rs b/backend/exposition/src/video/handler.rs index 0b3b1c0..595e627 100644 --- a/backend/exposition/src/video/handler.rs +++ b/backend/exposition/src/video/handler.rs @@ -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")] diff --git a/backend/infrastructure/src/video/adapter.rs b/backend/infrastructure/src/video/adapter.rs index 3755dfb..182c401 100644 --- a/backend/infrastructure/src/video/adapter.rs +++ b/backend/infrastructure/src/video/adapter.rs @@ -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 { let item_type = if file.path().is_dir() { LibraryItemType::FOLDER diff --git a/backend/launcher/src/application_context.rs b/backend/launcher/src/application_context.rs index c3ecb86..a62caba 100644 --- a/backend/launcher/src/application_context.rs +++ b/backend/launcher/src/application_context.rs @@ -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>, diff --git a/backend/launcher/src/main.rs b/backend/launcher/src/main.rs index e73f5a3..ceec33f 100644 --- a/backend/launcher/src/main.rs +++ b/backend/launcher/src/main.rs @@ -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();