aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-06-12 23:51:20 +0200
committermetamuffin <metamuffin@disroot.org>2023-06-12 23:51:20 +0200
commit77274b9a2af62124293b5a8a0ec0e430fa046de8 (patch)
tree15f176d57b4ea4d96f85eb9ba24bc94ab1b1660f
parent161693f372ea01d945b111501c6c1af4182c283d (diff)
downloadjellything-77274b9a2af62124293b5a8a0ec0e430fa046de8.tar
jellything-77274b9a2af62124293b5a8a0ec0e430fa046de8.tar.bz2
jellything-77274b9a2af62124293b5a8a0ec0e430fa046de8.tar.zst
flat view
-rw-r--r--server/src/routes/mod.rs2
-rw-r--r--server/src/routes/ui/browser.rs30
-rw-r--r--server/src/routes/ui/home.rs2
-rw-r--r--server/src/routes/ui/layout.rs1
-rw-r--r--server/src/routes/ui/mod.rs1
-rw-r--r--server/src/routes/ui/node.rs54
6 files changed, 68 insertions, 22 deletions
diff --git a/server/src/routes/mod.rs b/server/src/routes/mod.rs
index 8819cf8..4cbdb6e 100644
--- a/server/src/routes/mod.rs
+++ b/server/src/routes/mod.rs
@@ -22,6 +22,7 @@ use ui::{
r_account_register, r_account_register_post,
settings::{r_account_settings, r_account_settings_post},
},
+ browser::r_all_items,
error::r_catch,
home::{r_home, r_home_unpriv},
node::{r_item_assets, r_library_node},
@@ -67,6 +68,7 @@ pub fn build_rocket(
r_home_unpriv,
r_favicon,
r_item_assets,
+ r_all_items,
r_library_node,
r_assets_style,
r_assets_font,
diff --git a/server/src/routes/ui/browser.rs b/server/src/routes/ui/browser.rs
new file mode 100644
index 0000000..04d9b7c
--- /dev/null
+++ b/server/src/routes/ui/browser.rs
@@ -0,0 +1,30 @@
+use super::{account::session::Session, error::MyError, layout::DynLayoutPage, node::ItemCard};
+use crate::library::{Library, Node};
+use rocket::{get, State};
+use std::collections::VecDeque;
+
+#[get("/items")]
+pub fn r_all_items(_sess: Session, library: &State<Library>) -> Result<DynLayoutPage<'_>, MyError> {
+ let mut dirs = VecDeque::from_iter(Some(library.root.get_directory().unwrap()));
+ let mut items = Vec::new();
+ while let Some(d) = dirs.pop_front() {
+ for e in &d.children {
+ match e.as_ref() {
+ Node::Directory(d) => dirs.push_back(d.clone()),
+ Node::Item(i) => items.push(i.clone()),
+ }
+ }
+ }
+ Ok(super::layout::LayoutPage {
+ title: "All Items".to_owned(),
+ content: markup::new! {
+ .page.dir {
+ h1 { "All Items" }
+ ul.directorylisting { @for item in &items {
+ li { @ItemCard { item: &item } }
+ }}
+ }
+ },
+ ..Default::default()
+ })
+}
diff --git a/server/src/routes/ui/home.rs b/server/src/routes/ui/home.rs
index dde2369..cdde478 100644
--- a/server/src/routes/ui/home.rs
+++ b/server/src/routes/ui/home.rs
@@ -18,7 +18,7 @@ pub fn r_home(_sess: Session, library: &State<Library>) -> DynLayoutPage {
title: "Home".to_string(),
content: markup::new! {
p { "Welcome to " @CONF.brand }
- @NodePage { node: library.root.clone() }
+ @NodePage { node: &library.root }
},
..Default::default()
}
diff --git a/server/src/routes/ui/layout.rs b/server/src/routes/ui/layout.rs
index 746b534..ecccc7c 100644
--- a/server/src/routes/ui/layout.rs
+++ b/server/src/routes/ui/layout.rs
@@ -34,6 +34,7 @@ markup::define! {
h1 { a[href="/"] { @CONF.brand } }
@if let Some(_) = session {
a[href="/library"] { "My Library" }
+ a[href="/items"] { "All Items" }
}
div.account {
diff --git a/server/src/routes/ui/mod.rs b/server/src/routes/ui/mod.rs
index d0636c5..62c8aa8 100644
--- a/server/src/routes/ui/mod.rs
+++ b/server/src/routes/ui/mod.rs
@@ -20,6 +20,7 @@ pub mod layout;
pub mod node;
pub mod player;
pub mod style;
+pub mod browser;
pub struct HtmlTemplate<'a>(pub markup::DynRender<'a>);
diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs
index e6f0809..d09c75c 100644
--- a/server/src/routes/ui/node.rs
+++ b/server/src/routes/ui/node.rs
@@ -17,7 +17,8 @@ use crate::{
use anyhow::Context;
use log::info;
use rocket::{get, http::ContentType, State};
-use std::{ops::Deref, path::PathBuf, sync::Arc};
+use rocket::{FromFormField, UriDisplayQuery};
+use std::{path::PathBuf, sync::Arc};
use tokio::fs::File;
#[get("/library/<path..>")]
@@ -32,24 +33,30 @@ pub async fn r_library_node(
Ok(LayoutPage {
title: node.title().to_string(),
content: markup::new! {
- @NodePage { node: node.clone() }
+ @NodePage { node: &node }
},
..Default::default()
})
}
markup::define! {
- NodePage(node: Arc<Node>) {
- @match node.deref() {
- Node::Directory(dir) => { @DirectoryPage { dir: dir.clone() } }
- Node::Item(item) => { @ItemPage { item: item.clone() } }
+ NodePage<'a>(node: &'a Arc<Node>) {
+ @match node.as_ref() {
+ Node::Directory(dir) => { @DirectoryPage { dir } }
+ Node::Item(item) => { @ItemPage { item } }
}
}
- DirectoryCard(dir: Arc<Directory>) {
+ NodeCard<'a>(node: &'a Arc<Node>) {
+ @match node.as_ref() {
+ Node::Directory(dir) => { @DirectoryCard { dir } }
+ Node::Item(item) => { @ItemCard { item } }
+ }
+ }
+ DirectoryCard<'a>(dir: &'a Arc<Directory>) {
div.card.dir {
div.banner {
a[href=uri!(r_library_node(&dir.lib_path))] {
- img[src=uri!(r_item_assets(&dir.lib_path))];
+ img[src=uri!(r_item_assets(&dir.lib_path, AssetRole::Banner))];
}
div.hover { a[href=uri!(r_library_node(&dir.lib_path))] { "Open" } }
}
@@ -59,29 +66,25 @@ markup::define! {
}
}
}
- // a[href=&uri!(r_library_node(&dir.lib_path))] { @dir.info.name } }
}
- DirectoryPage(dir: Arc<Directory>) {
+ DirectoryPage<'a>(dir: &'a Arc<Directory>) {
div.page.dir {
h1 { @dir.info.name }
@if let Some(parent) = dir.lib_path.parent() {
a.dirup[href=uri!(r_library_node(&parent))] { "Go up" }
}
ul.directorylisting {
- @for el in &dir.children {
- li { @match el.deref().to_owned() {
- Node::Directory(dir) => { @DirectoryCard { dir } }
- Node::Item(item) => { @ItemCard { item } }
- } }
+ @for node in &dir.children {
+ li { @NodeCard { node } }
}
}
}
}
- ItemCard(item: Arc<Item>) {
+ ItemCard<'a>(item: &'a Arc<Item>) {
div.card.item {
div.banner {
a[href=uri!(r_library_node(&item.lib_path))] {
- img[src=uri!(r_item_assets(&item.lib_path))];
+ img[src=uri!(r_item_assets(&item.lib_path, AssetRole::Banner))];
}
div.hover { a[href=&player_uri(&item.lib_path)] { "▶" } }
}
@@ -92,12 +95,12 @@ markup::define! {
}
}
}
- ItemPage(item: Arc<Item>) {
+ ItemPage<'a>(item: &'a Arc<Item>) {
// TODO different image here
- img.backdrop[src=uri!(r_item_assets(&item.lib_path))];
+ img.backdrop[src=uri!(r_item_assets(&item.lib_path, AssetRole::Backdrop))];
div.page.item {
div.banner {
- img[src=uri!(r_item_assets(&item.lib_path))];
+ img[src=uri!(r_item_assets(&item.lib_path, AssetRole::Banner))];
}
div.title {
h1 { @item.info.title }
@@ -112,12 +115,21 @@ markup::define! {
}
}
-#[get("/item_assets/<path..>")]
+#[derive(FromFormField, UriDisplayQuery)]
+pub enum AssetRole {
+ Banner,
+ Backdrop,
+}
+
+#[get("/item_assets/<path..>?<role>")]
pub async fn r_item_assets(
_sess: Session,
path: PathBuf,
+ role: AssetRole,
library: &State<Library>,
) -> Result<(ContentType, File), MyError> {
+ // TODO role
+ drop(role);
let node = library
.nested_path(&path)
.context("retrieving library node")?;