aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/api/mod.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-06-16 18:18:53 +0200
committermetamuffin <metamuffin@disroot.org>2023-06-16 18:18:53 +0200
commited2b5a8911e46e9cc7242aff09b8fa61f210d185 (patch)
tree72c071c0103b865d05516fa581be10342f0ad1f3 /server/src/routes/api/mod.rs
parent846fe07c2d083fa1015a9ef55b440a83def6e8b8 (diff)
downloadjellything-ed2b5a8911e46e9cc7242aff09b8fa61f210d185.tar
jellything-ed2b5a8911e46e9cc7242aff09b8fa61f210d185.tar.bz2
jellything-ed2b5a8911e46e9cc7242aff09b8fa61f210d185.tar.zst
asset api
Diffstat (limited to 'server/src/routes/api/mod.rs')
-rw-r--r--server/src/routes/api/mod.rs33
1 files changed, 30 insertions, 3 deletions
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>,