open dir instead of 403 on native executable
This commit is contained in:
parent
165d5c0e7f
commit
057ac8e35f
1 changed files with 15 additions and 7 deletions
|
@ -12,7 +12,7 @@ use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound}
|
||||||
use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse};
|
use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use log::{debug, info, trace, error};
|
use log::{debug, info, trace};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -59,14 +59,22 @@ pub async fn get_raw(
|
||||||
#[cfg(feature = "desktop")]
|
#[cfg(feature = "desktop")]
|
||||||
{
|
{
|
||||||
info!("Opening {:?}...", file_path);
|
info!("Opening {:?}...", file_path);
|
||||||
if !file_path.is_executable() {
|
let path = if !file_path.is_executable() {
|
||||||
opener::open(file_path).map_err(error::ErrorServiceUnavailable)?;
|
file_path
|
||||||
return Ok(Either::B(HttpResponse::NoContent().finish()));
|
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
Err(error::ErrorBadRequest("Desktop features not enabled."))
|
Err(error::ErrorBadRequest("Desktop features not enabled."))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue