aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api.md6
-rw-r--r--server/src/library.rs18
-rw-r--r--server/src/routes/api/mod.rs33
-rw-r--r--server/src/routes/mod.rs5
-rw-r--r--server/src/routes/ui/node.rs15
-rw-r--r--server/src/routes/ui/style/layout.css2
6 files changed, 58 insertions, 21 deletions
diff --git a/api.md b/api.md
index 91cb3e3..8fac72c 100644
--- a/api.md
+++ b/api.md
@@ -20,11 +20,15 @@ Returns API version number.
Request body contains JSON with keys `username` and `password`. The Response
contains the session cookie.
-## GET* `/api/library/<path...>`
+## GET* `/api/node/<path...>`
Request a library node (either a directory or item). See
[`common/src/api.rs`](./common/src/api.rs)
+## GET* `/api/assets/node/<path..>?<role>`
+
+Where `role` is one of `Backdrop` or `Poster`. Returns assets for a node.
+
## GET* `/stream/<path..>?tracks=<track-ids>&webm=<bool>`
Responds with the stream.
diff --git a/server/src/library.rs b/server/src/library.rs
index 330f382..ffd8b4a 100644
--- a/server/src/library.rs
+++ b/server/src/library.rs
@@ -14,6 +14,8 @@ use std::{
sync::Arc,
};
+use crate::{routes::ui::node::AssetRole, CONF};
+
pub struct Library {
pub root: Arc<Node>,
pub root_path: PathBuf,
@@ -183,6 +185,22 @@ impl Node {
bail!("did somebody really put a fifo or socket in the library?!")
}
}
+
+ pub fn get_asset(&self, library: &Library, role: AssetRole) -> PathBuf {
+ let path = match role {
+ AssetRole::Backdrop => self
+ .common()
+ .backdrop
+ .clone()
+ .or_else(|| self.common().poster.clone()),
+ AssetRole::Poster => self.common().poster.clone(),
+ };
+ if let Some(p) = path {
+ library.root_path.join(p)
+ } else {
+ CONF.asset_path.join("fallback.jpeg")
+ }
+ }
}
impl Item {
diff --git a/server/src/routes/api/mod.rs b/server/src/routes/api/mod.rs
index 8f7190e..102d8b8 100644
--- a/server/src/routes/api/mod.rs
+++ b/server/src/routes/api/mod.rs
@@ -7,7 +7,10 @@ pub mod error;
use std::path::PathBuf;
-use super::ui::account::{login_logic, LoginForm};
+use super::ui::{
+ account::{login_logic, LoginForm},
+ node::AssetRole,
+};
use crate::{
database::Database,
library::{Library, Node},
@@ -15,8 +18,17 @@ use crate::{
};
use anyhow::Context;
use jellycommon::api::ApiNode;
-use rocket::{get, http::CookieJar, post, response::Redirect, serde::json::Json, State};
+use log::info;
+use rocket::{
+ get,
+ http::{ContentType, CookieJar},
+ post,
+ response::Redirect,
+ serde::json::Json,
+ State,
+};
use serde_json::{json, Value};
+use tokio::fs::File;
#[get("/api")]
pub fn r_api_root() -> Redirect {
@@ -38,8 +50,23 @@ pub fn r_api_account_login(
Ok(json!({ "ok": true }))
}
+#[get("/api/assets/node/<path..>?<role>")]
+pub async fn r_api_assets_node(
+ _sess: Session,
+ path: PathBuf,
+ role: AssetRole,
+ library: &State<Library>,
+) -> ApiResult<(ContentType, File)> {
+ let node = library
+ .nested_path(&path)
+ .context("retrieving library node")?;
+ let path = node.get_asset(library, role);
+ info!("loading asset from {path:?}");
+ Ok((ContentType::WEBP, File::open(path).await?))
+}
+
#[get("/api/library/<path..>")]
-pub fn r_api_library_node(
+pub fn r_api_node(
_sess: Session,
path: PathBuf,
library: &State<Library>,
diff --git a/server/src/routes/mod.rs b/server/src/routes/mod.rs
index 4cbdb6e..6f8109b 100644
--- a/server/src/routes/mod.rs
+++ b/server/src/routes/mod.rs
@@ -4,7 +4,7 @@
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
use crate::{database::Database, library::Library, routes::ui::error::MyResult, CONF};
-use api::{error::r_api_catch, r_api_account_login, r_api_library_node, r_api_root, r_api_version};
+use api::{error::r_api_catch, r_api_account_login, r_api_node, r_api_assets_node, r_api_root, r_api_version};
use jellyremuxer::RemuxerContext;
use rocket::{
catchers, config::SecretKey, fairing::AdHoc, fs::FileServer, get, http::Header, routes, Build,
@@ -89,7 +89,8 @@ pub fn build_rocket(
r_account_settings_post,
r_api_version,
r_api_account_login,
- r_api_library_node,
+ r_api_node,
+ r_api_assets_node,
r_api_root,
],
)
diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs
index 0b53e6d..46ab682 100644
--- a/server/src/routes/ui/node.rs
+++ b/server/src/routes/ui/node.rs
@@ -12,7 +12,6 @@ use crate::{
account::session::Session,
layout::{DynLayoutPage, LayoutPage},
},
- CONF,
};
use anyhow::Context;
use jellycommon::DirectoryKind;
@@ -153,19 +152,7 @@ pub async fn r_item_assets(
let node = library
.nested_path(&path)
.context("retrieving library node")?;
- let path = match role {
- AssetRole::Backdrop => node
- .common()
- .backdrop
- .clone()
- .or_else(|| node.common().poster.clone()),
- AssetRole::Poster => node.common().poster.clone(),
- };
- let path = if let Some(p) = path {
- library.root_path.join(p)
- } else {
- CONF.asset_path.join("fallback.jpeg")
- };
+ let path = node.get_asset(library, role);
info!("loading asset from {path:?}");
Ok((ContentType::WEBP, File::open(path).await?))
}
diff --git a/server/src/routes/ui/style/layout.css b/server/src/routes/ui/style/layout.css
index 89c12e2..07b7397 100644
--- a/server/src/routes/ui/style/layout.css
+++ b/server/src/routes/ui/style/layout.css
@@ -16,7 +16,7 @@
--dir-banner-aspect: (1.41 / 2);
--accent-light: rgb(255, 163, 87);
--accent-dark: rgb(199, 90, 0);
- --backdrop-height: 18em;
+ --backdrop-height: 24em;
--background-dark: #070707;
--background-light: #1c1c1c;
--main-side-margin: 2em;