Skip to content

Commit

Permalink
Fix hashes not showing (#496)
Browse files Browse the repository at this point in the history
* Fix hashes not showing

* Run prepare + fmt
  • Loading branch information
Geometrically authored Dec 8, 2022
1 parent d8b9d84 commit a5f9331
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/database/models/version_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
pub hash: String,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -795,7 +795,7 @@ impl Version {
struct Hash {
pub file_id: FileId,
pub algorithm: String,
pub hash: Vec<u8>,
pub hash: String,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -907,7 +907,7 @@ pub struct QueryFile {
pub id: FileId,
pub url: String,
pub filename: String,
pub hashes: HashMap<String, Vec<u8>>,
pub hashes: HashMap<String, String>,
pub primary: bool,
pub size: u32,
}
21 changes: 6 additions & 15 deletions src/models/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,21 +452,12 @@ impl From<QueryVersion> 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::<Option<_>>()
.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
Expand Down
6 changes: 2 additions & 4 deletions src/routes/maven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")))
}

Expand Down Expand Up @@ -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("")))
}

0 comments on commit a5f9331

Please sign in to comment.