⎇ 53dbdf0f1deea10d6fc567ea2b43e1e75d6d60cd
crates/modules/ui_engine/libs/providers/fs/src/lib.rs
History
Who touched what
raw
chore: monorepo inicial con arje + minga + yahweh absorbidos
1//! Provider de filesystem local. Crate puro: cero dependencia de UI.
2//! Implementa `yahweh_core::DataProvider` listando hijos de un path con
3//! `std::fs::read_dir` y leyendo archivos a `Vec<u8>` via `tokio::io`.
4
5use async_trait::async_trait;
6use std::fs;
7use std::io::Cursor;
8use std::path::Path;
9use std::pin::Pin;
10use tokio::io::{AsyncRead, AsyncWrite};
11use yahweh_core::{DataProvider, DisplayType, EntityNode};
12
13pub const PROVIDER_ID: &str = "local_fs";
14
15pub struct FileDataProvider;
16
17#[async_trait]
18impl DataProvider for FileDataProvider {
19 fn provider_id(&self) -> String {
20 PROVIDER_ID.to_string()
21 }
22
23 async fn list_children(&self, parent_id: Option<&str>) -> Result<Vec<EntityNode>, String> {
24 let path = parent_id.unwrap_or(".");
25 let mut children = Vec::new();
26
27 if let Ok(entries) = fs::read_dir(path) {
28 for entry in entries.filter_map(|e| e.ok()) {
29 let path = entry.path();
30 let name = path
31 .file_name()
32 .unwrap_or_default()
33 .to_string_lossy()
34 .into_owned();
35 let display_type = if path.is_dir() {
36 DisplayType::Folder
37 } else {
38 DisplayType::File
39 };
40
41 children.push(EntityNode {
42 id: path.to_string_lossy().into_owned(),
43 name,
44 display_type,
45 mime_type: None,
46 });
47 }
48 }
49
50 Ok(children)
51 }
52
53 async fn get_read_stream(
54 &self,
55 entity_id: &str,
56 ) -> Result<Pin<Box<dyn AsyncRead + Send>>, String> {
57 let content = fs::read(Path::new(entity_id)).map_err(|e| e.to_string())?;
58 Ok(Box::pin(Cursor::new(content)))
59 }
60
61 async fn get_write_stream(
62 &self,
63 _entity_id: &str,
64 ) -> Result<Pin<Box<dyn AsyncWrite + Send>>, String> {
65 Err("Escritura en streaming no implementada para FS".to_string())
66 }
67}