don't duplicate file if it already exists
parent
3cc0dcff45
commit
1f058670f8
|
@ -214,9 +214,15 @@ pub async fn put_object(
|
|||
}
|
||||
let path = PathBuf::from(file.path());
|
||||
let hash = web::block(move || path.hash()).await?;
|
||||
|
||||
let address = Address::Hash(hash.clone());
|
||||
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
|
||||
let existing_files = connection
|
||||
.retrieve_file(hash.clone())
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
|
||||
if existing_files.is_empty() {
|
||||
let addr_str = encode(address.encode().map_err(ErrorInternalServerError)?);
|
||||
let final_name = if let Some(filename) = filename {
|
||||
format!("{addr_str}_{filename}")
|
||||
|
@ -234,8 +240,8 @@ pub async fn put_object(
|
|||
})
|
||||
.await?;
|
||||
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
add_file(&connection, &final_path, hash).map_err(ErrorInternalServerError)?;
|
||||
}
|
||||
|
||||
if let Some(filename) = filename {
|
||||
let _ = upend_insert_val!(&connection, address, "LBL", filename);
|
||||
|
|
Loading…
Reference in New Issue