Skip to content

Commit

Permalink
refactor: check_steam param for updating maps
Browse files Browse the repository at this point in the history
Instead of `name` and `checksum`, we now have a single parameter that
will download the latest workshop version of the map, and then updates
both values.
  • Loading branch information
AlphaKeks committed Jan 14, 2024
1 parent 66a97e9 commit d283643
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 53 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

8 changes: 2 additions & 6 deletions api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2352,13 +2352,9 @@
"nullable": true,
"minimum": 0
},
"name": {
"type": "boolean",
"description": "Fetch the latest version of the map from Steam and update the name."
},
"checksum": {
"check_steam": {
"type": "boolean",
"description": "Fetch the latest version of the map from Steam and update the checksum."
"description": "Fetch the latest version of the map from Steam and update its name and checksum."
},
"added_mappers": {
"type": "array",
Expand Down
8 changes: 2 additions & 6 deletions src/maps/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,9 @@ pub struct MapUpdate {
/// A new workshop ID.
pub workshop_id: Option<u32>,

/// Fetch the latest version of the map from Steam and update the name.
/// Fetch the latest version of the map from Steam and update its name and checksum.
#[serde(default)]
pub name: bool,

/// Fetch the latest version of the map from Steam and update the checksum.
#[serde(default)]
pub checksum: bool,
pub check_steam: bool,

/// List of mappers to add.
pub added_mappers: Option<Vec<SteamID>>,
Expand Down
36 changes: 7 additions & 29 deletions src/maps/routes/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,8 @@ pub async fn update(
.workshop_id
};

if map_update.name || map_update.checksum {
update_name_and_checksum(
map_id,
workshop_id,
map_update.name,
map_update.checksum,
state.http(),
transaction.as_mut(),
)
.await?;
if map_update.check_steam {
update_name_and_checksum(map_id, workshop_id, state.http(), transaction.as_mut()).await?;
}

if let Some(mappers) = &map_update.added_mappers {
Expand Down Expand Up @@ -201,39 +193,25 @@ async fn update_workshop_id(
async fn update_name_and_checksum(
map_id: u16,
workshop_id: u32,
name: bool,
checksum: bool,
http_client: Arc<reqwest::Client>,
executor: impl MySqlExecutor<'_>,
) -> Result<()> {
let (workshop_map, checksum) = tokio::try_join! {
async {
Result::Ok(if name {
Some(workshop::Map::get(workshop_id, http_client).await?)
} else {
None
})
},
async {
Result::Ok(if checksum {
Some(workshop::MapFile::download(workshop_id).await?.checksum().await?)
} else {
None
})
},
workshop::Map::get(workshop_id, http_client),
async { workshop::MapFile::download(workshop_id).await?.checksum().await },
}?;

sqlx::query! {
r#"
UPDATE
Maps
SET
name = IFNULL(?, name),
checksum = IFNULL(?, checksum)
name = ?,
checksum = ?
WHERE
id = ?
"#,
workshop_map.map(|map| map.name),
workshop_map.name,
checksum,
map_id,
}
Expand Down

0 comments on commit d283643

Please sign in to comment.