use crate::Result;
#[cfg(all(feature = "tokio-runtime", not(target_arch = "wasm32")))]
use crate::XbergError;
use crate::plugins::InternalDocumentExtractor;
#[cfg(all(feature = "tokio-runtime", not(target_arch = "wasm32")))]
use crate::types::{ErrorMetadata, ExtractedDocument, Metadata};
#[cfg(all(feature = "tokio-runtime", not(target_arch = "wasm32")))]
use std::borrow::Cow;
use std::sync::Arc;
pub(in crate::core::extractor) fn get_extractor(mime_type: &str) -> Result<Arc<dyn InternalDocumentExtractor>> {
let registry = crate::plugins::registry::get_document_extractor_registry();
let registry_read = registry.read();
let extractor = registry_read.get_registered(mime_type)?;
let extractor: Arc<dyn InternalDocumentExtractor> = Arc::new(extractor);
#[cfg(feature = "otel")]
{
Ok(Arc::new(
crate::plugins::extractor::instrumented::InstrumentedExtractor::new(extractor),
))
}
#[cfg(not(feature = "otel"))]
{
Ok(extractor)
}
}
#[cfg(all(feature = "tokio-runtime", not(target_arch = "wasm32")))]
#[allow(dead_code)]
pub(crate) fn error_extraction_result(e: &XbergError, elapsed_ms: Option<u64>) -> ExtractedDocument {
let metadata = Metadata {
error: Some(ErrorMetadata {
error_type: format!("{:?}", e),
message: e.to_string(),
}),
extraction_duration_ms: elapsed_ms,
..Default::default()
};
ExtractedDocument {
content: format!("Error: {}", e),
mime_type: Cow::Borrowed("text/plain"),
metadata,
..Default::default()
}
}