add warning on parent native open

feat/vaults
Tomáš Mládek 2021-12-22 11:56:06 +01:00
parent 2ccfce6058
commit b2768cbad9
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
5 changed files with 38 additions and 7 deletions

View File

@ -9,6 +9,7 @@ use crate::util::hash::{decode, encode};
use crate::util::jobs::JobContainer;
use actix_files::NamedFile;
use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound};
use actix_web::http::{self};
use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse};
use anyhow::Result;
use futures_util::StreamExt;
@ -59,9 +60,20 @@ pub async fn get_raw(
#[cfg(feature = "desktop")]
{
info!("Opening {:?}...", file_path);
let mut response = HttpResponse::NoContent();
let path = if !file_path.is_executable() {
file_path
} else {
response
.header(
http::header::WARNING,
"199 - Opening parent directory due to file being executable.",
)
.header(
http::header::ACCESS_CONTROL_EXPOSE_HEADERS,
http::header::WARNING.to_string(),
);
file_path
.parent()
.ok_or_else(|| {
@ -70,7 +82,7 @@ pub async fn get_raw(
.to_path_buf()
};
opener::open(path).map_err(error::ErrorServiceUnavailable)?;
return Ok(Either::B(HttpResponse::NoContent().finish()));
return Ok(Either::B(response.finish()));
}
#[cfg(not(feature = "desktop"))]
@ -83,7 +95,9 @@ pub async fn get_raw(
Err(error::ErrorNotFound("NOT FOUND"))
}
} else {
Err(ErrorBadRequest("Address does not refer to a rawable object."))
Err(ErrorBadRequest(
"Address does not refer to a rawable object.",
))
}
}

View File

@ -62,6 +62,7 @@
--background: #{$background};
--background-emph: #{color.scale($background, $lightness: -3%)};
--error: darkred;
--warning: orange;
font-size: 15px;
b {

View File

@ -46,6 +46,17 @@
if (!response.ok) {
throw new Error(response.statusText);
}
if (response.headers.has("warning")) {
const warningText = response.headers
.get("warning")
.split(" ")
.slice(2)
.join(" ");
notify.emit(
"notification",
new UpNotification(warningText, "warning")
);
}
})
.catch((err) => {
notify.emit(

View File

@ -19,7 +19,8 @@
});
const icons = {
error: "exclamation-triangle",
error: "x-octagon",
warning: "exclamation-triangle"
};
</script>
@ -37,4 +38,8 @@
.notification-error {
color: var(--error);
}
.notification-warning {
color: var(--warning);
}
</style>

View File

@ -4,20 +4,20 @@ type NotifyEvents = {
notification: UpNotification;
};
export type NotificationLevel = "info" | "error";
export type UpNotificationLevel = "info" | "warning" | "error";
export interface INotification {
id: string;
content: string;
level: NotificationLevel;
level: UpNotificationLevel;
}
export class UpNotification implements INotification {
id: string;
content: string;
level: NotificationLevel;
level: UpNotificationLevel;
constructor(content: string, level?: NotificationLevel) {
constructor(content: string, level?: UpNotificationLevel) {
this.id = String(Math.random());
this.content = content;
this.level = level || "info";