2024-12-31 02:05:31 +00:00
|
|
|
use core::Core;
|
|
|
|
use std::path::PathBuf;
|
2024-11-30 04:14:52 +00:00
|
|
|
|
2024-12-27 19:29:07 +00:00
|
|
|
use asset_db::FsAssets;
|
2024-12-31 02:05:31 +00:00
|
|
|
use axum::{routing::{get, post}, Router, Json};
|
2024-11-30 16:48:35 +00:00
|
|
|
use database::DbConn;
|
2023-11-21 14:57:35 +00:00
|
|
|
|
2024-11-20 14:52:26 +00:00
|
|
|
mod asset_db;
|
2024-11-12 00:58:50 +00:00
|
|
|
mod core;
|
2024-11-30 04:14:52 +00:00
|
|
|
mod database;
|
2024-12-27 19:29:07 +00:00
|
|
|
mod filters;
|
2023-11-21 14:57:35 +00:00
|
|
|
mod handlers;
|
2024-12-31 02:05:31 +00:00
|
|
|
use handlers::{ healthcheck, check_password, AuthRequest};
|
2024-11-19 00:08:49 +00:00
|
|
|
mod types;
|
|
|
|
|
2023-11-21 14:57:35 +00:00
|
|
|
#[tokio::main]
|
|
|
|
pub async fn main() {
|
2024-12-31 02:05:31 +00:00
|
|
|
/*
|
2024-12-22 14:17:00 +00:00
|
|
|
pretty_env_logger::init();
|
|
|
|
|
2024-12-27 19:02:43 +00:00
|
|
|
let unauthenticated_endpoints = route_healthcheck().or(route_authenticate(core.clone()));
|
|
|
|
let authenticated_endpoints = route_image(core.clone());
|
2024-12-31 02:05:31 +00:00
|
|
|
*/
|
2024-12-16 05:27:55 +00:00
|
|
|
|
2024-12-31 02:05:31 +00:00
|
|
|
let conn = DbConn::new(Some("/home/savanni/game.db"));
|
|
|
|
let core = Core::new(FsAssets::new(PathBuf::from("/home/savanni/Pictures")), conn);
|
|
|
|
|
|
|
|
let app = Router::new().route(
|
|
|
|
"/api/v1/health",
|
|
|
|
get({
|
|
|
|
let core = core.clone();
|
|
|
|
move || healthcheck(core)
|
|
|
|
}),
|
|
|
|
).route(
|
|
|
|
"/api/v1/auth",
|
|
|
|
post({
|
|
|
|
let core = core.clone();
|
|
|
|
move |req: Json<AuthRequest>| handlers::check_password(core, req)
|
|
|
|
}),
|
2024-12-27 19:29:07 +00:00
|
|
|
);
|
2024-12-31 02:05:31 +00:00
|
|
|
|
|
|
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:8001")
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
axum::serve(listener, app).await.unwrap();
|
2023-11-20 04:23:26 +00:00
|
|
|
}
|