add warning on parent native open
parent
2ccfce6058
commit
b2768cbad9
|
@ -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.",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
--background: #{$background};
|
||||
--background-emph: #{color.scale($background, $lightness: -3%)};
|
||||
--error: darkred;
|
||||
--warning: orange;
|
||||
font-size: 15px;
|
||||
|
||||
b {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue