add countdown
This commit is contained in:
parent
8cedeb531d
commit
a7aec1b94e
4 changed files with 45 additions and 4 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -865,6 +865,12 @@ dependencies = [
|
|||
"syn 2.0.72",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cyborgtime"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "817fa642fb0ee7fe42e95783e00e0969927b96091bdd4b9b1af082acd943913b"
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.10"
|
||||
|
@ -1069,6 +1075,7 @@ dependencies = [
|
|||
"chrono",
|
||||
"chrono-tz",
|
||||
"comrak",
|
||||
"cyborgtime",
|
||||
"glob",
|
||||
"lol_html",
|
||||
"mime_guess",
|
||||
|
|
|
@ -31,6 +31,7 @@ base64 = "0.22"
|
|||
mime_guess = "2.0"
|
||||
urlencoding = "2.1"
|
||||
regex = "1.10"
|
||||
cyborgtime = "2.1.1"
|
||||
|
||||
[lints.clippy]
|
||||
pedantic = "warn"
|
||||
|
|
|
@ -42,7 +42,10 @@ async fn main() -> Result<()> {
|
|||
.add(("Server", format!("ewp/{}", env!("CARGO_PKG_VERSION"))))
|
||||
.add(("Permissions-Policy", "interest-cohort=()")),
|
||||
)
|
||||
.service(web::scope("/api").service(web::scope("v1").service(api_v1::love)))
|
||||
.service(
|
||||
web::scope("/api")
|
||||
.service(web::scope("v1").service(api_v1::love).service(api_v1::btf)),
|
||||
)
|
||||
.service(index::page)
|
||||
.service(agreements::security)
|
||||
.service(agreements::humans)
|
||||
|
|
|
@ -1,15 +1,45 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use actix_web::{get, HttpResponse, Responder};
|
||||
use chrono::Utc;
|
||||
use cyborgtime::format_duration;
|
||||
use serde::Serialize;
|
||||
|
||||
/// Response
|
||||
/// Response for /love
|
||||
#[derive(Serialize)]
|
||||
struct Info {
|
||||
struct InfoLove {
|
||||
unix_epoch: u32,
|
||||
}
|
||||
|
||||
#[get("/love")]
|
||||
pub async fn love() -> impl Responder {
|
||||
HttpResponse::Ok().json(Info {
|
||||
HttpResponse::Ok().json(InfoLove {
|
||||
unix_epoch: 1_605_576_600,
|
||||
})
|
||||
}
|
||||
|
||||
/// Response for /backtofrance
|
||||
#[derive(Serialize)]
|
||||
struct InfoBTF {
|
||||
unix_epoch: u64,
|
||||
countdown: String,
|
||||
}
|
||||
|
||||
#[get("/backtofrance")]
|
||||
pub async fn btf() -> impl Responder {
|
||||
let target = 1_736_618_100;
|
||||
let current_time: u64 = Utc::now().timestamp().try_into().unwrap();
|
||||
|
||||
let info = InfoBTF {
|
||||
unix_epoch: target,
|
||||
countdown: if current_time > target {
|
||||
"Already happened".to_owned()
|
||||
} else {
|
||||
let duration_epoch = target - current_time;
|
||||
let duration = Duration::from_secs(duration_epoch);
|
||||
format_duration(duration).to_string()
|
||||
},
|
||||
};
|
||||
|
||||
HttpResponse::Ok().json(info)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue