typescript
This commit is contained in:
+20
-11
@@ -1,24 +1,30 @@
|
||||
import { createAssetView, resolveDocumentAssetUrl } from '../asset_manager';
|
||||
import type {
|
||||
DocumentLike as AssetManagerDocumentLike,
|
||||
DocumentVersionLike,
|
||||
AssetLike as AssetManagerAssetLike,
|
||||
GetAsset as AssetManagerGetAsset,
|
||||
} from '../asset_manager';
|
||||
|
||||
const BASE_FETCH_OPTIONS = { start: 1, limit: 1 } as const;
|
||||
|
||||
interface DocumentLike {
|
||||
id?: string | number;
|
||||
current_version?: unknown;
|
||||
interface DocumentVersion extends DocumentVersionLike {
|
||||
download_path?: string | null;
|
||||
}
|
||||
|
||||
interface AssetLike {
|
||||
id?: string | number;
|
||||
[key: string]: unknown;
|
||||
export interface DocumentLike extends AssetManagerDocumentLike {
|
||||
current_version?: DocumentVersion | null;
|
||||
}
|
||||
|
||||
type EnsurePreviewData = (id: string | number) => Promise<DocumentLike | null | undefined>;
|
||||
type GetDocumentAsset = (doc: DocumentLike, type: string) => AssetLike | null | undefined;
|
||||
type EnsureAssetUrl = (
|
||||
export type AssetLike = AssetManagerAssetLike;
|
||||
|
||||
export type EnsurePreviewData = (id: string | number) => Promise<DocumentLike | null | undefined>;
|
||||
export type EnsureAssetUrl = (
|
||||
id: string | number,
|
||||
asset: AssetLike,
|
||||
options?: { start?: number; limit?: number; force?: boolean },
|
||||
) => Promise<AssetLike | null | undefined>;
|
||||
export type GetDocumentAsset = AssetManagerGetAsset;
|
||||
|
||||
interface ResolveOcrTextUrlOptions {
|
||||
document: DocumentLike | null;
|
||||
@@ -62,10 +68,13 @@ export async function resolveOcrTextUrl({
|
||||
const baseView = createAssetView(asset);
|
||||
const hasUrl = Boolean(baseView.getPrimaryUrl());
|
||||
|
||||
let entry = asset;
|
||||
let entry: AssetLike = asset;
|
||||
if (ensureAssetUrl) {
|
||||
const ensureOptions = { ...BASE_FETCH_OPTIONS, force: !hasUrl };
|
||||
entry = (await ensureAssetUrl(docRef.id!, asset, ensureOptions)) || asset;
|
||||
const ensured = await ensureAssetUrl(docRef.id!, asset, ensureOptions);
|
||||
if (ensured) {
|
||||
entry = ensured;
|
||||
}
|
||||
}
|
||||
|
||||
const ensuredView = createAssetView(entry);
|
||||
|
||||
Reference in New Issue
Block a user