1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*
This file is part of jellything (https://codeberg.org/metamuffin/jellything)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
use super::{assets::rocket_uri_macro_r_item_assets, error::MyError, player::player_uri};
use crate::{
database::Database,
routes::ui::{
account::session::Session,
assets::AssetRole,
layout::{DynLayoutPage, LayoutPage},
},
uri,
};
use anyhow::{anyhow, Context};
use jellycommon::{Node, NodeKind};
use rocket::{get, State};
#[get("/library/<id>")]
pub async fn r_library_node(
_sess: Session,
id: String,
db: &State<Database>,
) -> Result<DynLayoutPage<'_>, MyError> {
let node = db
.node
.get(&id)
.context("retrieving library node")?
.ok_or(anyhow!("node does not exist"))?;
let children = node
.public
.children
.iter()
.map(|c| {
Ok((
c.to_owned(),
db.node.get(c)?.ok_or(anyhow!("child does not exist"))?,
))
})
.collect::<anyhow::Result<Vec<_>>>()?
.into_iter()
.collect();
Ok(LayoutPage {
title: node.public.title.to_string(),
show_back: matches!(node.public.kind, NodeKind::Movie | NodeKind::Episode),
content: markup::new! {
@NodePage { node: &node, id: &id, children: &children }
},
..Default::default()
})
}
markup::define! {
NodePage<'a>(id: &'a str, node: &'a Node, children: &'a Vec<(String,Node)>) {
@match node.public.kind {
NodeKind::Collection | NodeKind::Show | NodeKind::Season => { @DirectoryPage { node, id, children } }
NodeKind::Series => { @SeriesPage { node, children, id } }
NodeKind::Movie | NodeKind::Episode => { @ItemPage { node, id } }
}
}
NodeCard<'a>(id: &'a str, node: &'a Node) {
@PosterCard {
wide: matches!(node.public.kind, NodeKind::Collection),
dir: !matches!(node.public.kind, NodeKind::Movie | NodeKind::Episode),
id,
title: &node.public.title
}
}
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" }
// }
ul.directorylisting {
@for (id, node) in children.iter() {
li { @NodeCard { id, node } }
}
}
}
}
PosterCard<'a>(id: &'a str, title: &'a str, wide: bool, dir: bool) {
div[class=if *wide {"card wide poster"} else {"card poster"}] {
div.banner {
a[href=uri!(r_library_node(id))] {
img[src=uri!(r_item_assets(id, AssetRole::Poster))];
}
@if *dir {
div.hoverdir { a[href=&uri!(r_library_node(id))] { "Open" } }
} else {
div.hoveritem { a[href=&player_uri(id)] { "▶" } }
}
}
p.title {
a[href=uri!(r_library_node(id))] {
@title
}
}
}
}
ItemPage<'a>(id: &'a str, node: &'a Node) {
// TODO different image here
img.backdrop[src=uri!(r_item_assets(id, AssetRole::Backdrop))];
div.page.item {
div.banner {
img[src=uri!(r_item_assets(id, AssetRole::Poster))];
}
div.title {
h1 { @node.public.title }
// TODO release date, duration, ratings
a.play[href=&player_uri(id)] { "Watch now" }
}
div.details {
h3 { @node.public.tagline }
p { @node.public.description }
}
}
}
SeriesPage<'a>(id: &'a str, node: &'a Node, children: &'a Vec<(String,Node)>) {
// TODO different image here
img.backdrop[src=uri!(r_item_assets(id, AssetRole::Backdrop))];
div.page.item {
div.banner {
img[src=uri!(r_item_assets(id, AssetRole::Poster))];
}
div.title {
h1 { @node.public.title }
}
div.details {
h3 { @node.public.tagline }
p { @node.public.description }
}
ol { @for (id, c) in children.iter() {
li { a[href=uri!(r_library_node(id))] { @c.public.title } }
} }
}
}
}
|