/raw/ queries of entries
This commit is contained in:
parent
2f6a265af8
commit
338be4be10
2 changed files with 26 additions and 0 deletions
|
@ -249,6 +249,22 @@ impl UpEndConnection {
|
|||
.execute(&self.conn)?)
|
||||
}
|
||||
|
||||
pub fn retrieve_entry(&self, hash: Hash) -> Result<Option<Entry>> {
|
||||
use crate::database::inner::schema::data::dsl::*;
|
||||
|
||||
let entry = data
|
||||
.filter(identity.eq(Address::Hash(hash).encode()?))
|
||||
.load::<models::Entry>(&self.conn)?;
|
||||
|
||||
match entry.len() {
|
||||
0 => Ok(None),
|
||||
1 => Ok(Some(Entry::try_from(entry.get(0).unwrap())?)),
|
||||
_ => {
|
||||
unreachable!("Multiple entries returned with the same hash - this should be impossible!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn retrieve_object(&self, object_address: Address) -> Result<Vec<Entry>> {
|
||||
use crate::database::inner::schema::data::dsl::*;
|
||||
|
||||
|
|
|
@ -48,6 +48,16 @@ pub async fn get_raw(
|
|||
.map_err(ErrorInternalServerError)?;
|
||||
if let Address::Hash(hash) = address {
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
|
||||
// First check if there's an entry with this hash
|
||||
let entry = connection
|
||||
.retrieve_entry(hash.clone())
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
if let Some(entry) = entry {
|
||||
return Ok(Either::B(HttpResponse::Ok().json(entry)));
|
||||
}
|
||||
|
||||
// Then, check the files
|
||||
let files = connection
|
||||
.retrieve_file(hash)
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
|
|
Loading…
Reference in a new issue