run (all) extractors for manually added blobs and addresses
parent
506727356c
commit
82c7bfcb64
|
@ -45,3 +45,23 @@ pub trait Extractor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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::hierarchies::{list_roots, resolve_path, UHierPath};
|
||||||
use crate::database::lang::Query;
|
use crate::database::lang::Query;
|
||||||
use crate::database::UpEndDatabase;
|
use crate::database::UpEndDatabase;
|
||||||
use crate::extractors::Extractor;
|
use crate::extractors::{self};
|
||||||
use crate::filesystem::add_file;
|
use crate::filesystem::add_file;
|
||||||
use crate::previews::PreviewStore;
|
use crate::previews::PreviewStore;
|
||||||
use crate::util::exec::block_background;
|
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 actix_web::{http, Responder};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use futures_util::TryStreamExt;
|
use futures_util::TryStreamExt;
|
||||||
use log::{debug, info, trace};
|
use log::{debug, info, trace, warn};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
@ -354,33 +354,34 @@ pub async fn put_object(
|
||||||
InEntry::Address { entity: in_address } => {
|
InEntry::Address { entity: in_address } => {
|
||||||
let address = in_address.try_into().map_err(ErrorBadRequest)?;
|
let address = in_address.try_into().map_err(ErrorBadRequest)?;
|
||||||
|
|
||||||
let entries_to_add = match &address {
|
let label_entry = match &address {
|
||||||
Address::Hash(_) | Address::Uuid(_) => vec![],
|
Address::Hash(_) | Address::Uuid(_) => None,
|
||||||
Address::Attribute(attribute) => vec![Entry {
|
Address::Attribute(attribute) => Some(Entry {
|
||||||
entity: address.clone(),
|
entity: address.clone(),
|
||||||
attribute: LABEL_ATTR.to_string(),
|
attribute: LABEL_ATTR.to_string(),
|
||||||
value: format!("ATTRIBUTE: {attribute}").into(),
|
value: format!("ATTRIBUTE: {attribute}").into(),
|
||||||
}],
|
}),
|
||||||
Address::Url(url) => {
|
Address::Url(url) => Some(Entry {
|
||||||
#[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(),
|
entity: address.clone(),
|
||||||
attribute: LABEL_ATTR.to_string(),
|
attribute: LABEL_ATTR.to_string(),
|
||||||
value: url.clone().into(),
|
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 || {
|
Ok(web::block(move || {
|
||||||
connection.transaction::<_, anyhow::Error, _>(|| {
|
connection.transaction::<_, anyhow::Error, _>(|| {
|
||||||
if connection.retrieve_object(&address)?.is_empty() {
|
if connection.retrieve_object(&address)?.is_empty() {
|
||||||
|
@ -397,8 +398,8 @@ pub async fn put_object(
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for entry in entries_to_add {
|
if let Some(label_entry) = label_entry {
|
||||||
connection.insert_entry(entry)?;
|
connection.insert_entry(label_entry)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((None, Some(address)))
|
Ok((None, Some(address)))
|
||||||
|
@ -466,6 +467,20 @@ pub async fn put_object(
|
||||||
.await;
|
.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)))
|
Ok((None, Some(address)))
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!("Multipart contains no fields."))
|
Err(anyhow!("Multipart contains no fields."))
|
||||||
|
|
Loading…
Reference in New Issue