Add scary warning for people still using API v1 (#525)

* Add scary warning for people still using API v1

* change [] brackets to headers
This commit is contained in:
triphora 2023-01-17 17:01:26 -05:00 committed by GitHub
parent 867ba7b68f
commit df3aeed291
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 6 deletions

View File

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

View File

@ -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<PgPool>,
) -> Result<HttpResponse, ApiError> {
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))
}
}

View File

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