mirror of
https://github.com/Xevion/time-banner.git
synced 2025-12-05 23:16:35 -06:00
Add route for index, redirect to relative of current epoch time
This commit is contained in:
@@ -3,7 +3,7 @@ use std::net::SocketAddr;
|
||||
use axum::{Router, routing::get};
|
||||
use dotenvy::dotenv;
|
||||
use config::Configuration;
|
||||
use crate::routes::{relative_handler, implicit_handler, absolute_handler};
|
||||
use crate::routes::{relative_handler, implicit_handler, absolute_handler, index_handler};
|
||||
|
||||
mod config;
|
||||
mod raster;
|
||||
@@ -29,6 +29,7 @@ async fn main() {
|
||||
.init();
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(index_handler))
|
||||
.route("/:path", get(implicit_handler))
|
||||
.route("/rel/:path", get(relative_handler))
|
||||
.route("/relative/:path", get(relative_handler))
|
||||
|
||||
@@ -2,7 +2,7 @@ use axum::{http::StatusCode, response::IntoResponse};
|
||||
use axum::body::{Bytes, Full};
|
||||
use axum::extract::{Path};
|
||||
use axum::http::{header};
|
||||
use axum::response::Response;
|
||||
use axum::response::{Redirect, Response};
|
||||
use chrono::{DateTime, NaiveDateTime, Offset, Utc};
|
||||
use crate::error::{get_error_response, TimeBannerError};
|
||||
|
||||
@@ -34,6 +34,11 @@ fn handle_rasterize(data: String, extension: &str) -> Result<(&str, Bytes), Time
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn index_handler() -> impl IntoResponse {
|
||||
let epoch_now = Utc::now().timestamp();
|
||||
return Redirect::temporary(&*format!("/relative/{epoch_now}")).into_response();
|
||||
}
|
||||
|
||||
pub async fn relative_handler(Path(path): Path<String>) -> impl IntoResponse {
|
||||
let (raw_time, extension) = parse_path(path.as_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user