diff options
author | metamuffin <metamuffin@disroot.org> | 2023-06-16 18:18:53 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-06-16 18:18:53 +0200 |
commit | ed2b5a8911e46e9cc7242aff09b8fa61f210d185 (patch) | |
tree | 72c071c0103b865d05516fa581be10342f0ad1f3 /server | |
parent | 846fe07c2d083fa1015a9ef55b440a83def6e8b8 (diff) | |
download | jellything-ed2b5a8911e46e9cc7242aff09b8fa61f210d185.tar jellything-ed2b5a8911e46e9cc7242aff09b8fa61f210d185.tar.bz2 jellything-ed2b5a8911e46e9cc7242aff09b8fa61f210d185.tar.zst |
asset api
Diffstat (limited to 'server')
-rw-r--r-- | server/src/library.rs | 18 | ||||
-rw-r--r-- | server/src/routes/api/mod.rs | 33 | ||||
-rw-r--r-- | server/src/routes/mod.rs | 5 | ||||
-rw-r--r-- | server/src/routes/ui/node.rs | 15 | ||||
-rw-r--r-- | server/src/routes/ui/style/layout.css | 2 |
5 files changed, 53 insertions, 20 deletions
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; |