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:
parent
867ba7b68f
commit
df3aeed291
@ -37,7 +37,7 @@ pub fn mods_config(cfg: &mut web::ServiceConfig) {
|
|||||||
|
|
||||||
cfg.service(
|
cfg.service(
|
||||||
web::scope("mod")
|
web::scope("mod")
|
||||||
.service(super::projects::project_get)
|
.service(mods::mod_get)
|
||||||
.service(super::projects::project_delete)
|
.service(super::projects::project_delete)
|
||||||
.service(super::projects::project_edit)
|
.service(super::projects::project_edit)
|
||||||
.service(super::projects::project_icon_edit)
|
.service(super::projects::project_icon_edit)
|
||||||
|
|||||||
@ -61,8 +61,8 @@ pub async fn mod_search(
|
|||||||
mod_id: format!("local-{}", x.project_id),
|
mod_id: format!("local-{}", x.project_id),
|
||||||
slug: x.slug,
|
slug: x.slug,
|
||||||
author: x.author.clone(),
|
author: x.author.clone(),
|
||||||
title: x.title,
|
title: format!("[STOP USING API v1] {}", x.title),
|
||||||
description: x.description,
|
description: format!("[STOP USING API v1] {}", x.description),
|
||||||
categories: x.categories,
|
categories: x.categories,
|
||||||
versions: x.versions,
|
versions: x.versions,
|
||||||
downloads: x.downloads,
|
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")]
|
#[get("mods")]
|
||||||
pub async fn mods_get(
|
pub async fn mods_get(
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
@ -105,8 +135,14 @@ pub async fn mods_get(
|
|||||||
let mut projects = Vec::with_capacity(projects_data.len());
|
let mut projects = Vec::with_capacity(projects_data.len());
|
||||||
|
|
||||||
// can't use `map` and `collect` here since `is_authorized` must be async
|
// 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? {
|
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))
|
projects.push(crate::models::projects::Project::from(proj))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,9 +36,9 @@ fn convert_to_legacy(version: Version) -> LegacyVersion {
|
|||||||
mod_id: version.project_id,
|
mod_id: version.project_id,
|
||||||
author_id: version.author_id,
|
author_id: version.author_id,
|
||||||
featured: version.featured,
|
featured: version.featured,
|
||||||
name: version.name,
|
name: format!("[STOP USING API v1] {}", version.name),
|
||||||
version_number: version.version_number,
|
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,
|
changelog_url: None,
|
||||||
date_published: version.date_published,
|
date_published: version.date_published,
|
||||||
downloads: version.downloads,
|
downloads: version.downloads,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user