mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-12 10:21:36 +00:00
Improved PDFium initialization and error handling logic
This commit is contained in:
parent
5ea92c9ced
commit
7136c12f45
@ -3,4 +3,5 @@
|
|||||||
- Added support for defining document analysis policies (in preview) by configuration plugins, enabling centralized management of policies across entire departments or organizations.
|
- Added support for defining document analysis policies (in preview) by configuration plugins, enabling centralized management of policies across entire departments or organizations.
|
||||||
- Added an option to hide the policy definition in the Document Analysis Assistant (in preview) when exporting and distributing that policy by a configuration plugin in organizations, making it easier for users to use.
|
- Added an option to hide the policy definition in the Document Analysis Assistant (in preview) when exporting and distributing that policy by a configuration plugin in organizations, making it easier for users to use.
|
||||||
- Added the policy export functionality to the Document Analysis Assistant (in preview). You can now export policies as Lua code for a configuration plugin to distribute the policy across your organization.
|
- Added the policy export functionality to the Document Analysis Assistant (in preview). You can now export policies as Lua code for a configuration plugin to distribute the policy across your organization.
|
||||||
|
- Improved the error checking & logging behavior when the installed `PDFium` version did not meet the minimum required version.
|
||||||
- Fixed a bug where the global minimum confidence level was not being applied to the assistants.
|
- Fixed a bug where the global minimum confidence level was not being applied to the assistants.
|
||||||
@ -246,7 +246,13 @@ async fn stream_pdf(file_path: &str) -> Result<ChunkStream> {
|
|||||||
let (tx, rx) = mpsc::channel(10);
|
let (tx, rx) = mpsc::channel(10);
|
||||||
|
|
||||||
tokio::task::spawn_blocking(move || {
|
tokio::task::spawn_blocking(move || {
|
||||||
let pdfium = Pdfium::ai_studio_init();
|
let pdfium = match Pdfium::ai_studio_init() {
|
||||||
|
Ok(pdfium) => pdfium,
|
||||||
|
Err(e) => {
|
||||||
|
let _ = tx.blocking_send(Err(e));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
let doc = match pdfium.load_pdf_from_file(&path, None) {
|
let doc = match pdfium.load_pdf_from_file(&path, None) {
|
||||||
Ok(document) => document,
|
Ok(document) => document,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@ -1,26 +1,47 @@
|
|||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use pdfium_render::prelude::Pdfium;
|
use pdfium_render::prelude::Pdfium;
|
||||||
|
use log::{error, warn};
|
||||||
|
|
||||||
pub static PDFIUM_LIB_PATH: Lazy<Mutex<Option<String>>> = Lazy::new(|| Mutex::new(None));
|
pub static PDFIUM_LIB_PATH: Lazy<Mutex<Option<String>>> = Lazy::new(|| Mutex::new(None));
|
||||||
|
|
||||||
pub trait PdfiumInit {
|
pub trait PdfiumInit {
|
||||||
fn ai_studio_init() -> Pdfium;
|
fn ai_studio_init() -> Result<Pdfium, Box<dyn std::error::Error + Send + Sync>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PdfiumInit for Pdfium {
|
impl PdfiumInit for Pdfium {
|
||||||
|
|
||||||
/// Initializes the PDFium library for AI Studio.
|
/// Initializes the PDFium library for AI Studio.
|
||||||
fn ai_studio_init() -> Pdfium {
|
fn ai_studio_init() -> Result<Pdfium, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let lib_path = PDFIUM_LIB_PATH.lock().unwrap();
|
let lib_path = PDFIUM_LIB_PATH.lock().unwrap();
|
||||||
if let Some(path) = lib_path.as_ref() {
|
if let Some(path) = lib_path.as_ref() {
|
||||||
return Pdfium::new(
|
return match Pdfium::bind_to_library(Pdfium::pdfium_platform_library_name_at_path(path)) {
|
||||||
Pdfium::bind_to_library(Pdfium::pdfium_platform_library_name_at_path(path))
|
Ok(binding) => Ok(Pdfium::new(binding)),
|
||||||
.or_else(|_| Pdfium::bind_to_system_library())
|
Err(library_error) => {
|
||||||
.unwrap(),
|
match Pdfium::bind_to_system_library() {
|
||||||
|
Ok(binding) => Ok(Pdfium::new(binding)),
|
||||||
|
Err(system_error) => {
|
||||||
|
error!(
|
||||||
|
"Failed to load PDFium from '{path}' and the system library. Developer action (from repo root): run the build script once to download the required PDFium version: `cd app/Build` and `dotnet run build`. Details: library error: '{library_error}'; system error: '{system_error}'."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Err(Box::new(system_error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Pdfium::new(Pdfium::bind_to_system_library().unwrap())
|
warn!("No custom PDFium library path set; trying to load PDFium from the system library.");
|
||||||
|
match Pdfium::bind_to_system_library() {
|
||||||
|
Ok(binding) => Ok(Pdfium::new(binding)),
|
||||||
|
Err(system_error) => {
|
||||||
|
error!(
|
||||||
|
"Failed to load PDFium from the system library. Developer action (from repo root): run the build script once to download the required PDFium version: `cd app/Build` and `dotnet run build`. Details: '{system_error}'."
|
||||||
|
);
|
||||||
|
|
||||||
|
Err(Box::new(system_error))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user