use axum::{Router, http::header, response::IntoResponse, routing::get};
use crate::AppState;
const TABULATOR_JS: &str = include_str!("../assets/tabulator/tabulator.min.js");
const TABULATOR_CSS: &str = include_str!("../assets/tabulator/tabulator.min.css");
const APP_JS: &str = include_str!("../assets/app.js");
const APP_CSS: &str = include_str!("../assets/app.css");
const ICON_PNG: &[u8] = include_bytes!("../assets/kovra-icon.png");
const SORA_600: &[u8] = include_bytes!("../assets/fonts/sora-latin-600-normal.woff2");
const INTER_400: &[u8] = include_bytes!("../assets/fonts/inter-latin-400-normal.woff2");
const INTER_500: &[u8] = include_bytes!("../assets/fonts/inter-latin-500-normal.woff2");
const INTER_600: &[u8] = include_bytes!("../assets/fonts/inter-latin-600-normal.woff2");
const JS: &str = "text/javascript; charset=utf-8";
const CSS: &str = "text/css; charset=utf-8";
const PNG: &str = "image/png";
const WOFF2: &str = "font/woff2";
pub fn routes() -> Router<AppState> {
Router::new()
.route("/assets/tabulator/tabulator.min.js", get(tabulator_js))
.route("/assets/tabulator/tabulator.min.css", get(tabulator_css))
.route("/assets/app.js", get(app_js))
.route("/assets/app.css", get(app_css))
.route("/assets/kovra-icon.png", get(icon_png))
.route("/assets/fonts/sora-latin-600-normal.woff2", get(sora_600))
.route("/assets/fonts/inter-latin-400-normal.woff2", get(inter_400))
.route("/assets/fonts/inter-latin-500-normal.woff2", get(inter_500))
.route("/assets/fonts/inter-latin-600-normal.woff2", get(inter_600))
}
fn asset(content_type: &'static str, body: &'static str) -> impl IntoResponse {
(
[
(header::CONTENT_TYPE, content_type),
(header::CACHE_CONTROL, "no-store"),
],
body,
)
}
fn binary(content_type: &'static str, body: &'static [u8]) -> impl IntoResponse {
(
[
(header::CONTENT_TYPE, content_type),
(header::CACHE_CONTROL, "no-store"),
],
body,
)
}
async fn tabulator_js() -> impl IntoResponse {
asset(JS, TABULATOR_JS)
}
async fn tabulator_css() -> impl IntoResponse {
asset(CSS, TABULATOR_CSS)
}
async fn app_js() -> impl IntoResponse {
asset(JS, APP_JS)
}
async fn app_css() -> impl IntoResponse {
asset(CSS, APP_CSS)
}
async fn icon_png() -> impl IntoResponse {
binary(PNG, ICON_PNG)
}
async fn sora_600() -> impl IntoResponse {
binary(WOFF2, SORA_600)
}
async fn inter_400() -> impl IntoResponse {
binary(WOFF2, INTER_400)
}
async fn inter_500() -> impl IntoResponse {
binary(WOFF2, INTER_500)
}
async fn inter_600() -> impl IntoResponse {
binary(WOFF2, INTER_600)
}