Track and sort by release date of game_versions tags (#95)

This commit is contained in:
Aeledfyr
2020-10-31 23:06:47 -05:00
committed by GitHub
parent a4ba6d1444
commit da79386cc3
5 changed files with 108 additions and 55 deletions

View File

@@ -82,6 +82,8 @@ struct VersionFormat<'a> {
id: String,
#[serde(rename = "type")]
type_: std::borrow::Cow<'a, str>,
#[serde(rename = "releaseTime")]
release_time: chrono::DateTime<chrono::Utc>,
}
async fn update_versions(pool: &sqlx::Pool<sqlx::Postgres>) -> Result<(), VersionIndexingError> {
@@ -92,15 +94,41 @@ async fn update_versions(pool: &sqlx::Pool<sqlx::Postgres>) -> Result<(), Versio
let mut skipped_versions_count = 0u32;
// A list of version names that contains spaces.
// Generated using the command
// ```sh
// curl https://launchermeta.mojang.com/mc/game/version_manifest.json \
// | jq '[.versions[].id | select(contains(" "))]'
// ```
const HALL_OF_SHAME: [(&str, &str); 12] = [
("1.14.2 Pre-Release 4", "1.14.2-pre4"),
("1.14.2 Pre-Release 3", "1.14.2-pre3"),
("1.14.2 Pre-Release 2", "1.14.2-pre2"),
("1.14.2 Pre-Release 1", "1.14.2-pre1"),
("1.14.1 Pre-Release 2", "1.14.1-pre2"),
("1.14.1 Pre-Release 1", "1.14.1-pre1"),
("1.14 Pre-Release 5", "1.14-pre5"),
("1.14 Pre-Release 4", "1.14-pre4"),
("1.14 Pre-Release 3", "1.14-pre3"),
("1.14 Pre-Release 2", "1.14-pre2"),
("1.14 Pre-Release 1", "1.14-pre1"),
("3D Shareware v1.34", "3D-Shareware-v1.34"),
];
for version in input.versions.into_iter() {
let name = version.id;
let mut name = version.id;
if !name
.chars()
.all(|c| c.is_ascii_alphanumeric() || "-_.".contains(c))
{
// We'll deal with these manually
skipped_versions_count += 1;
continue;
if let Some((_, alternate)) = HALL_OF_SHAME.iter().find(|(version, _)| name == *version)
{
name = String::from(*alternate);
} else {
// We'll deal with these manually
skipped_versions_count += 1;
continue;
}
}
let type_ = match &*version.type_ {
@@ -114,6 +142,7 @@ async fn update_versions(pool: &sqlx::Pool<sqlx::Postgres>) -> Result<(), Versio
crate::database::models::categories::GameVersion::builder()
.version(&name)?
.version_type(type_)?
.created(&version.release_time)
.insert(pool)
.await?;
}