fix(client): also resolve missing thumbnails

This commit is contained in:
perf3ct 2025-07-15 15:57:14 +00:00
parent 8b23e8a1c1
commit 3df5b5ef1d
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
1 changed files with 11 additions and 5 deletions

View File

@ -137,9 +137,9 @@ pub async fn get_document_thumbnail(
let file_service = FileService::new(state.config.upload_path.clone());
// Try to read thumbnail from the thumbnails directory
let thumbnail_path = format!("{}/thumbnails/{}.jpg", state.config.upload_path, document.id);
match file_service.read_file(&thumbnail_path).await {
// Use the FileService to get or generate thumbnail
#[cfg(feature = "ocr")]
match file_service.get_or_generate_thumbnail(&document.file_path, &document.original_filename).await {
Ok(data) => {
let response = axum::response::Response::builder()
.status(StatusCode::OK)
@ -155,11 +155,17 @@ pub async fn get_document_thumbnail(
debug!("Thumbnail served for document: {}", document_id);
Ok(response)
}
Err(_) => {
// Return a default "no thumbnail" response or generate one on the fly
Err(e) => {
error!("Failed to get or generate thumbnail for document {}: {}", document_id, e);
Err(StatusCode::NOT_FOUND)
}
}
#[cfg(not(feature = "ocr"))]
{
error!("Thumbnail generation requires OCR feature to be enabled");
Err(StatusCode::NOT_FOUND)
}
}
/// Get processed image for a document (if available)