From 4a5d46915d74d63a68e132906ed2a6e0232464ae Mon Sep 17 00:00:00 2001 From: Geometrically Date: Wed, 27 Jan 2021 08:46:38 -0700 Subject: [PATCH] Fix version get --- sqlx-data.json | 208 ++++++++++++++-------------- src/database/models/mod_item.rs | 46 +++--- src/database/models/version_item.rs | 18 +-- src/routes/mod_creation.rs | 8 +- 4 files changed, 139 insertions(+), 141 deletions(-) diff --git a/sqlx-data.json b/sqlx-data.json index a6f73cec..cc612b57 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -491,110 +491,6 @@ ] } }, - "1e932b3ed3a406e860817241dec7616f712c1af59ce041a622a978b3be20ad5b": { - "query": "\n SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,\n v.changelog changelog, v.changelog_url changelog_url, v.date_published date_published, v.downloads downloads,\n rc.channel release_channel, v.featured featured,\n ARRAY_AGG(gv.version ORDER BY gv.created) game_versions, ARRAY_AGG(DISTINCT l.loader) loaders,\n ARRAY_AGG(DISTINCT f.id || ', ' || f.filename || ', ' || f.is_primary || ', ' || f.url) files,\n ARRAY_AGG(DISTINCT h.hash || ', ' || h.algorithm || ', ' || h.file_id) hashes\n FROM versions v\n INNER JOIN release_channels rc on v.release_channel = rc.id\n INNER JOIN game_versions_versions gvv on v.id = gvv.joining_version_id\n INNER JOIN game_versions gv on gvv.game_version_id = gv.id\n INNER JOIN loaders_versions lv on v.id = lv.version_id\n INNER JOIN loaders l on lv.loader_id = l.id\n INNER JOIN files f on v.id = f.version_id\n INNER JOIN hashes h on f.id = h.file_id\n WHERE v.id = $1\n GROUP BY v.id, rc.id;\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Int8" - }, - { - "ordinal": 1, - "name": "mod_id", - "type_info": "Int8" - }, - { - "ordinal": 2, - "name": "author_id", - "type_info": "Int8" - }, - { - "ordinal": 3, - "name": "version_name", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "version_number", - "type_info": "Varchar" - }, - { - "ordinal": 5, - "name": "changelog", - "type_info": "Varchar" - }, - { - "ordinal": 6, - "name": "changelog_url", - "type_info": "Varchar" - }, - { - "ordinal": 7, - "name": "date_published", - "type_info": "Timestamptz" - }, - { - "ordinal": 8, - "name": "downloads", - "type_info": "Int4" - }, - { - "ordinal": 9, - "name": "release_channel", - "type_info": "Varchar" - }, - { - "ordinal": 10, - "name": "featured", - "type_info": "Bool" - }, - { - "ordinal": 11, - "name": "game_versions", - "type_info": "VarcharArray" - }, - { - "ordinal": 12, - "name": "loaders", - "type_info": "VarcharArray" - }, - { - "ordinal": 13, - "name": "files", - "type_info": "TextArray" - }, - { - "ordinal": 14, - "name": "hashes", - "type_info": "TextArray" - } - ], - "parameters": { - "Left": [ - "Int8" - ] - }, - "nullable": [ - false, - false, - false, - false, - false, - false, - true, - false, - false, - false, - false, - null, - null, - null, - null - ] - } - }, "1ffce9b2d5c9fa6c8b9abce4bad9f9419c44ad6367b7463b979c91b9b5b4fea1": { "query": "SELECT EXISTS(SELECT 1 FROM versions WHERE id=$1)", "describe": { @@ -2217,6 +2113,110 @@ ] } }, + "94ee8161c16e89692c912c7416d67263896912f7ad86edee567b1a244758a649": { + "query": "\n SELECT v.id id, v.mod_id mod_id, v.author_id author_id, v.name version_name, v.version_number version_number,\n v.changelog changelog, v.changelog_url changelog_url, v.date_published date_published, v.downloads downloads,\n rc.channel release_channel, v.featured featured,\n ARRAY_AGG(gv.version ORDER BY gv.created) game_versions, ARRAY_AGG(DISTINCT l.loader) loaders,\n ARRAY_AGG(DISTINCT f.id || ', ' || f.filename || ', ' || f.is_primary || ', ' || f.url) files,\n ARRAY_AGG(DISTINCT h.algorithm || ', ' || encode(h.hash, 'escape') || ', ' || h.file_id) hashes\n FROM versions v\n INNER JOIN release_channels rc on v.release_channel = rc.id\n INNER JOIN game_versions_versions gvv on v.id = gvv.joining_version_id\n INNER JOIN game_versions gv on gvv.game_version_id = gv.id\n INNER JOIN loaders_versions lv on v.id = lv.version_id\n INNER JOIN loaders l on lv.loader_id = l.id\n INNER JOIN files f on v.id = f.version_id\n INNER JOIN hashes h on f.id = h.file_id\n WHERE v.id = $1\n GROUP BY v.id, rc.id;\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "mod_id", + "type_info": "Int8" + }, + { + "ordinal": 2, + "name": "author_id", + "type_info": "Int8" + }, + { + "ordinal": 3, + "name": "version_name", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "version_number", + "type_info": "Varchar" + }, + { + "ordinal": 5, + "name": "changelog", + "type_info": "Varchar" + }, + { + "ordinal": 6, + "name": "changelog_url", + "type_info": "Varchar" + }, + { + "ordinal": 7, + "name": "date_published", + "type_info": "Timestamptz" + }, + { + "ordinal": 8, + "name": "downloads", + "type_info": "Int4" + }, + { + "ordinal": 9, + "name": "release_channel", + "type_info": "Varchar" + }, + { + "ordinal": 10, + "name": "featured", + "type_info": "Bool" + }, + { + "ordinal": 11, + "name": "game_versions", + "type_info": "VarcharArray" + }, + { + "ordinal": 12, + "name": "loaders", + "type_info": "VarcharArray" + }, + { + "ordinal": 13, + "name": "files", + "type_info": "TextArray" + }, + { + "ordinal": 14, + "name": "hashes", + "type_info": "TextArray" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + true, + false, + false, + false, + false, + null, + null, + null, + null + ] + } + }, "97143e41c18d191d09d244113b7b6cdf5bd6ab89c62ac46d0980d700ab288f48": { "query": "\n SELECT name FROM side_types\n WHERE id = $1\n ", "describe": { diff --git a/src/database/models/mod_item.rs b/src/database/models/mod_item.rs index 03e8523e..656ebc0e 100644 --- a/src/database/models/mod_item.rs +++ b/src/database/models/mod_item.rs @@ -429,34 +429,34 @@ impl Mod { if let Some(m) = result { Ok(Some(QueryMod { inner: Mod { - id: ModId(m.id.clone()), - team_id: TeamId(m.team_id.clone()), + id: ModId(m.id), + team_id: TeamId(m.team_id), title: m.title.clone(), description: m.description.clone(), - downloads: m.downloads.clone(), + downloads: m.downloads, body_url: m.body_url.clone(), icon_url: m.icon_url.clone(), - published: m.published.clone(), - updated: m.updated.clone(), + published: m.published, + updated: m.updated, issues_url: m.issues_url.clone(), source_url: m.source_url.clone(), wiki_url: m.wiki_url.clone(), license_url: m.license_url.clone(), discord_url: m.discord_url.clone(), - client_side: SideTypeId(m.client_side.clone()), - status: StatusId(m.status.clone()), - server_side: SideTypeId(m.server_side.clone()), - license: LicenseId(m.license.clone()), + client_side: SideTypeId(m.client_side), + status: StatusId(m.status), + server_side: SideTypeId(m.server_side), + license: LicenseId(m.license), slug: m.slug.clone(), body: m.body.clone(), }, - categories: m.categories.clone().unwrap_or(vec![]), + categories: m.categories.clone().unwrap_or_default(), versions: m .versions .clone() - .unwrap_or(vec![]) + .unwrap_or_default() .into_iter() - .map(|v| VersionId(v)) + .map(VersionId) .collect(), donation_urls: vec![], status: crate::models::mods::ModStatus::from_str(&m.status_name), @@ -506,29 +506,29 @@ impl Mod { .try_filter_map(|e| async { Ok(e.right().map(|m| QueryMod { inner: Mod { - id: ModId(m.id.clone()), - team_id: TeamId(m.team_id.clone()), + id: ModId(m.id), + team_id: TeamId(m.team_id), title: m.title.clone(), description: m.description.clone(), - downloads: m.downloads.clone(), + downloads: m.downloads, body_url: m.body_url.clone(), icon_url: m.icon_url.clone(), - published: m.published.clone(), - updated: m.updated.clone(), + published: m.published, + updated: m.updated, issues_url: m.issues_url.clone(), source_url: m.source_url.clone(), wiki_url: m.wiki_url.clone(), license_url: m.license_url.clone(), discord_url: m.discord_url.clone(), - client_side: SideTypeId(m.client_side.clone()), - status: StatusId(m.status.clone()), - server_side: SideTypeId(m.server_side.clone()), - license: LicenseId(m.license.clone()), + client_side: SideTypeId(m.client_side), + status: StatusId(m.status), + server_side: SideTypeId(m.server_side), + license: LicenseId(m.license), slug: m.slug.clone(), body: m.body.clone(), }, - categories: m.categories.clone().unwrap_or(vec![]), - versions: m.versions.clone().unwrap_or(vec![]).into_iter().map(|v| VersionId(v)).collect(), + categories: m.categories.clone().unwrap_or_default(), + versions: m.versions.clone().unwrap_or_default().into_iter().map(VersionId).collect(), donation_urls: vec![], status: crate::models::mods::ModStatus::from_str(&m.status_name), license_id: m.short, diff --git a/src/database/models/version_item.rs b/src/database/models/version_item.rs index 1e449196..72d7981e 100644 --- a/src/database/models/version_item.rs +++ b/src/database/models/version_item.rs @@ -467,7 +467,7 @@ impl Version { rc.channel release_channel, v.featured featured, ARRAY_AGG(gv.version ORDER BY gv.created) game_versions, ARRAY_AGG(DISTINCT l.loader) loaders, ARRAY_AGG(DISTINCT f.id || ', ' || f.filename || ', ' || f.is_primary || ', ' || f.url) files, - ARRAY_AGG(DISTINCT h.hash || ', ' || h.algorithm || ', ' || h.file_id) hashes + ARRAY_AGG(DISTINCT h.algorithm || ', ' || encode(h.hash, 'escape') || ', ' || h.file_id) hashes FROM versions v INNER JOIN release_channels rc on v.release_channel = rc.id INNER JOIN game_versions_versions gvv on v.id = gvv.joining_version_id @@ -487,7 +487,7 @@ impl Version { if let Some(v) = result { let mut hashes: Vec<(FileId, String, Vec)> = Vec::new(); - v.hashes.unwrap_or(vec![]).into_iter().for_each(|f| { + v.hashes.unwrap_or_default().into_iter().for_each(|f| { let hash: Vec<&str> = f.split(", ").collect(); hashes.push(( FileId(hash[2].parse().unwrap_or(0)), @@ -509,7 +509,7 @@ impl Version { release_channel: v.release_channel, files: v .files - .unwrap_or(vec![]) + .unwrap_or_default() .into_iter() .map(|f| { let file: Vec<&str> = f.split(", ").collect(); @@ -531,8 +531,8 @@ impl Version { } }) .collect(), - game_versions: v.game_versions.unwrap_or(vec![]), - loaders: v.loaders.unwrap_or(vec![]), + game_versions: v.game_versions.unwrap_or_default(), + loaders: v.loaders.unwrap_or_default(), featured: v.featured, })) } else { @@ -576,7 +576,7 @@ impl Version { Ok(e.right().map(|v| { let mut hashes : Vec<(FileId, String, Vec)> = Vec::new(); - v.hashes.unwrap_or(vec![]).into_iter().for_each(|f| { + v.hashes.unwrap_or_default().into_iter().for_each(|f| { let hash : Vec<&str> = f.split(", ").collect(); hashes.push((FileId(hash[2].parse().unwrap_or(0)), hash[0].to_string(), hash[1].to_string().into_bytes())); }); @@ -592,7 +592,7 @@ impl Version { date_published: v.date_published, downloads: v.downloads, release_channel: v.release_channel, - files: v.files.unwrap_or(vec![]).into_iter().map(|f| { + files: v.files.unwrap_or_default().into_iter().map(|f| { let file : Vec<&str> = f.split(", ").collect(); let file_id = FileId(file[0].parse().unwrap_or(0)); let mut file_hashes = HashMap::new(); @@ -611,8 +611,8 @@ impl Version { primary: file[3].parse().unwrap_or(false) } }).collect(), - game_versions: v.game_versions.unwrap_or(vec![]), - loaders: v.loaders.unwrap_or(vec![]), + game_versions: v.game_versions.unwrap_or_default(), + loaders: v.loaders.unwrap_or_default(), featured: v.featured, } })) diff --git a/src/routes/mod_creation.rs b/src/routes/mod_creation.rs index 731c5df0..f8d5f869 100644 --- a/src/routes/mod_creation.rs +++ b/src/routes/mod_creation.rs @@ -306,8 +306,7 @@ async fn mod_create_inner( create_data .categories .iter() - .map(|f| check_length(1..=256, "category", f)) - .collect::>()?; + .try_for_each(|f| check_length(1..=256, "category", f))?; if let Some(url) = &create_data.issues_url { check_length(..=2048, "url", url)?; @@ -322,8 +321,7 @@ async fn mod_create_inner( create_data .initial_versions .iter() - .map(|v| super::version_creation::check_version(v)) - .collect::>()?; + .try_for_each(|v| super::version_creation::check_version(v))?; } // Create VersionBuilders for the versions specified in `initial_versions` @@ -688,7 +686,7 @@ pub fn get_image_content_type(extension: &str) -> Option<&'static str> { _ => "", }; - if content_type != "" { + if !content_type.is_empty() { Some(content_type) } else { None