diff options
| author | metamuffin <metamuffin@disroot.org> | 2023-12-22 10:09:22 +0100 | 
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2023-12-22 10:09:22 +0100 | 
| commit | 6056fa9df419c1745b0c4f246e95c0b73fbcb645 (patch) | |
| tree | 7e08ba07ce9d00b5eae1e14857cc9b62967529f2 /import | |
| parent | b92983fb0cab2a284301b930d2b15ec0109dd93e (diff) | |
| download | jellything-6056fa9df419c1745b0c4f246e95c0b73fbcb645.tar jellything-6056fa9df419c1745b0c4f246e95c0b73fbcb645.tar.bz2 jellything-6056fa9df419c1745b0c4f246e95c0b73fbcb645.tar.zst | |
rework import pt. 3: auto children
Diffstat (limited to 'import')
| -rw-r--r-- | import/src/lib.rs | 40 | 
1 files changed, 32 insertions, 8 deletions
| diff --git a/import/src/lib.rs b/import/src/lib.rs index ed0af2d..4f83653 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -7,7 +7,7 @@  pub mod infojson;  pub mod tmdb; -use anyhow::{Context, Ok}; +use anyhow::{anyhow, Context, Ok};  use async_recursion::async_recursion;  use futures::{stream::FuturesUnordered, StreamExt};  use jellybase::{ @@ -201,8 +201,31 @@ async fn process_source(                  .await                  .context("federated import")?          } -        ImportSource::AutoChildren => { -            // TODO dont forget to update path of children +        ImportSource::AutoChildren { path: cpath } => { +            let paths = cpath +                .unwrap_or_else(|| path.parent().unwrap().to_path_buf()) +                .read_dir()? +                .map(Result::unwrap) +                .map(|e| e.path()) +                .filter(|e| e.extension() == Some(&OsStr::from_bytes(b"yaml"))); + +            let mut children = Vec::new(); +            for p in paths { +                let opts: ImportOptions = serde_yaml::from_reader(File::open(&p)?)?; +                if opts.id != id { +                    children.push(opts.id); +                } +            } +            insert_node( +                &id, +                Node { +                    private: NodePrivate::default(), +                    public: NodePublic { +                        children, +                        ..Default::default() +                    }, +                }, +            )?;          }      }      Ok(()) @@ -215,11 +238,12 @@ fn merge_node(x: Node, y: Node) -> Node {              title: x.public.title.or(y.public.title),              id: x.public.id.or(y.public.id),              path: vec![], -            children: if x.public.children.is_empty() { -                x.public.children -            } else { -                y.public.children -            }, +            children: x +                .public +                .children +                .into_iter() +                .chain(y.public.children) +                .collect(),              tagline: x.public.tagline.or(y.public.tagline),              description: x.public.description.or(y.public.description),              release_date: x.public.release_date.or(y.public.release_date), | 
