Implement the video adapter to retrieve the root folder content.

This commit is contained in:
Florian THIERRY
2026-07-14 21:35:55 +02:00
parent fc7eeb1d57
commit beb0134dfc
11 changed files with 90 additions and 29 deletions
+3 -2
View File
@@ -2,7 +2,7 @@ extern crate core;
use actix_web::web::ServiceConfig;
use actix_web::{get, web, HttpResponse, Responder};
use crate::video::handler::download_file;
use crate::video::handler::{download_file, get_root_folder_content};
pub mod user;
pub mod video;
@@ -13,7 +13,8 @@ async fn health() -> impl Responder {
}
pub fn init(cfg: &mut ServiceConfig) {
cfg.service(download_file);
cfg.service(download_file)
.service(get_root_folder_content);
cfg.default_service(web::to(not_found));
}
+21 -1
View File
@@ -1,7 +1,12 @@
use actix_web::{get, HttpResponse, Responder};
use std::sync::Arc;
use actix_web::{get, web, HttpResponse, Responder};
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")]
pub async fn download_file() -> impl Responder {
@@ -14,4 +19,19 @@ pub async fn download_file() -> impl Responder {
yield chunk.map(|bytes| bytes.freeze());
}
})
}
#[get("/library")]
pub async fn get_root_folder_content(
video_service: web::Data<Arc<VideoService>>
) -> impl Responder {
match video_service.list_root_folder() {
Ok(library_items) => {
let result: Vec<LibraryItemDto> = library_items.iter()
.map(LibraryItemDto::new)
.collect();
HttpResponse::Ok().json(result)
}
Err(_) => HttpResponse::InternalServerError().finish()
}
}
+1
View File
@@ -1,2 +1,3 @@
pub mod handler;
pub mod model;
pub mod video_format_content_type_mapper;
+27
View File
@@ -0,0 +1,27 @@
use lumiere_domain::video::model::library_item::{LibraryItem, LibraryItemType};
use serde::Serialize;
use uuid::Uuid;
#[derive(Serialize)]
pub struct LibraryItemDto {
pub id: Uuid,
pub name: String,
pub r#type: String
}
impl LibraryItemDto {
pub fn new(library_item: &LibraryItem) -> Self {
Self {
id: library_item.id.clone(),
name: library_item.name.clone(),
r#type: Self::map_type_to_string(library_item.r#type)
}
}
fn map_type_to_string(r#type: LibraryItemType) -> String {
match r#type {
LibraryItemType::VIDEO => String::from("VIDEO"),
LibraryItemType::FOLDER => String::from("FOLDER")
}
}
}
@@ -1,11 +1,11 @@
use lumiere_domain::video::library_item::VideoFormat;
pub fn map_to_content_type(video_format: &VideoFormat) -> &'static str {
match video_format {
VideoFormat::AVI => "video/x-msvideo",
VideoFormat::MKV => "video/x-matroska",
VideoFormat::MP4 => "video/mp4",
VideoFormat::WEBM => "video/webm",
VideoFormat::UNKNOWN => "application/octet-stream"
}
}
// use lumiere_domain::video::library_item::VideoFormat;
//
// pub fn map_to_content_type(video_format: &VideoFormat) -> &'static str {
// match video_format {
// VideoFormat::AVI => "video/x-msvideo",
// VideoFormat::MKV => "video/x-matroska",
// VideoFormat::MP4 => "video/mp4",
// VideoFormat::WEBM => "video/webm",
// VideoFormat::UNKNOWN => "application/octet-stream"
// }
// }