Game Version types, indexing, and bugfixes (#91)

* Add types to game_versions, allow filtering by version type

- Fixes an issue with version numbers in the initial mod indexing
  queue
- Modifies the /api/v1/categories/game_versions route to take an
  optional query parameter `type` to filter the listed game versions
- Creating tags is now idempotent
- Creating game_versions now requires a JSON body that specifies
  the version type

* Implement automatic indexing of new Minecraft versions

It's currently set to run every 6 hours and isn't configurable; we
could add config for it, but it doesn't seem likely to be rate
limited or have issues with frequency.
This commit is contained in:
Aeledfyr
2020-10-28 11:11:49 -05:00
committed by GitHub
parent ef28459b61
commit a4ba6d1444
7 changed files with 270 additions and 80 deletions

View File

@@ -460,10 +460,10 @@ async fn mod_create_inner(
status: status_id,
};
let versions_list = mod_builder
let versions_list = mod_create_data
.initial_versions
.iter()
.flat_map(|v| v.game_versions.iter().map(|id| id.0.to_string()))
.flat_map(|v| v.game_versions.iter().map(|name| name.0.clone()))
.collect::<std::collections::HashSet<String>>()
.into_iter()
.collect::<Vec<_>>();

View File

@@ -28,9 +28,6 @@ pub async fn category_list(pool: web::Data<PgPool>) -> Result<HttpResponse, ApiE
Ok(HttpResponse::Ok().json(results))
}
// At some point this may take more info, but it should be able to
// remain idempotent
// TODO: don't fail if category already exists
#[put("category/{name}")]
pub async fn category_create(
req: HttpRequest,
@@ -93,9 +90,6 @@ pub async fn loader_list(pool: web::Data<PgPool>) -> Result<HttpResponse, ApiErr
Ok(HttpResponse::Ok().json(results))
}
// At some point this may take more info, but it should be able to
// remain idempotent
// TODO: don't fail if loader already exists
#[put("loader/{name}")]
pub async fn loader_create(
req: HttpRequest,
@@ -152,19 +146,38 @@ pub async fn loader_delete(
}
}
#[get("game_version")]
pub async fn game_version_list(pool: web::Data<PgPool>) -> Result<HttpResponse, ApiError> {
let results = GameVersion::list(&**pool).await?;
Ok(HttpResponse::Ok().json(results))
#[derive(serde::Deserialize)]
pub struct GameVersionQueryData {
#[serde(rename = "type")]
type_: Option<String>,
}
#[get("game_version")]
pub async fn game_version_list(
pool: web::Data<PgPool>,
query: web::Query<GameVersionQueryData>,
) -> Result<HttpResponse, ApiError> {
if let Some(type_) = &query.type_ {
let results = GameVersion::list_type(type_, &**pool).await?;
Ok(HttpResponse::Ok().json(results))
} else {
let results = GameVersion::list(&**pool).await?;
Ok(HttpResponse::Ok().json(results))
}
}
#[derive(serde::Deserialize)]
pub struct GameVersionData {
#[serde(rename = "type")]
type_: String,
}
// At some point this may take more info, but it should be able to
// remain idempotent
#[put("game_version/{name}")]
pub async fn game_version_create(
req: HttpRequest,
pool: web::Data<PgPool>,
game_version: web::Path<(String,)>,
version_data: web::Json<GameVersionData>,
) -> Result<HttpResponse, ApiError> {
check_is_admin_from_headers(
req.headers(),
@@ -178,8 +191,12 @@ pub async fn game_version_create(
let name = game_version.into_inner().0;
// The version type currently isn't limited, but it should be one of:
// "release", "snapshot", "alpha", "beta", "other"
let _id = GameVersion::builder()
.version(&name)?
.version_type(&version_data.type_)?
.insert(&**pool)
.await?;