retireve_file takes reference

feat/vaults
Tomáš Mládek 2022-02-04 20:33:07 +01:00
parent 2337cd54c1
commit 8d51529f38
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
3 changed files with 6 additions and 6 deletions

View File

@ -222,12 +222,12 @@ impl UpEndConnection {
.unwrap())
}
pub fn retrieve_file(&self, obj_hash: Hash) -> Result<Vec<models::OutFile>> {
pub fn retrieve_file(&self, obj_hash: &Hash) -> Result<Vec<models::OutFile>> {
use crate::database::inner::schema::files::dsl::*;
let matches = files
.filter(valid.eq(true))
.filter(hash.eq(obj_hash.0))
.filter(hash.eq(&obj_hash.0))
.load::<models::File>(&self.conn)?;
let matches = matches

View File

@ -58,7 +58,7 @@ impl PreviewStore {
Ok(Some(thumbpath.clone()))
} else {
let connection = self.db.connection()?;
let files = connection.retrieve_file(hash)?;
let files = connection.retrieve_file(&hash)?;
if let Some(file) = files.get(0) {
let preview = match tree_magic_mini::from_filepath(&file.path) {
Some(tm) if tm.starts_with("text") => Ok(TextPath(&file.path).get_thumbnail()?),

View File

@ -66,7 +66,7 @@ pub async fn get_raw(
// Then, check the files
let files = connection
.retrieve_file(hash)
.retrieve_file(&hash)
.map_err(ErrorInternalServerError)?;
if let Some(file) = files.get(0) {
let file_path = state.upend.vault_path.join(&file.path);
@ -268,7 +268,7 @@ pub async fn put_object(
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
let existing_files = connection
.retrieve_file(hash.clone())
.retrieve_file(&hash)
.map_err(ErrorInternalServerError)?;
if existing_files.is_empty() {
@ -465,7 +465,7 @@ pub async fn get_file(
if let Address::Hash(hash) = address {
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
let response = connection
.retrieve_file(hash)
.retrieve_file(&hash)
.map_err(ErrorInternalServerError)?;
Ok(HttpResponse::Ok().json(response))