diff --git a/src/routes.rs b/src/routes.rs index 7ae0c9f..861369f 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -11,6 +11,7 @@ use actix_files::NamedFile; use actix_multipart::Multipart; use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound}; use actix_web::http; +use actix_web::http::header::{ContentDisposition, DispositionType}; use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse}; use anyhow::{anyhow, Result}; use futures_util::TryStreamExt; @@ -42,6 +43,7 @@ pub struct State { #[derive(Deserialize)] pub struct RawRequest { native: Option, + inline: Option, } #[get("/api/raw/{hash}")] @@ -50,8 +52,9 @@ pub async fn get_raw( web::Query(query): web::Query, hash: web::Path, ) -> Result, Error> { - let address = Address::decode(&b58_decode(hash.into_inner()).map_err(ErrorInternalServerError)?) - .map_err(ErrorInternalServerError)?; + let address = + Address::decode(&b58_decode(hash.into_inner()).map_err(ErrorInternalServerError)?) + .map_err(ErrorInternalServerError)?; if let Address::Hash(hash) = address { let connection = state.upend.connection().map_err(ErrorInternalServerError)?; @@ -71,7 +74,14 @@ pub async fn get_raw( let file_path = state.upend.vault_path.join(&file.path); if query.native.is_none() { - Ok(Either::A(NamedFile::open(file_path)?)) + Ok(Either::A(if query.inline.is_some() { + NamedFile::open(file_path)?.set_content_disposition(ContentDisposition { + disposition: DispositionType::Inline, + parameters: vec![], + }) + } else { + NamedFile::open(file_path)? + })) } else if state.desktop_enabled { #[cfg(feature = "desktop")] { @@ -370,8 +380,9 @@ pub async fn get_file( state: web::Data, hash: web::Path, ) -> Result { - let address = Address::decode(&b58_decode(hash.into_inner()).map_err(ErrorInternalServerError)?) - .map_err(ErrorInternalServerError)?; + let address = + Address::decode(&b58_decode(hash.into_inner()).map_err(ErrorInternalServerError)?) + .map_err(ErrorInternalServerError)?; if let Address::Hash(hash) = address { let connection = state.upend.connection().map_err(ErrorInternalServerError)?; diff --git a/webui/src/components/display/BlobPreview.svelte b/webui/src/components/display/BlobPreview.svelte index bb112d6..4b95e25 100644 --- a/webui/src/components/display/BlobPreview.svelte +++ b/webui/src/components/display/BlobPreview.svelte @@ -10,8 +10,8 @@ $: mimeType = String($entity?.get("FILE_MIME")); $: handled = Boolean(mimeType) && - ["audio", "video", "image", "model", "text"].some((prefix) => - mimeType.startsWith(prefix) + ["audio", "video", "image", "model", "text", "application/pdf"].some( + (prefix) => mimeType.startsWith(prefix) ); let imageLoaded = null; @@ -48,6 +48,9 @@ /> {/if} + {#if mimeType == "application/pdf"} +