From df3aeed2910cf11d39fe0dbe1a05f411e0541397 Mon Sep 17 00:00:00 2001 From: triphora Date: Tue, 17 Jan 2023 17:01:26 -0500 Subject: [PATCH] Add scary warning for people still using API v1 (#525) * Add scary warning for people still using API v1 * change [] brackets to headers --- src/routes/v1/mod.rs | 2 +- src/routes/v1/mods.rs | 42 ++++++++++++++++++++++++++++++++++++--- src/routes/v1/versions.rs | 4 ++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/routes/v1/mod.rs b/src/routes/v1/mod.rs index 4e54b2ce9..466e086eb 100644 --- a/src/routes/v1/mod.rs +++ b/src/routes/v1/mod.rs @@ -37,7 +37,7 @@ pub fn mods_config(cfg: &mut web::ServiceConfig) { cfg.service( web::scope("mod") - .service(super::projects::project_get) + .service(mods::mod_get) .service(super::projects::project_delete) .service(super::projects::project_edit) .service(super::projects::project_icon_edit) diff --git a/src/routes/v1/mods.rs b/src/routes/v1/mods.rs index c933870a0..96a76448c 100644 --- a/src/routes/v1/mods.rs +++ b/src/routes/v1/mods.rs @@ -61,8 +61,8 @@ pub async fn mod_search( mod_id: format!("local-{}", x.project_id), slug: x.slug, author: x.author.clone(), - title: x.title, - description: x.description, + title: format!("[STOP USING API v1] {}", x.title), + description: format!("[STOP USING API v1] {}", x.description), categories: x.categories, versions: x.versions, downloads: x.downloads, @@ -85,6 +85,36 @@ pub async fn mod_search( })) } +#[get("{id}")] +pub async fn mod_get( + req: HttpRequest, + info: web::Path<(String,)>, + pool: web::Data, +) -> Result { + let string = info.into_inner().0; + + let project_data = + database::models::Project::get_full_from_slug_or_project_id( + &string, &**pool, + ) + .await?; + + let user_option = get_user_from_headers(req.headers(), &**pool).await.ok(); + + if let Some(mut data) = project_data { + if is_authorized(&data.inner, &user_option, &pool).await? { + data.inner.title = + format!("[STOP USING API v1] {}", data.inner.title); + data.inner.description = + format!("[STOP USING API v1] {}", data.inner.description); + data.inner.body = + format!("# STOP USING API v1 - whatever application you're using right now is likely deprecated or abandoned\n{}", data.inner.body); + return Ok(HttpResponse::Ok().json(models::projects::Project::from(data))); + } + } + Ok(HttpResponse::NotFound().body("")) +} + #[get("mods")] pub async fn mods_get( req: HttpRequest, @@ -105,8 +135,14 @@ pub async fn mods_get( let mut projects = Vec::with_capacity(projects_data.len()); // can't use `map` and `collect` here since `is_authorized` must be async - for proj in projects_data { + for mut proj in projects_data { if is_authorized(&proj.inner, &user_option, &pool).await? { + proj.inner.title = + format!("[STOP USING API v1] {}", proj.inner.title); + proj.inner.description = + format!("[STOP USING API v1] {}", proj.inner.description); + proj.inner.body = + format!("# STOP USING API v1 - whatever application you're using right now is likely deprecated or abandoned\n{}", proj.inner.body); projects.push(crate::models::projects::Project::from(proj)) } } diff --git a/src/routes/v1/versions.rs b/src/routes/v1/versions.rs index 2c1c0aa0a..156ce782a 100644 --- a/src/routes/v1/versions.rs +++ b/src/routes/v1/versions.rs @@ -36,9 +36,9 @@ fn convert_to_legacy(version: Version) -> LegacyVersion { mod_id: version.project_id, author_id: version.author_id, featured: version.featured, - name: version.name, + name: format!("[STOP USING API v1] {}", version.name), version_number: version.version_number, - changelog: version.changelog, + changelog: format!("# STOP USING API v1 - whatever application you're using right now is likely deprecated or abandoned\n{}", version.changelog), changelog_url: None, date_published: version.date_published, downloads: version.downloads,