Skip to content

Commit

Permalink
fix: translate the id into a hash before fetching from the storage
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Jun 14, 2024
1 parent 9b7fd77 commit 12c0d71
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions modules/fundamental/src/advisory/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ struct UploadParams {
#[utoipa::path(
tag = "advisory",
context_path = "/api",
request_body = Vec <u8>,
params( UploadParams ),
request_body = Vec<u8>,
params(UploadParams),
responses(
(status = 201, description = "Upload a file"),
(status = 400, description = "The file could not be parsed as an advisory"),
(status = 201, description = "Upload a file"),
(status = 400, description = "The file could not be parsed as an advisory"),
)
)]
#[post("/v1/advisory")]
Expand Down Expand Up @@ -135,12 +135,26 @@ pub async fn upload(
)]
#[get("/v1/advisory/{key}/download")]
pub async fn download(
service: web::Data<IngestorService>,
ingestor: web::Data<IngestorService>,
advisory: web::Data<AdvisoryService>,
key: web::Path<String>,
) -> Result<impl Responder, Error> {
let hash_key = Id::from_str(&key).map_err(Error::HashKey)?;

let stream = service
let Some(adv) = advisory.fetch_advisory(hash_key, ()).await? else {
return Ok(HttpResponse::NotFound().finish());
};

let Some(hash) = adv.head.hashes.into_iter().find_map(|hash| match hash {
Id::Sha256(hash) => Some(hash),
_ => None,
}) else {
return Ok(HttpResponse::NotFound().finish());
};

let hash_key = Id::Sha256(hash);

let stream = ingestor
.get_ref()
.storage()
.clone()
Expand Down

0 comments on commit 12c0d71

Please sign in to comment.