Files
spacedrive/apps/server/src/main.rs
Ericson "Fogo" Soares bcbcd260d4 ENG 223 Location Awareness (#468)
* Introducing location online/offline checks and location relink

* Some initial drafts for location watchers

* Location metadata relink and add library

* Many improvements at job system
Now using prisma batching at identifier job
Removing blocking I/O from extension subcrate
Implementing lazy generation of thumbnails
New current directory identifier job to be used on light rescans

* Some optimizations on identifier and object validator jobs

* merge jamie's identifier PR

* fully repaired identifier job

* properly hooked up object kind

* inspector fix

* fix video badge

* small improvements to libraries settings

* identifier and inspector improvements

* fix feature flags and hook up context menu location utilities

* BETTER CONTEXT MENU x100

* test-files

* style tweaks

* new icon designs

* manifest

* fix thumbnails on web

* media data

* New Location Watcher and some minor fixes

* disable broken media_data extractor, wip

* wip

* function name fix

* Fixing pnpm prep and some warnings

* Solving a race condition beetween indexer job and FS event handlerSome other minor warnings

* Generating thumbnails on watcher

* Remove event handler on watcher

* Some initial works on modify events and other small fixes

* File update event

* Trying to be more generic with used events and some tests to validate our assumptions

* Turning on location metadata file

* Introducing core unit tests on CI pipeline

* Submiting new unit test assumptions to validate on windows CI

* Fixing unit tests

* Fixing unit tests again

* Fixing unit tests

* Fixing unit tests for macos

* Fixing unit tests for macos again

* New structure for platform dependent event handling
Implementing event handlers for Linux and MacOS

* minor fixes + rustfmt + clippy

* Windows event handling

* Introducing a feature gate to only use location watching on desktop app for now

* Putting more stuff behind feature gates to avoid warnings

* Adding feature to cargo test on CI

* Changing some debug logs to trace logs and removing Jamie specific stuff

* Make location removal from manager less async

* fix build when "location-watcher" feature disabled

* fix types + clippy

* make location manager non-static

* remove uses of `to_string_lossy`

* more invalidate_query calls

* Expose `library_ctx` directly to avoid needless clones

* New materialized_path handling for directories

* Removing cascade delete between file_path and object
- Some other minor stuff

* remove unused `CurrentDirFileIdentifierJob`

Co-authored-by: Jamie Pine <ijamespine@me.com>
Co-authored-by: Oscar Beaumont <oscar@otbeaumont.me>
2022-12-31 00:53:24 +08:00

75 lines
1.9 KiB
Rust

use std::{env, net::SocketAddr, path::Path};
use axum::{
extract,
handler::Handler,
http::{header::CONTENT_TYPE, HeaderMap, StatusCode},
routing::get,
};
use sd_core::Node;
use tracing::info;
mod utils;
#[tokio::main]
async fn main() {
let data_dir = match env::var("DATA_DIR") {
Ok(path) => Path::new(&path).to_path_buf(),
Err(_e) => {
#[cfg(not(debug_assertions))]
{
panic!("'$DATA_DIR' is not set ({})", _e)
}
#[cfg(debug_assertions)]
{
std::env::current_dir()
.expect("Unable to get your current directory. Maybe try setting $DATA_DIR?")
.join("sdserver_data")
}
}
};
let port = env::var("PORT")
.map(|port| port.parse::<u16>().unwrap_or(8080))
.unwrap_or(8080);
let (node, router) = Node::new(data_dir).await.expect("Unable to create node");
let signal = utils::axum_shutdown_signal(node.clone());
let app = axum::Router::new()
.route("/", get(|| async { "Spacedrive Server!" }))
.route("/health", get(|| async { "OK" }))
.route("/spacedrive/*id", {
let node = node.clone();
get(|extract::Path(path): extract::Path<String>| async move {
let (status_code, content_type, body) = node
.handle_custom_uri(path.split('/').skip(1).collect())
.await;
(
StatusCode::from_u16(status_code).unwrap(),
{
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, content_type.parse().unwrap());
headers
},
body,
)
})
})
.route(
"/rspc/:id",
router.endpoint(move || node.get_request_context()).axum(),
)
.fallback((|| async { "404 Not Found: We're past the event horizon..." }).into_service());
let mut addr = "[::]:8080".parse::<SocketAddr>().unwrap(); // This listens on IPv6 and IPv4
addr.set_port(port);
info!("Listening on http://localhost:{}", port);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.with_graceful_shutdown(signal)
.await
.expect("Error with HTTP server!");
}