diff --git a/src/routes.rs b/src/routes.rs index 2c335f0..237da57 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -12,7 +12,7 @@ use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound} use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse}; use anyhow::Result; use futures_util::StreamExt; -use log::{debug, info, trace, error}; +use log::{debug, info, trace}; use serde::Deserialize; use serde_json::json; use std::collections::HashMap; @@ -59,14 +59,22 @@ pub async fn get_raw( #[cfg(feature = "desktop")] { info!("Opening {:?}...", file_path); - if !file_path.is_executable() { - opener::open(file_path).map_err(error::ErrorServiceUnavailable)?; - return Ok(Either::B(HttpResponse::NoContent().finish())); + let path = if !file_path.is_executable() { + file_path } else { - error!("Attempted to natively open {:?}, which is executable!", file_path); - } + file_path + .parent() + .ok_or_else(|| { + ErrorInternalServerError("No parent to open as fallback.") + })? + .to_path_buf() + }; + opener::open(path).map_err(error::ErrorServiceUnavailable)?; + return Ok(Either::B(HttpResponse::NoContent().finish())); } - Err(error::ErrorForbidden("")) + + #[cfg(not(feature = "desktop"))] + !unreachable() } else { Err(error::ErrorBadRequest("Desktop features not enabled.")) }