diff options
-rw-r--r-- | common/src/lib.rs | 1 | ||||
-rw-r--r-- | server/src/import.rs | 19 | ||||
-rw-r--r-- | server/src/routes/ui/account/session/guard.rs | 4 | ||||
-rw-r--r-- | server/src/routes/ui/home.rs | 5 | ||||
-rw-r--r-- | server/src/routes/ui/node.rs | 6 | ||||
-rw-r--r-- | tools/src/bin/import.rs | 3 |
6 files changed, 24 insertions, 14 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs index 7392c87..81fcfd8 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -28,6 +28,7 @@ pub struct NodePrivate { pub struct NodePublic { pub kind: NodeKind, pub title: String, + #[serde(default)] pub parent: Option<String>, #[serde(default)] pub children: Vec<String>, #[serde(default)] pub tagline: Option<String>, #[serde(default)] pub description: Option<String>, diff --git a/server/src/import.rs b/server/src/import.rs index 72fb399..c8f4f10 100644 --- a/server/src/import.rs +++ b/server/src/import.rs @@ -13,11 +13,15 @@ pub fn import(db: &Database) -> anyhow::Result<()> { info!("clearing node tree"); db.node.clear()?; info!("importing..."); - import_path(CONF.library_path.clone(), db).context("indexing")?; + import_path(CONF.library_path.clone(), db, None).context("indexing")?; Ok(()) } -pub fn import_path(path: PathBuf, db: &Database) -> anyhow::Result<Vec<String>> { +pub fn import_path( + path: PathBuf, + db: &Database, + parent: Option<String>, +) -> anyhow::Result<Vec<String>> { if path.is_dir() { let mpath = path.join("directory.json"); let children = path.read_dir()?.filter_map(|e| { @@ -30,8 +34,9 @@ pub fn import_path(path: PathBuf, db: &Database) -> anyhow::Result<Vec<String>> None } }); + let identifier = path.file_name().unwrap().to_str().unwrap().to_string(); let children = children - .map(|e| import_path(e, db)) + .map(|e| import_path(e, db, Some(identifier.clone()))) .collect::<anyhow::Result<Vec<_>>>()? .into_iter() .flatten() @@ -40,12 +45,10 @@ pub fn import_path(path: PathBuf, db: &Database) -> anyhow::Result<Vec<String>> let mut data: Node = serde_json::from_reader(File::open(mpath).context("metadata missing")?)?; - let identifier = path.file_name().unwrap().to_str().unwrap().to_string(); - data.public.children = children; + data.public.parent = parent; info!("insert {identifier}"); db.node.insert(&identifier, &data)?; - Ok(vec![identifier]) } else { Ok(children) @@ -53,7 +56,7 @@ pub fn import_path(path: PathBuf, db: &Database) -> anyhow::Result<Vec<String>> } else if path.is_file() { info!("loading item {path:?}"); let datafile = File::open(path.clone()).context("cant load metadata")?; - let data: Node = serde_json::from_reader(datafile).context("invalid metadata")?; + let mut data: Node = serde_json::from_reader(datafile).context("invalid metadata")?; let identifier = path .file_name() .unwrap() @@ -62,7 +65,9 @@ pub fn import_path(path: PathBuf, db: &Database) -> anyhow::Result<Vec<String>> .strip_suffix(".jelly") .unwrap() .to_string(); + info!("insert {identifier}"); + data.public.parent = parent; db.node.insert(&identifier, &data)?; Ok(vec![identifier]) } else { diff --git a/server/src/routes/ui/account/session/guard.rs b/server/src/routes/ui/account/session/guard.rs index 58dfe01..c6f5c29 100644 --- a/server/src/routes/ui/account/session/guard.rs +++ b/server/src/routes/ui/account/session/guard.rs @@ -3,7 +3,7 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2023 metamuffin <metamuffin.org> */ -use super::{token, Session}; +use super::Session; use crate::{database::Database, routes::ui::error::MyError}; use anyhow::anyhow; use log::warn; @@ -25,7 +25,7 @@ impl Session { .or(req.cookies().get("session").map(|cookie| cookie.value())) .ok_or(anyhow!("not logged in"))?; - username = token::validate(token)?; + username = super::token::validate(token)?; }; #[cfg(feature = "bypass-auth")] diff --git a/server/src/routes/ui/home.rs b/server/src/routes/ui/home.rs index 0b85e89..c4defd0 100644 --- a/server/src/routes/ui/home.rs +++ b/server/src/routes/ui/home.rs @@ -18,7 +18,10 @@ pub fn r_home(_sess: Session, _db: &State<Database>) -> DynLayoutPage { title: "Home".to_string(), content: markup::new! { p { "Welcome to " @CONF.brand } - // @NodePage { node: &db } + p.error { "TODO: continue watching" } + p.error { "TODO: recently added" } + p.error { "TODO: best rating" } + p.error { "TODO: random" } }, ..Default::default() } diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs index 069f478..e4bf329 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -72,9 +72,9 @@ markup::define! { DirectoryPage<'a>(_id: &'a str, node: &'a Node, children: &'a Vec<(String,Node)>) { div.page.dir { h1 { @node.public.title } - // @if let Some(parent) = node.lib_path.parent() { - // a.dirup[href=uri!(r_library_node(&parent))] { "Go up" } - // } + @if let Some(parent) = &node.public.parent { + a.dirup[href=uri!(r_library_node(parent))] { "Go up" } + } ul.directorylisting { @for (id, node) in children.iter() { li { @NodeCard { id, node } } diff --git a/tools/src/bin/import.rs b/tools/src/bin/import.rs index c886adf..28151e4 100644 --- a/tools/src/bin/import.rs +++ b/tools/src/bin/import.rs @@ -138,7 +138,7 @@ fn main() -> anyhow::Result<()> { let mut input = EbmlReader::new(input); let (tracks, local_tracks, seek_index) = import_read(&source_path.to_path_buf(), &mut input)?; - + for (tn, index) in seek_index { info!("writing index {tn} with {} blocks", index.blocks.len()); bincode::encode_into_std_write( @@ -169,6 +169,7 @@ fn main() -> anyhow::Result<()> { source, }, public: NodePublic { + parent: None, description: Some(details.overview), tagline: details.tagline, title: details.title.clone().or(details.name.clone()).unwrap(), |