/raw/ queries of entries
parent
2f6a265af8
commit
338be4be10
|
@ -249,6 +249,22 @@ impl UpEndConnection {
|
||||||
.execute(&self.conn)?)
|
.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>> {
|
pub fn retrieve_object(&self, object_address: Address) -> Result<Vec<Entry>> {
|
||||||
use crate::database::inner::schema::data::dsl::*;
|
use crate::database::inner::schema::data::dsl::*;
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,16 @@ pub async fn get_raw(
|
||||||
.map_err(ErrorInternalServerError)?;
|
.map_err(ErrorInternalServerError)?;
|
||||||
if let Address::Hash(hash) = address {
|
if let Address::Hash(hash) = address {
|
||||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
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
|
let files = connection
|
||||||
.retrieve_file(hash)
|
.retrieve_file(hash)
|
||||||
.map_err(ErrorInternalServerError)?;
|
.map_err(ErrorInternalServerError)?;
|
||||||
|
|
Loading…
Reference in New Issue