mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-05-06 06:13:22 -04:00
* First draft on task system usage, still missing job system * Scan location roughly working, a ton of stuff to fix yet * Updating some deps due to crashes and bugs * Exposing non critical errors to frontend * Getting active job reports from job system * Using boxed opaque type to avoid a downcast issue with generics * Task system issues discovered on race conditions * Enable debug * Fix job report in the job manager * Fix race condition on steal tasks * Fixed race condition on task suspend * Some fixes on job progress reporting and save * Fixed many race conditions and a hard deadlock Also some progress report polishing * Ignore .ts and .mts video files for now * Some better logs * bruh * Internal deadlocks and excess of communication in the task system - Also better logs * Bunch of fixes and optimizations * WIP at fixing file identifier * Fixed file identifier job - still need to work on its progress report frontend * A bunch of polishing * Fixed some bugs and did more polishing * Cleanup * Bridging old and new job systems * A ton of fixes * A bunch of bugs related to shutdown and resume * Indexer and watcher bugs * Log normalizing * Fixing CI * Change error! to warn! on non critical errors log * Fix redirect to new location * Type annotation * Bogus merge resolution on cargo lock
86 lines
2.4 KiB
Rust
86 lines
2.4 KiB
Rust
use crate::util::InfallibleResponse;
|
|
|
|
use std::{fmt::Debug, panic::Location};
|
|
|
|
use axum::{
|
|
body::{self, BoxBody},
|
|
http::{self, HeaderValue, Method, Request, Response, StatusCode},
|
|
middleware::Next,
|
|
};
|
|
use http_body::Full;
|
|
use tracing::debug;
|
|
|
|
#[track_caller]
|
|
pub(crate) fn bad_request(e: impl Debug) -> http::Response<BoxBody> {
|
|
debug!(caller = %Location::caller(), ?e, "400: Bad Request;");
|
|
|
|
InfallibleResponse::builder()
|
|
.status(StatusCode::BAD_REQUEST)
|
|
.body(body::boxed(Full::from("")))
|
|
}
|
|
|
|
#[track_caller]
|
|
pub(crate) fn not_found(e: impl Debug) -> http::Response<BoxBody> {
|
|
debug!(caller = %Location::caller(), ?e, "404: Not Found;");
|
|
|
|
InfallibleResponse::builder()
|
|
.status(StatusCode::NOT_FOUND)
|
|
.body(body::boxed(Full::from("")))
|
|
}
|
|
|
|
#[track_caller]
|
|
pub(crate) fn internal_server_error(e: impl Debug) -> http::Response<BoxBody> {
|
|
debug!(caller = %Location::caller(), ?e, "500: Internal Server Error;");
|
|
|
|
InfallibleResponse::builder()
|
|
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
|
.body(body::boxed(Full::from("")))
|
|
}
|
|
|
|
#[track_caller]
|
|
pub(crate) fn not_implemented(e: impl Debug) -> http::Response<BoxBody> {
|
|
debug!(caller = %Location::caller(), ?e, "501: Not Implemented;");
|
|
|
|
InfallibleResponse::builder()
|
|
.status(StatusCode::NOT_IMPLEMENTED)
|
|
.body(body::boxed(Full::from("")))
|
|
}
|
|
|
|
pub(crate) async fn cors_middleware<B>(req: Request<B>, next: Next<B>) -> Response<BoxBody> {
|
|
if req.method() == Method::OPTIONS {
|
|
return Response::builder()
|
|
.header("Access-Control-Allow-Methods", "GET, HEAD, POST, OPTIONS")
|
|
.header("Access-Control-Allow-Origin", "*")
|
|
.header("Access-Control-Allow-Headers", "*")
|
|
.header("Access-Control-Max-Age", "86400")
|
|
.status(StatusCode::OK)
|
|
.body(body::boxed(Full::from("")))
|
|
.expect("Invalid static response!");
|
|
}
|
|
|
|
let is_upgrade_request = req.headers().get("Upgrade").is_some();
|
|
|
|
let mut response = next.run(req).await;
|
|
|
|
{
|
|
let headers = response.headers_mut();
|
|
|
|
headers.insert("Access-Control-Allow-Origin", HeaderValue::from_static("*"));
|
|
|
|
headers.insert(
|
|
"Access-Control-Allow-Headers",
|
|
HeaderValue::from_static("*"),
|
|
);
|
|
|
|
// With websocket requests, setting this causes the browser to loose it's shit.
|
|
if !is_upgrade_request {
|
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection
|
|
headers.insert("Connection", HeaderValue::from_static("Keep-Alive"));
|
|
}
|
|
|
|
headers.insert("Server", HeaderValue::from_static("Spacedrive"));
|
|
}
|
|
|
|
response
|
|
}
|