1- use std:: collections :: HashMap ;
2-
3- use std :: path:: Path ;
4- use std :: env ;
5-
6- use std :: sync :: { Arc , Mutex } ;
7- use tokio:: time:: { self } ;
1+ use std:: {
2+ env ,
3+ path:: Path ,
4+ sync :: Arc ,
5+ { net :: SocketAddr , path :: PathBuf }
6+ } ;
7+ use tokio:: time;
88use async_trait:: async_trait;
9+ use migration:: Migrator ;
10+ use sea_orm:: DatabaseConnection ;
11+ use reqwest:: Client ;
12+ use tower_http:: normalize_path:: NormalizePathLayer ;
13+ use tower_layer:: Layer ;
14+ use axum_server:: tls_rustls:: RustlsConfig ;
15+ use axum:: {
16+ extract:: Host ,
17+ handler:: HandlerWithoutStateExt ,
18+ http:: { StatusCode , Uri } ,
19+ response:: Redirect , Extension ,
20+ } ;
921use loco_rs:: {
1022 app:: { AppContext , Hooks , Initializer } ,
1123 boot:: { create_app, BootResult , StartMode } ,
1224 controller:: AppRoutes ,
13- db:: { self , truncate_table} ,
25+ db:: truncate_table,
1426 environment:: Environment ,
1527 task:: Tasks ,
1628 worker:: { AppWorker , Processor } ,
1729 Result ,
1830} ;
19- use migration:: { Migrator } ;
20- use sea_orm:: DatabaseConnection ;
21- use serde:: { Deserialize , Serialize } ;
2231
2332use crate :: {
24- controllers, initializers,
25- models:: _entities:: { devices, notes, users} ,
2633 tasks,
34+ controllers,
35+ initializers,
36+ controllers:: ws:: ConnectionManager ,
37+ models:: _entities:: { devices, users} ,
2738} ;
2839
29- use reqwest:: { Client } ;
30- use tower_http:: normalize_path:: NormalizePathLayer ;
31- use tower_layer:: Layer ;
32- use tokio:: sync:: { mpsc, oneshot, RwLock } ;
33-
34- use axum:: {
35- extract:: Host ,
36- handler:: HandlerWithoutStateExt ,
37- http:: { StatusCode , Uri } ,
38- response:: Redirect , Extension ,
39- } ;
40- use axum_server:: tls_rustls:: RustlsConfig ;
41- use std:: { net:: SocketAddr , path:: PathBuf } ;
42-
43-
44- #[ derive( Serialize , Deserialize , Clone ) ]
45- struct JsonRpcCommand {
46- id : String ,
47- method : String ,
48- params : serde_json:: Value ,
49- }
50-
51- #[ derive( Serialize , Deserialize , Clone ) ]
52- struct JsonRpcResponse {
53- id : String ,
54- result : Option < serde_json:: Value > ,
55- error : Option < serde_json:: Value > ,
56- }
57-
58- type SharedState = Arc < RwLock < App > > ;
59-
60- use crate :: controllers:: ws:: ConnectionManager ;
61-
62- pub struct App {
63- // command_sender: mpsc::Sender<JsonRpcCommand>,
64- // pending_commands: Arc<Mutex<HashMap<String, oneshot::Sender<JsonRpcResponse>>>>,
65- // offline_queues: Arc<Mutex<HashMap<String, Vec<JsonRpcCommand>>>>, // offline queue for each device
66- }
40+ pub struct App { }
6741#[ async_trait]
6842impl Hooks for App {
6943 fn app_name ( ) -> & ' static str {
@@ -123,14 +97,13 @@ impl Hooks for App {
12397
12498 async fn truncate ( db : & DatabaseConnection ) -> Result < ( ) > {
12599 truncate_table ( db, users:: Entity ) . await ?;
126- truncate_table ( db, notes:: Entity ) . await ?;
127100 Ok ( ( ) )
128101 }
129102
130- async fn seed ( db : & DatabaseConnection , base : & Path ) -> Result < ( ) > {
131- db:: seed :: < users:: ActiveModel > ( db, & base. join ( "users.yaml" ) . display ( ) . to_string ( ) ) . await ?;
103+ async fn seed ( _db : & DatabaseConnection , _base : & Path ) -> Result < ( ) > {
104+ // db::seed::<users::ActiveModel>(db, &base.join("users.yaml").display().to_string()).await?;
132105 //db::seed::<notes::ActiveModel>(db, &base.join("notes.yaml").display().to_string()).await?;
133- db:: seed :: < devices:: ActiveModel > ( db, & base. join ( "devices.yaml" ) . display ( ) . to_string ( ) ) . await ?;
106+ // db::seed::<devices::ActiveModel>(db, &base.join("devices.yaml").display().to_string()).await?;
134107 //db::seed::<routes::ActiveModel>(db, &base.join("routes.yaml").display().to_string()).await?;
135108 //db::seed::<segments::ActiveModel>(db, &base.join("segments.yaml").display().to_string()).await?;
136109 Ok ( ( ) )
@@ -159,20 +132,10 @@ impl Hooks for App {
159132 }
160133 } ) ;
161134
162-
163-
164- //let (command_sender, _command_receiver) = mpsc::channel(100);
165- // let shared_state: Arc<RwLock<App>> = Arc::new(RwLock::new(App {
166- // command_sender,
167- // pending_commands: Arc::new(Mutex::new(HashMap::new())),
168- // offline_queues: Arc::new(Mutex::new(HashMap::new())),
169- // }));
170135 let client = Client :: new ( ) ;
171-
172136 let router = router
173137 . layer ( Extension ( client) )
174138 . layer ( Extension ( connection_manager) ) ;
175- //.layer(Extension(shared_state));
176139
177140 Ok ( router)
178141 }
@@ -241,6 +204,7 @@ struct MyServerConfig {
241204 binding : String
242205}
243206
207+ /*
244208async fn redirect_http_to_https(my_server_config: MyServerConfig) {
245209 let config_clone = my_server_config.clone(); // Clone the config for the closure
246210
@@ -274,4 +238,5 @@ async fn redirect_http_to_https(my_server_config: MyServerConfig) {
274238 axum::serve(listener, redirect.into_make_service())
275239 .await
276240 .unwrap();
277- }
241+ }
242+ */
0 commit comments