From a5f9331023b434f1edfee9a756b40e38a312192f Mon Sep 17 00:00:00 2001 From: Geometrically <18202329+Geometrically@users.noreply.github.com> Date: Thu, 8 Dec 2022 15:42:59 -0700 Subject: [PATCH] Fix hashes not showing (#496) * Fix hashes not showing * Run prepare + fmt --- src/database/models/version_item.rs | 8 ++++---- src/models/projects.rs | 21 ++++++--------------- src/routes/maven.rs | 6 ++---- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/database/models/version_item.rs b/src/database/models/version_item.rs index 95edab68..be4343bd 100644 --- a/src/database/models/version_item.rs +++ b/src/database/models/version_item.rs @@ -642,11 +642,11 @@ impl Version { .map(|x| VersionStatus::from_str(&x)), }, files: { - #[derive(Deserialize)] + #[derive(Deserialize, Debug)] struct Hash { pub file_id: FileId, pub algorithm: String, - pub hash: Vec, + pub hash: String, } #[derive(Deserialize, Debug)] @@ -795,7 +795,7 @@ impl Version { struct Hash { pub file_id: FileId, pub algorithm: String, - pub hash: Vec, + pub hash: String, } #[derive(Deserialize)] @@ -907,7 +907,7 @@ pub struct QueryFile { pub id: FileId, pub url: String, pub filename: String, - pub hashes: HashMap>, + pub hashes: HashMap, pub primary: bool, pub size: u32, } diff --git a/src/models/projects.rs b/src/models/projects.rs index df303221..ff3d989c 100644 --- a/src/models/projects.rs +++ b/src/models/projects.rs @@ -452,21 +452,12 @@ impl From for Version { files: data .files .into_iter() - .map(|f| { - VersionFile { - url: f.url, - filename: f.filename, - // FIXME: Hashes are currently stored as an ascii byte slice instead - // of as an actual byte array in the database - hashes: f - .hashes - .into_iter() - .map(|(k, v)| Some((k, String::from_utf8(v).ok()?))) - .collect::>() - .unwrap_or_default(), - primary: f.primary, - size: f.size, - } + .map(|f| VersionFile { + url: f.url, + filename: f.filename, + hashes: f.hashes, + primary: f.primary, + size: f.size, }) .collect(), dependencies: data diff --git a/src/routes/maven.rs b/src/routes/maven.rs index bf67e7cd..4434fcb2 100644 --- a/src/routes/maven.rs +++ b/src/routes/maven.rs @@ -321,8 +321,7 @@ pub async fn version_file_sha1( Ok(find_file(&project_id, &project, &version, &file) .and_then(|file| file.hashes.get("sha1")) - .and_then(|hash_bytes| std::str::from_utf8(hash_bytes).ok()) - .map(|hash_str| HttpResponse::Ok().body(hash_str.to_string())) + .map(|hash_str| HttpResponse::Ok().body(hash_str.clone())) .unwrap_or_else(|| HttpResponse::NotFound().body(""))) } @@ -387,7 +386,6 @@ pub async fn version_file_sha512( Ok(find_file(&project_id, &project, &version, &file) .and_then(|file| file.hashes.get("sha512")) - .and_then(|hash_bytes| std::str::from_utf8(hash_bytes).ok()) - .map(|hash_str| HttpResponse::Ok().body(hash_str.to_string())) + .map(|hash_str| HttpResponse::Ok().body(hash_str.clone())) .unwrap_or_else(|| HttpResponse::NotFound().body(""))) }