diff --git a/backend/migrations/202511300000_rename_ocr_text_asset/down.sql b/backend/migrations/202511300000_rename_ocr_text_asset/down.sql new file mode 100644 index 0000000..9c89d15 --- /dev/null +++ b/backend/migrations/202511300000_rename_ocr_text_asset/down.sql @@ -0,0 +1,3 @@ +UPDATE tenant.document_assets +SET asset_type = 'ocr-text' +WHERE asset_type = 'text-content'; diff --git a/backend/migrations/202511300000_rename_ocr_text_asset/up.sql b/backend/migrations/202511300000_rename_ocr_text_asset/up.sql new file mode 100644 index 0000000..4a7bf6e --- /dev/null +++ b/backend/migrations/202511300000_rename_ocr_text_asset/up.sql @@ -0,0 +1,3 @@ +UPDATE tenant.document_assets +SET asset_type = 'text-content' +WHERE asset_type = 'ocr-text'; diff --git a/backend/src/workers/analyze.rs b/backend/src/workers/analyze.rs index 7344fcf..5bbdd6f 100644 --- a/backend/src/workers/analyze.rs +++ b/backend/src/workers/analyze.rs @@ -16,7 +16,7 @@ use super::{ index::IndexDocumentTask, issued_at::DetermineIssuedAtTask, job_execution_from_task_error, - ocr::{GenerateOcrTask, OCR_TEXT_ASSET_TYPE}, + ocr::{GenerateOcrTask, TEXT_CONTENT_ASSET_TYPE}, taskflow::{ document::DocumentVersionTaskContext, BoxedTask, Task, TaskError, TaskExecutor, TaskPlanner, TaskResult, @@ -126,7 +126,7 @@ impl TaskPlanner for AnalyzePlanner { tasks.push(Box::new(GenerateThumbnailsTask::new(self.force))); } - let existing_ocr = ctx.asset(OCR_TEXT_ASSET_TYPE).await?.is_some(); + let existing_ocr = ctx.asset(TEXT_CONTENT_ASSET_TYPE).await?.is_some(); let mut should_index = existing_ocr; if document_supports_ocr(&document) { diff --git a/backend/src/workers/index.rs b/backend/src/workers/index.rs index 7a6c5af..09bd082 100644 --- a/backend/src/workers/index.rs +++ b/backend/src/workers/index.rs @@ -6,7 +6,7 @@ use reqwest::Client; use crate::documents::search::{build_quickwit_ingest_record, quickwit_ingest}; use super::{ - ocr::OCR_TEXT_ASSET_TYPE, + ocr::TEXT_CONTENT_ASSET_TYPE, taskflow::{document::DocumentVersionTaskContext, Task, TaskError, TaskResult}, }; @@ -45,7 +45,7 @@ impl Task for IndexDocumentTask { .ok_or_else(|| TaskError::fail("tenant quickwit index not configured"))?; let asset = ctx - .asset(OCR_TEXT_ASSET_TYPE) + .asset(TEXT_CONTENT_ASSET_TYPE) .await? .ok_or_else(|| TaskError::fail("missing OCR text asset"))?; diff --git a/backend/src/workers/issued_at.rs b/backend/src/workers/issued_at.rs index 238d3b4..05805c9 100644 --- a/backend/src/workers/issued_at.rs +++ b/backend/src/workers/issued_at.rs @@ -12,7 +12,7 @@ use uuid::Uuid; use crate::issued_at::{DateOrder, IssuedAtSettings}; use crate::schema::documents::dsl as documents_dsl; -use crate::workers::ocr::OCR_TEXT_ASSET_TYPE; +use crate::workers::ocr::TEXT_CONTENT_ASSET_TYPE; use crate::workers::taskflow::document::DocumentVersionTaskContext; use crate::workers::taskflow::{Task, TaskContext, TaskError, TaskResult}; @@ -427,10 +427,8 @@ fn month_name_to_number(value: &str, settings: &IssuedAtSettings) -> Option async fn load_document_text(ctx: &mut DocumentVersionTaskContext) -> TaskResult> { let object_key = { - let assets = ctx.assets().await?; - assets - .get(OCR_TEXT_ASSET_TYPE) - .map(|asset| asset.asset.s3_key.clone()) + let asset = ctx.asset(TEXT_CONTENT_ASSET_TYPE).await?; + asset.map(|a| a.asset.s3_key.clone()) }; let Some(key) = object_key else { diff --git a/backend/src/workers/ocr.rs b/backend/src/workers/ocr.rs index 5afc607..d6dd8ff 100644 --- a/backend/src/workers/ocr.rs +++ b/backend/src/workers/ocr.rs @@ -29,7 +29,7 @@ use super::taskflow::{ document::DocumentVersionTaskContext, Task, TaskContext, TaskError, TaskResult, }; -pub const OCR_TEXT_ASSET_TYPE: &str = "ocr-text"; +pub const TEXT_CONTENT_ASSET_TYPE: &str = "text-content"; const MIN_TEXT_LENGTH: usize = 50; pub struct GenerateOcrTask { @@ -83,7 +83,7 @@ impl Task for GenerateOcrTask { let s3_key = document_asset_key( context.document.id, context.version.version_number, - OCR_TEXT_ASSET_TYPE, + TEXT_CONTENT_ASSET_TYPE, asset_id, ); @@ -129,7 +129,7 @@ async fn build_ocr_context( ) -> TaskResult { let document = ctx.document().await?.clone(); let version = ctx.version().await?.clone(); - let asset = ctx.asset(OCR_TEXT_ASSET_TYPE).await?; + let asset = ctx.asset(TEXT_CONTENT_ASSET_TYPE).await?; let existing_asset = asset.map(|asset| asset.asset.clone()); @@ -226,7 +226,7 @@ fn persist_ocr_metadata( let new_asset = NewDocumentAsset { id: asset_id, document_version_id, - asset_type: OCR_TEXT_ASSET_TYPE.to_string(), + asset_type: TEXT_CONTENT_ASSET_TYPE.to_string(), mime_type: "text/plain".to_string(), metadata, s3_key: s3_key.to_string(), diff --git a/frontend/src/documents/DocumentInfoPanel.tsx b/frontend/src/documents/DocumentInfoPanel.tsx index 02f50a4..7f36af6 100644 --- a/frontend/src/documents/DocumentInfoPanel.tsx +++ b/frontend/src/documents/DocumentInfoPanel.tsx @@ -194,7 +194,7 @@ const DocumentInfoPanel: React.FC = ({ render: () => { const messageClass = `${base}__message`; const errorClass = `${base}__message ${base}__message--error`; - const objectClass = `${base}__object ${base}__object--ocr-text`; + const objectClass = `${base}__object ${base}__object--text-content`; if (!contentEnabled || !contentConfig.loadContent) { return ( diff --git a/frontend/src/documents/documentActions.ts b/frontend/src/documents/documentActions.ts index 675a01e..a36b6ee 100644 --- a/frontend/src/documents/documentActions.ts +++ b/frontend/src/documents/documentActions.ts @@ -1,4 +1,4 @@ -import { openOcrTextInNewTab } from '../utils/ocr'; +import { openTextContentInNewTab } from '../utils/ocr'; import type { EnsureAssetUrl, EnsurePreviewData, @@ -21,11 +21,11 @@ const resolveDocumentDownloadHref = (document?: Document | null): string | null return downloadUrl; }; -const hasDocumentOcrAsset = (document?: Document | null, getDocumentAsset?: GetDocumentAsset | null): boolean => { +const hasDocumentTextContentAsset = (document?: Document | null, getDocumentAsset?: GetDocumentAsset | null): boolean => { if (!document || !getDocumentAsset) { return false; } - return Boolean(getDocumentAsset(document, 'ocr-text')); + return Boolean(getDocumentAsset(document, 'text-content')); }; interface CreateDocumentActionStateArgs { @@ -43,7 +43,7 @@ export const createDocumentActionState = ({ ensureAssetUrl, getDocumentAsset, notifyApiError, - ocrErrorMessage = 'Unable to open OCR text.', + ocrErrorMessage = 'Unable to open text content.', }: CreateDocumentActionStateArgs) => { if (!document) { return { @@ -54,19 +54,19 @@ export const createDocumentActionState = ({ } const downloadHref = resolveDocumentDownloadHref(document); - const hasOcr = hasDocumentOcrAsset(document, getDocumentAsset); + const hasOcr = hasDocumentTextContentAsset(document, getDocumentAsset); const openOcr = hasOcr ? async () => { try { - const success = await openOcrTextInNewTab({ + const success = await openTextContentInNewTab({ document, ensurePreviewData, getDocumentAsset, ensureAssetUrl, }); if (!success) { - notifyApiError?.(new Error('OCR text URL unavailable.'), ocrErrorMessage); + notifyApiError?.(new Error('Text content URL unavailable.'), ocrErrorMessage); } return success; } catch (error) { @@ -85,5 +85,5 @@ export const createDocumentActionState = ({ export const documentActionsTestExports = { resolveDocumentDownloadHref, - hasDocumentOcrAsset, + hasDocumentTextContentAsset, }; diff --git a/frontend/src/preview/DocumentViewerPanel.tsx b/frontend/src/preview/DocumentViewerPanel.tsx index d9cd2cd..8fb1ce3 100644 --- a/frontend/src/preview/DocumentViewerPanel.tsx +++ b/frontend/src/preview/DocumentViewerPanel.tsx @@ -135,7 +135,7 @@ const DocumentViewerPanel: React.FC = ({ if (!document || !getDocumentAsset) { return false; } - return Boolean(getDocumentAsset(document, 'ocr-text')); + return Boolean(getDocumentAsset(document, 'text-content')); }, [document, getDocumentAsset]); const navigateToFolder = useCallback( @@ -183,12 +183,12 @@ const DocumentViewerPanel: React.FC = ({ } const updateUrl = () => - resolveDocumentAssetUrl(document, 'ocr-text', { + resolveDocumentAssetUrl(document, 'text-content', { ensureAssetUrl, getAsset: getDocumentAsset, }); - const asset = getDocumentAsset(document, 'ocr-text'); + const asset = getDocumentAsset(document, 'text-content'); let url = updateUrl(); if (!url && document.id && asset?.id && ensureAssetUrl) { @@ -223,10 +223,10 @@ const DocumentViewerPanel: React.FC = ({ id: 'content', label: 'Content', loadContent: loadOcrContent, - loadingMessage: 'Loading OCR content…', - emptyMessage: 'No OCR content available.', - unavailableMessage: 'No OCR content available.', - errorMessage: 'Failed to load OCR content.', + loadingMessage: 'Loading text content…', + emptyMessage: 'No text content available.', + unavailableMessage: 'No text content available.', + errorMessage: 'Failed to load text content.', }), [hasOcr, loadOcrContent], ); @@ -282,7 +282,7 @@ const DocumentViewerPanel: React.FC = ({ ensureAssetUrl, getDocumentAsset, notifyApiError, - ocrErrorMessage: 'Unable to open OCR text.', + ocrErrorMessage: 'Unable to open text content.', }) : null, [ diff --git a/frontend/src/styles/documents/viewer.css b/frontend/src/styles/documents/viewer.css index aa8cb3c..e476243 100644 --- a/frontend/src/styles/documents/viewer.css +++ b/frontend/src/styles/documents/viewer.css @@ -357,7 +357,7 @@ height: 100%; } -.document-viewer__object--ocr-text { +.document-viewer__object--text-content { width: 100%; height: 100%; margin: 0; diff --git a/frontend/src/utils/ocr.ts b/frontend/src/utils/ocr.ts index 51cdeb4..6e6c106 100644 --- a/frontend/src/utils/ocr.ts +++ b/frontend/src/utils/ocr.ts @@ -18,7 +18,7 @@ export type EnsureAssetUrl = ( ) => Promise; export type GetDocumentAsset = AssetManagerGetAsset; -interface ResolveOcrTextUrlOptions { +interface ResolveTextContentUrlOptions { document: Document | null; ensurePreviewData?: EnsurePreviewData; getDocumentAsset?: GetDocumentAsset; @@ -29,15 +29,15 @@ const pickAsset = (doc?: Document | null, getDocumentAsset?: GetDocumentAsset): if (!doc || !getDocumentAsset) { return null; } - return getDocumentAsset(doc, 'ocr-text') || null; + return getDocumentAsset(doc, 'text-content') || null; }; -export async function resolveOcrTextUrl({ +export async function resolveTextContentUrl({ document, ensurePreviewData, getDocumentAsset, ensureAssetUrl, -}: ResolveOcrTextUrlOptions): Promise { +}: ResolveTextContentUrlOptions): Promise { if (!document?.id) { return null; } @@ -75,7 +75,7 @@ export async function resolveOcrTextUrl({ } return ( - resolveDocumentAssetUrl(docRef, 'ocr-text', { + resolveDocumentAssetUrl(docRef, 'text-content', { ensureAssetUrl, getAsset: getDocumentAsset, ensureOptions: { force: true }, @@ -83,7 +83,7 @@ export async function resolveOcrTextUrl({ ); } -export async function openOcrTextInNewTab(options: ResolveOcrTextUrlOptions): Promise { +export async function openTextContentInNewTab(options: ResolveTextContentUrlOptions): Promise { const popup = window.open('', '_blank'); const popupAvailable = Boolean(popup); @@ -96,7 +96,7 @@ export async function openOcrTextInNewTab(options: ResolveOcrTextUrlOptions): Pr } try { - const url = await resolveOcrTextUrl(options); + const url = await resolveTextContentUrl(options); if (!url) { if (popupAvailable) { popup.close();