From 368eb90d5ba34835f17495a985d92131b8721b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Fri, 7 Jan 2022 00:52:09 +0100 Subject: [PATCH] fix compile with no default features --- src/main.rs | 4 +--- src/previews/mod.rs | 1 + src/routes.rs | 14 ++++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3316726..8a6cd35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,12 +20,10 @@ use crate::database::UpEndDatabase; mod addressing; mod database; mod filesystem; +mod previews; mod routes; mod util; -#[cfg(feature = "previews")] -mod previews; - const VERSION: &str = env!("CARGO_PKG_VERSION"); fn main() -> Result<()> { diff --git a/src/previews/mod.rs b/src/previews/mod.rs index 1c25879..3573c42 100644 --- a/src/previews/mod.rs +++ b/src/previews/mod.rs @@ -26,6 +26,7 @@ pub struct PreviewStore { locks: Mutex>>>, } +#[cfg(feature = "previews")] impl PreviewStore { pub fn new>(path: P, db: Arc) -> Self { PreviewStore { diff --git a/src/routes.rs b/src/routes.rs index c19aadd..3b1c5ad 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -220,7 +220,9 @@ pub async fn delete_object( #[get("/api/all/attributes")] pub async fn get_all_attributes(state: web::Data) -> Result { let connection = state.upend.connection().map_err(ErrorInternalServerError)?; - let result = connection.get_all_attributes().map_err(ErrorInternalServerError)?; + let result = connection + .get_all_attributes() + .map_err(ErrorInternalServerError)?; Ok(HttpResponse::Ok().json(result)) } @@ -322,6 +324,7 @@ pub async fn get_thumbnail( state: web::Data, hash: web::Path, ) -> Result { + #[cfg(feature = "previews")] if let Some(preview_store) = &state.preview_store { let address = Address::decode(&decode(hash.into_inner()).map_err(ErrorInternalServerError)?) @@ -337,13 +340,12 @@ pub async fn get_thumbnail( file = file.set_content_type(mime); } } - Ok(file) + return Ok(file); } else { - Err(ErrorBadRequest( + return Err(ErrorBadRequest( "Address does not refer to a previewable object.", - )) + )); } - } else { - Err(error::ErrorNotImplemented("Previews not enabled.")) } + Err(error::ErrorNotImplemented("Previews not enabled.")) }