diff --git a/src/main.rs b/src/main.rs index ac4ba81e2..8a36c84d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -235,6 +235,7 @@ async fn main() -> std::io::Result<()> { // Init App HttpServer::new(move || { App::new() + .wrap(actix_web::middleware::Compress::default()) .wrap( Cors::default() .allow_any_origin() diff --git a/src/routes/v1/mod.rs b/src/routes/v1/mod.rs index 466e086eb..681a922c2 100644 --- a/src/routes/v1/mod.rs +++ b/src/routes/v1/mod.rs @@ -1,4 +1,6 @@ -use actix_web::web; +use actix_web::{dev::Service, web, HttpResponse}; +use chrono::{Timelike, Utc}; +use futures::FutureExt; mod mods; mod tags; @@ -9,6 +11,23 @@ mod versions; pub fn v1_config(cfg: &mut web::ServiceConfig) { cfg.service( web::scope("api/v1") + .wrap_fn(|req, srv| { + let current_minute = Utc::now().minute(); + + if current_minute % 10 > 5 { + srv.call(req).boxed_local() + } else { + async { + Ok( + req.into_response( + HttpResponse::Gone() + .content_type("application/json") + .body(r#"{"error":"api_deprecated","description":"You are using an application that uses an outdated version of Modrinth's API. Please either update it or switch to another application. For developers: https://docs.modrinth.com/docs/migrations/v1-to-v2/"}"#) + ) + ) + }.boxed_local() + } + }) .configure(tags_config) .configure(mods_config) .configure(versions_config)