Add API V1 flickers (#541)

Co-authored-by: triphora <emmaffle@modrinth.com>
This commit is contained in:
Geometrically 2023-02-15 15:05:28 -07:00 committed by GitHub
parent b056610eaa
commit c15acc4ce3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -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()

View File

@ -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)