You've already forked AstralRinth
forked from didirus/AstralRinth
Add API V1 flickers (#541)
Co-authored-by: triphora <emmaffle@modrinth.com>
This commit is contained in:
@@ -235,6 +235,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
// Init App
|
// Init App
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
|
.wrap(actix_web::middleware::Compress::default())
|
||||||
.wrap(
|
.wrap(
|
||||||
Cors::default()
|
Cors::default()
|
||||||
.allow_any_origin()
|
.allow_any_origin()
|
||||||
|
|||||||
@@ -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 mods;
|
||||||
mod tags;
|
mod tags;
|
||||||
@@ -9,6 +11,23 @@ mod versions;
|
|||||||
pub fn v1_config(cfg: &mut web::ServiceConfig) {
|
pub fn v1_config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(
|
cfg.service(
|
||||||
web::scope("api/v1")
|
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(tags_config)
|
||||||
.configure(mods_config)
|
.configure(mods_config)
|
||||||
.configure(versions_config)
|
.configure(versions_config)
|
||||||
|
|||||||
Reference in New Issue
Block a user