run (all) extractors for manually added blobs and addresses
parent
506727356c
commit
82c7bfcb64
|
@ -44,4 +44,24 @@ pub trait Extractor {
|
|||
Ok(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extract_all(
|
||||
address: &Address,
|
||||
connection: &UpEndConnection,
|
||||
job_container: Arc<RwLock<JobContainer>>,
|
||||
) -> Result<usize> {
|
||||
let mut entry_count = 0;
|
||||
|
||||
#[cfg(feature = "extractors-web")]
|
||||
{
|
||||
entry_count += web::WebExtractor.insert_info(address, connection, job_container.clone())?;
|
||||
}
|
||||
|
||||
#[cfg(feature = "extractors-audio")]
|
||||
{
|
||||
entry_count += audio::ID3Extractor.insert_info(address, connection, job_container)?;
|
||||
}
|
||||
|
||||
Ok(entry_count)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::database::entry::{Entry, EntryValue, InvariantEntry};
|
|||
use crate::database::hierarchies::{list_roots, resolve_path, UHierPath};
|
||||
use crate::database::lang::Query;
|
||||
use crate::database::UpEndDatabase;
|
||||
use crate::extractors::Extractor;
|
||||
use crate::extractors::{self};
|
||||
use crate::filesystem::add_file;
|
||||
use crate::previews::PreviewStore;
|
||||
use crate::util::exec::block_background;
|
||||
|
@ -18,7 +18,7 @@ use actix_web::{delete, error, get, post, put, web, Either, Error, HttpResponse}
|
|||
use actix_web::{http, Responder};
|
||||
use anyhow::{anyhow, Result};
|
||||
use futures_util::TryStreamExt;
|
||||
use log::{debug, info, trace};
|
||||
use log::{debug, info, trace, warn};
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
|
@ -354,33 +354,34 @@ pub async fn put_object(
|
|||
InEntry::Address { entity: in_address } => {
|
||||
let address = in_address.try_into().map_err(ErrorBadRequest)?;
|
||||
|
||||
let entries_to_add = match &address {
|
||||
Address::Hash(_) | Address::Uuid(_) => vec![],
|
||||
Address::Attribute(attribute) => vec![Entry {
|
||||
let label_entry = match &address {
|
||||
Address::Hash(_) | Address::Uuid(_) => None,
|
||||
Address::Attribute(attribute) => Some(Entry {
|
||||
entity: address.clone(),
|
||||
attribute: LABEL_ATTR.to_string(),
|
||||
value: format!("ATTRIBUTE: {attribute}").into(),
|
||||
}],
|
||||
Address::Url(url) => {
|
||||
#[cfg(feature = "extractors-web")]
|
||||
{
|
||||
let _address = address.clone();
|
||||
block_background(move || {
|
||||
(crate::extractors::web::WebExtractor {}).insert_info(
|
||||
&_address,
|
||||
&state.upend.connection()?,
|
||||
state.job_container.clone(),
|
||||
)
|
||||
});
|
||||
}
|
||||
vec![Entry {
|
||||
entity: address.clone(),
|
||||
attribute: LABEL_ATTR.to_string(),
|
||||
value: url.clone().into(),
|
||||
}]
|
||||
}
|
||||
}),
|
||||
Address::Url(url) => Some(Entry {
|
||||
entity: address.clone(),
|
||||
attribute: LABEL_ATTR.to_string(),
|
||||
value: url.clone().into(),
|
||||
}),
|
||||
};
|
||||
|
||||
let _address = address.clone();
|
||||
let _job_container = state.job_container.clone();
|
||||
block_background::<_, _, anyhow::Error>(move || {
|
||||
let extract_result =
|
||||
extractors::extract_all(&_address, &connection, _job_container);
|
||||
if let Ok(entry_count) = extract_result {
|
||||
debug!("Added {entry_count} extracted entries for {_address:?}");
|
||||
} else {
|
||||
warn!("Failed to add extracted entries for {_address:?}!");
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
Ok(web::block(move || {
|
||||
connection.transaction::<_, anyhow::Error, _>(|| {
|
||||
if connection.retrieve_object(&address)?.is_empty() {
|
||||
|
@ -397,8 +398,8 @@ pub async fn put_object(
|
|||
})?;
|
||||
}
|
||||
|
||||
for entry in entries_to_add {
|
||||
connection.insert_entry(entry)?;
|
||||
if let Some(label_entry) = label_entry {
|
||||
connection.insert_entry(label_entry)?;
|
||||
}
|
||||
|
||||
Ok((None, Some(address)))
|
||||
|
@ -466,6 +467,20 @@ pub async fn put_object(
|
|||
.await;
|
||||
}
|
||||
|
||||
let _address = address.clone();
|
||||
let _job_container = state.job_container.clone();
|
||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||
block_background::<_, _, anyhow::Error>(move || {
|
||||
let extract_result =
|
||||
extractors::extract_all(&_address, &connection, _job_container);
|
||||
if let Ok(entry_count) = extract_result {
|
||||
debug!("Added {entry_count} extracted entries for {_address:?}");
|
||||
} else {
|
||||
warn!("Failed to add extracted entries for {_address:?}!");
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
|
||||
Ok((None, Some(address)))
|
||||
} else {
|
||||
Err(anyhow!("Multipart contains no fields."))
|
||||
|
|
Loading…
Reference in New Issue