From 3428a637ce420baef9aa9f9803e71bd587867005 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 10 Apr 2024 00:16:55 +0200 Subject: Closes #24. Changed postgres to json directory storage --- src/main.rs | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 70c67cf..cf0d39b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,5 @@ use crate::{ - config::Config, - db::init_db_pool, - routes::{device, start, status}, - services::ping::{BroadcastCommand, StatusMap}, + config::Config, routes::{device, start, status}, services::ping::{BroadcastCommand, StatusMap}, storage::Device }; use axum::{ middleware::from_fn_with_state, @@ -10,7 +7,6 @@ use axum::{ Router, }; use dashmap::DashMap; -use sqlx::PgPool; use std::{env, sync::Arc}; use time::UtcOffset; use tokio::sync::broadcast::{channel, Sender}; @@ -26,10 +22,10 @@ use utoipa::{ }; use utoipa_swagger_ui::SwaggerUi; +mod auth; mod config; -mod db; +mod storage; mod error; -mod auth; mod routes; mod services; mod wol; @@ -39,20 +35,16 @@ mod wol; paths( start::post, start::get, - start::start_payload, device::get, - device::get_payload, device::post, device::put, ), components( schemas( - start::PayloadOld, start::Payload, start::Response, - device::DevicePayload, - device::GetDevicePayload, - db::DeviceSchema, + device::Payload, + storage::DeviceSchema, ) ), modifiers(&SecurityAddon), @@ -99,34 +91,26 @@ async fn main() -> color_eyre::eyre::Result<()> { ) .init(); - let version = env!("CARGO_PKG_VERSION"); + Device::setup()?; + let version = env!("CARGO_PKG_VERSION"); info!("start webol v{}", version); - let db = init_db_pool(&config.database_url).await; - sqlx::migrate!().run(&db).await.unwrap(); - let (tx, _) = channel(32); let ping_map: StatusMap = DashMap::new(); let shared_state = AppState { - db, config: config.clone(), ping_send: tx, ping_map, }; let app = Router::new() - .route("/start", post(start::start_payload)) .route("/start/:id", post(start::post).get(start::get)) - .route( - "/device", - post(device::post).get(device::get_payload).put(device::put), - ) + .route("/device", post(device::post).put(device::put)) .route("/device/:id", get(device::get)) .route("/status", get(status::status)) - // TODO: Don't load on `None` Auth .route_layer(from_fn_with_state(shared_state.clone(), auth::auth)) .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi())) .with_state(Arc::new(shared_state)); @@ -141,7 +125,6 @@ async fn main() -> color_eyre::eyre::Result<()> { #[derive(Clone)] pub struct AppState { - db: PgPool, config: Config, ping_send: Sender, ping_map: StatusMap, -- cgit v1.2.3