From e46280182324ebce80b202f99252ac47550b10fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sun, 21 Feb 2021 17:08:33 +0100 Subject: [PATCH] fix entry addresses for /api/obj --- src/database.rs | 6 ++++++ src/routes.rs | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/database.rs b/src/database.rs index 5999724..4994db3 100644 --- a/src/database.rs +++ b/src/database.rs @@ -67,6 +67,12 @@ impl Hashable for Entry { } } +impl Entry { + pub fn address(&self) -> Result
{ + Ok(Address::Hash(self.hash()?)) + } +} + impl EntryValue { pub fn to_string(&self) -> Result { let (type_char, content) = match self { diff --git a/src/routes.rs b/src/routes.rs index 7489d5b..da349a6 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -3,7 +3,7 @@ use crate::database::{ insert_entry, query, remove_object, retrieve_file, retrieve_object, DbPool, Entry, Query, }; use crate::filesystem::{list_directory, UPath}; -use crate::hash::{decode, encode, Hashable}; +use crate::hash::{decode, encode}; use crate::jobs::JobContainer; use actix_files::NamedFile; use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorNotFound}; @@ -64,7 +64,13 @@ pub async fn get_query( let mut result: HashMap = HashMap::new(); for entry in entries { result.insert( - encode(entry.hash().map_err(ErrorInternalServerError)?), + encode( + entry + .address() + .map_err(ErrorInternalServerError)? + .encode() + .map_err(ErrorInternalServerError)?, + ), entry, ); } @@ -81,7 +87,7 @@ pub async fn get_object( let response: Result> = retrieve_object( &connection, Address::decode(&decode(address_str.into_inner()).map_err(ErrorBadRequest)?) - .map_err(ErrorInternalServerError)?, + .map_err(ErrorBadRequest)?, ); debug!("{:?}", response); @@ -89,7 +95,13 @@ pub async fn get_object( let mut result: HashMap = HashMap::new(); for entry in response.map_err(error::ErrorInternalServerError)? { result.insert( - encode(entry.hash().map_err(ErrorInternalServerError)?), + encode( + entry + .address() + .map_err(ErrorInternalServerError)? + .encode() + .map_err(ErrorInternalServerError)?, + ), entry, ); }