mylloon.fr/src/routes/api_v1.rs

54 lines
1.2 KiB
Rust
Raw Normal View History

2024-08-29 23:31:35 +02:00
use std::time::Duration;
2023-05-23 10:04:02 +02:00
use actix_web::{get, HttpResponse, Responder};
2024-08-29 23:31:35 +02:00
use chrono::Utc;
use cyborgtime::format_duration;
2023-05-23 10:04:02 +02:00
use serde::Serialize;
2024-08-29 23:31:35 +02:00
/// Response for /love
2023-05-23 10:04:02 +02:00
#[derive(Serialize)]
2024-08-29 23:31:35 +02:00
struct InfoLove {
2023-05-23 10:04:02 +02:00
unix_epoch: u32,
}
#[get("/love")]
2024-06-17 15:56:57 +02:00
pub async fn love() -> impl Responder {
2024-08-29 23:31:35 +02:00
HttpResponse::Ok().json(InfoLove {
2024-05-28 20:26:58 +02:00
unix_epoch: 1_605_576_600,
2023-05-23 10:04:02 +02:00
})
}
2024-08-29 23:31:35 +02:00
/// 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)
}
2024-09-19 15:50:37 +02:00
#[get("/websites")]
pub async fn websites() -> impl Responder {
HttpResponse::Ok().json((
"http://www.bocal.cs.univ-paris8.fr/~akennel/",
"https://anri.up8.site/",
))
}