Compare commits
	
		
			4 commits
		
	
	
		
			e9b215c686
			...
			075a684ee3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						075a684ee3 | ||
| 
							 | 
						867eb24d5d | ||
| 
							 | 
						b3124948c4 | ||
| 
							 | 
						d92a1cd617 | 
					 4 changed files with 51 additions and 23 deletions
				
			
		| 
						 | 
					@ -31,26 +31,34 @@ export function Navbar() {
 | 
				
			||||||
  let login_ctx = useContext(LoginContext);
 | 
					  let login_ctx = useContext(LoginContext);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div class="navbar bg-base-100 max-w-3xl max-w flex justify-around">
 | 
					    <div class="navbar bg-base-100 max-w-3xl max-w flex">
 | 
				
			||||||
      <A href={"/"} class="btn btn-ghost normal-case text-xl">FrostByte</A>
 | 
					      <div class="flex-1">
 | 
				
			||||||
      <Menu />
 | 
					        <A href={"/"} class="btn btn-ghost normal-case text-xl">
 | 
				
			||||||
      <A
 | 
					          FrostByte
 | 
				
			||||||
        href="#"
 | 
					        </A>
 | 
				
			||||||
        class="btn btn-ghost normal-case text-sm"
 | 
					      </div>
 | 
				
			||||||
        onClick={(b) => {
 | 
					      <div class="">
 | 
				
			||||||
          b.preventDefault();
 | 
					        <Menu />
 | 
				
			||||||
          if (login_ctx?.token() != "") {
 | 
					      </div>
 | 
				
			||||||
            localStorage.setItem("token", "");
 | 
					      <div class="flex-1 justify-end">
 | 
				
			||||||
            localStorage.setItem("username", "");
 | 
					        <A
 | 
				
			||||||
            login_ctx?.setToken("");
 | 
					          href="#"
 | 
				
			||||||
            login_ctx?.setUsername("");
 | 
					          class="btn btn-ghost normal-case text-sm"
 | 
				
			||||||
            return;
 | 
					          onClick={(b) => {
 | 
				
			||||||
          }
 | 
					            b.preventDefault();
 | 
				
			||||||
          modal_ctx?.setLoginModalOpen(true);
 | 
					            if (login_ctx?.token() != "") {
 | 
				
			||||||
        }}
 | 
					              localStorage.setItem("token", "");
 | 
				
			||||||
      >
 | 
					              localStorage.setItem("username", "");
 | 
				
			||||||
        {login_ctx?.token() != "" ? login_ctx?.username() : "Login"}
 | 
					              login_ctx?.setToken("");
 | 
				
			||||||
      </A>
 | 
					              login_ctx?.setUsername("");
 | 
				
			||||||
 | 
					              return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            modal_ctx?.setLoginModalOpen(true);
 | 
				
			||||||
 | 
					          }}
 | 
				
			||||||
 | 
					        >
 | 
				
			||||||
 | 
					          {login_ctx?.token() != "" ? login_ctx?.username() : "Login"}
 | 
				
			||||||
 | 
					        </A>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								justfile
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								justfile
									
										
									
									
									
								
							| 
						 | 
					@ -32,7 +32,7 @@ build-container-release:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Builds a release container and runs it
 | 
					# Builds a release container and runs it
 | 
				
			||||||
start-release: build-container-release remove-podman-containers
 | 
					start-release: build-container-release remove-podman-containers
 | 
				
			||||||
    {{runtime}} run -d -p 8080:8080 --name frostbyte fb-server
 | 
					    {{runtime}} run -d -e DATABASE_URL=sqlite:release.db -p 8080:8080 --name frostbyte fb-server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
init-sqlx:
 | 
					init-sqlx:
 | 
				
			||||||
    echo "DATABASE_URL=sqlite:debug.db" > server/.env
 | 
					    echo "DATABASE_URL=sqlite:debug.db" > server/.env
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,11 @@ async fn main() -> std::io::Result<()> {
 | 
				
			||||||
                    .app_data(Data::new(data.clone()))
 | 
					                    .app_data(Data::new(data.clone()))
 | 
				
			||||||
                    .app_data(Data::new(capt_db.clone())),
 | 
					                    .app_data(Data::new(capt_db.clone())),
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            .service(Files::new("/", "./public").index_file("index.html"))
 | 
					            .service(
 | 
				
			||||||
 | 
					                Files::new("/", "./public")
 | 
				
			||||||
 | 
					                    .index_file("index.html")
 | 
				
			||||||
 | 
					                    .default_handler(actix_files::NamedFile::open("./public/index.html").unwrap()),
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    .bind("0.0.0.0:8080")?
 | 
					    .bind("0.0.0.0:8080")?
 | 
				
			||||||
    .run()
 | 
					    .run()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,9 +2,11 @@ use std::collections::BTreeMap;
 | 
				
			||||||
use std::sync::Arc;
 | 
					use std::sync::Arc;
 | 
				
			||||||
use std::sync::Mutex;
 | 
					use std::sync::Mutex;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use log::error;
 | 
				
			||||||
 | 
					use log::info;
 | 
				
			||||||
 | 
					use sqlx::migrate::MigrateDatabase;
 | 
				
			||||||
use sqlx::Pool;
 | 
					use sqlx::Pool;
 | 
				
			||||||
use sqlx::Sqlite;
 | 
					use sqlx::Sqlite;
 | 
				
			||||||
use sqlx::SqlitePool;
 | 
					 | 
				
			||||||
use sqlx::{self, sqlite};
 | 
					use sqlx::{self, sqlite};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone)]
 | 
					#[derive(Clone)]
 | 
				
			||||||
| 
						 | 
					@ -30,6 +32,11 @@ impl ServerState {
 | 
				
			||||||
        // This is almost certainly bad practice for more reasons than I can count
 | 
					        // This is almost certainly bad practice for more reasons than I can count
 | 
				
			||||||
        dotenvy::dotenv().ok();
 | 
					        dotenvy::dotenv().ok();
 | 
				
			||||||
        let db_url = dotenvy::var("DATABASE_URL").unwrap_or(":memory:".to_string());
 | 
					        let db_url = dotenvy::var("DATABASE_URL").unwrap_or(":memory:".to_string());
 | 
				
			||||||
 | 
					        info!("Using db_url: {}", &db_url);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if !sqlx::Sqlite::database_exists(&db_url).await.unwrap() {
 | 
				
			||||||
 | 
					            sqlx::Sqlite::create_database(&db_url).await.unwrap();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let pool = sqlite::SqlitePoolOptions::new()
 | 
					        let pool = sqlite::SqlitePoolOptions::new()
 | 
				
			||||||
            .max_connections(5)
 | 
					            .max_connections(5)
 | 
				
			||||||
| 
						 | 
					@ -39,6 +46,12 @@ impl ServerState {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        sqlx::migrate!("./migrations").run(&pool).await.unwrap();
 | 
					        sqlx::migrate!("./migrations").run(&pool).await.unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        match crate::db::db_new_user("imbus".to_string(), "kartellen1234".to_string(), &pool).await
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Some(u) => info!("Created default user {}", u.username),
 | 
				
			||||||
 | 
					            None => error!("Failed to create default user..."),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #[cfg(debug_assertions)]
 | 
					        #[cfg(debug_assertions)]
 | 
				
			||||||
        debug_setup(&pool).await.unwrap();
 | 
					        debug_setup(&pool).await.unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,6 +59,9 @@ impl ServerState {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[cfg(debug_assertions)]
 | 
				
			||||||
 | 
					use sqlx::SqlitePool;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Inserts a bunch of dummy data into the database
 | 
					// Inserts a bunch of dummy data into the database
 | 
				
			||||||
// Mostly useful for debugging new posts, as we need to satisfy foreign key constraints.
 | 
					// Mostly useful for debugging new posts, as we need to satisfy foreign key constraints.
 | 
				
			||||||
#[cfg(debug_assertions)]
 | 
					#[cfg(debug_assertions)]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue