add countdown

This commit is contained in:
Mylloon 2024-08-29 23:31:35 +02:00
parent 8cedeb531d
commit a7aec1b94e
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 45 additions and 4 deletions

7
Cargo.lock generated
View file

@ -865,6 +865,12 @@ dependencies = [
"syn 2.0.72", "syn 2.0.72",
] ]
[[package]]
name = "cyborgtime"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "817fa642fb0ee7fe42e95783e00e0969927b96091bdd4b9b1af082acd943913b"
[[package]] [[package]]
name = "darling" name = "darling"
version = "0.20.10" version = "0.20.10"
@ -1069,6 +1075,7 @@ dependencies = [
"chrono", "chrono",
"chrono-tz", "chrono-tz",
"comrak", "comrak",
"cyborgtime",
"glob", "glob",
"lol_html", "lol_html",
"mime_guess", "mime_guess",

View file

@ -31,6 +31,7 @@ base64 = "0.22"
mime_guess = "2.0" mime_guess = "2.0"
urlencoding = "2.1" urlencoding = "2.1"
regex = "1.10" regex = "1.10"
cyborgtime = "2.1.1"
[lints.clippy] [lints.clippy]
pedantic = "warn" pedantic = "warn"

View file

@ -42,7 +42,10 @@ async fn main() -> Result<()> {
.add(("Server", format!("ewp/{}", env!("CARGO_PKG_VERSION")))) .add(("Server", format!("ewp/{}", env!("CARGO_PKG_VERSION"))))
.add(("Permissions-Policy", "interest-cohort=()")), .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(index::page)
.service(agreements::security) .service(agreements::security)
.service(agreements::humans) .service(agreements::humans)

View file

@ -1,15 +1,45 @@
use std::time::Duration;
use actix_web::{get, HttpResponse, Responder}; use actix_web::{get, HttpResponse, Responder};
use chrono::Utc;
use cyborgtime::format_duration;
use serde::Serialize; use serde::Serialize;
/// Response /// Response for /love
#[derive(Serialize)] #[derive(Serialize)]
struct Info { struct InfoLove {
unix_epoch: u32, unix_epoch: u32,
} }
#[get("/love")] #[get("/love")]
pub async fn love() -> impl Responder { pub async fn love() -> impl Responder {
HttpResponse::Ok().json(Info { HttpResponse::Ok().json(InfoLove {
unix_epoch: 1_605_576_600, 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)
}