2023-10-04 19:06:59 -04:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
|
|
|
use axum::{
|
|
|
|
Json,
|
|
|
|
Router, routing::get,
|
|
|
|
};
|
|
|
|
use serde::{Deserialize, Serialize};
|
2024-06-29 14:07:44 -04:00
|
|
|
use kawari::config::{Config, get_config};
|
2023-10-04 19:06:59 -04:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
struct GateStatus {
|
|
|
|
status: i32,
|
|
|
|
}
|
|
|
|
|
2024-06-29 14:06:44 -04:00
|
|
|
async fn get_login_status() -> Json<GateStatus> {
|
2024-06-29 14:07:44 -04:00
|
|
|
tracing::info!("Requesting login status...");
|
2024-06-29 14:06:44 -04:00
|
|
|
|
2024-06-29 14:07:44 -04:00
|
|
|
let config = get_config();
|
2024-06-29 14:06:44 -04:00
|
|
|
Json(GateStatus {
|
2024-06-29 14:07:44 -04:00
|
|
|
status: config.login_open.into()
|
2024-06-29 14:06:44 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_world_status() -> Json<GateStatus> {
|
2024-06-29 14:07:44 -04:00
|
|
|
tracing::info!("Requesting world status...");
|
2023-10-05 12:09:05 -04:00
|
|
|
|
2024-06-29 14:07:44 -04:00
|
|
|
let config = get_config();
|
2023-10-04 19:06:59 -04:00
|
|
|
Json(GateStatus {
|
2024-06-29 14:07:44 -04:00
|
|
|
status: config.login_open.into()
|
2023-10-04 19:06:59 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-11 13:07:00 -04:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
struct Banner {
|
|
|
|
link: String,
|
|
|
|
lsb_banner: String
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
struct NewsItem {
|
|
|
|
date: String,
|
|
|
|
id: String,
|
|
|
|
tag: String,
|
|
|
|
title: String,
|
|
|
|
url: String
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
struct Headline {
|
|
|
|
banner: Vec<Banner>,
|
|
|
|
news: Vec<NewsItem>,
|
|
|
|
pinned: Vec<NewsItem>,
|
|
|
|
topics: Vec<NewsItem>,
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_headline() -> Json<Headline> {
|
|
|
|
tracing::info!("Requesting headline...");
|
|
|
|
|
|
|
|
Json(Headline {
|
|
|
|
banner: vec![],
|
|
|
|
news: vec![NewsItem {
|
|
|
|
date: "".to_string(),
|
|
|
|
id: "".to_string(),
|
|
|
|
tag: "".to_string(),
|
|
|
|
title: "Test News Item".to_string(),
|
|
|
|
url: "".to_string(),
|
|
|
|
}],
|
|
|
|
pinned: vec![],
|
|
|
|
topics: vec![],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-04 19:06:59 -04:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
|
|
let app = Router::new()
|
2024-06-29 14:06:44 -04:00
|
|
|
.route("/worldStatus/gate_status.json", get(get_world_status))
|
|
|
|
.route("/worldStatus/login_status.json", get(get_login_status))
|
2024-05-11 13:07:00 -04:00
|
|
|
.route("/news/headline.json", get(get_headline));
|
2023-10-04 19:06:59 -04:00
|
|
|
|
2023-10-04 19:24:18 -04:00
|
|
|
let addr = SocketAddr::from(([127, 0, 0, 1], 5857));
|
2023-10-04 19:06:59 -04:00
|
|
|
tracing::info!("Frontier server started on {}", addr);
|
|
|
|
axum::Server::bind(&addr)
|
|
|
|
.serve(app.into_make_service())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|