From 1aa8a77b7884101714a238e0aeac0f93345d081c Mon Sep 17 00:00:00 2001 From: blek Date: Sat, 9 Dec 2023 23:02:23 +1000 Subject: [PATCH] respect the config.api.METHOD config values --- filed/src/web/api/files.rs | 7 +++++++ filed/src/web/api/files/get_all.rs | 8 ++++++-- filed/src/web/api/types.rs | 4 +++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/filed/src/web/api/files.rs b/filed/src/web/api/files.rs index d2d3873..6a599d0 100644 --- a/filed/src/web/api/files.rs +++ b/filed/src/web/api/files.rs @@ -16,4 +16,11 @@ fn check_api_enabled(state: &SharedState) -> Result<(), WithStatus> { Ok(()) } +fn function_disabled_err() -> WithStatus { + warp::reply::with_status( + json(&ErrorMessage::new(Error::APIFunctionDisabled)), + StatusCode::SERVICE_UNAVAILABLE + ) +} + pub mod get_all; \ No newline at end of file diff --git a/filed/src/web/api/files/get_all.rs b/filed/src/web/api/files/get_all.rs index 212762a..7439727 100644 --- a/filed/src/web/api/files/get_all.rs +++ b/filed/src/web/api/files/get_all.rs @@ -2,11 +2,15 @@ use warp::{reply::{Reply, json}, reject::Rejection, Filter}; use crate::web::{state::SharedState, rejection::HttpReject}; -use super::check_api_enabled; +use super::{check_api_enabled, function_disabled_err}; pub async fn get_all(state: SharedState) -> Result, Rejection> { if let Err(res) = check_api_enabled(&state) { - return Ok(Box::new(res)); + return Ok(Box::new(res)) + } + + if ! state.config.api.get_all { + return Ok(Box::new(function_disabled_err())) } Ok( diff --git a/filed/src/web/api/types.rs b/filed/src/web/api/types.rs index a1ecb62..717394f 100644 --- a/filed/src/web/api/types.rs +++ b/filed/src/web/api/types.rs @@ -3,6 +3,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub enum Error { APIDisabled, + APIFunctionDisabled } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -15,7 +16,8 @@ impl ErrorMessage { pub fn new(error: Error) -> ErrorMessage { ErrorMessage { details: match error { - Error::APIDisabled => Some("API is disabled by the administrator. Please contact them for further details".into()) + Error::APIDisabled => Some("API is disabled by the administrator. Please contact them for further details".into()), + Error::APIFunctionDisabled => Some("This API function is disabled by the administrator. Please contact them for further details.".into()) }, error, }