Stirling-PDF/frontend/src/hooks/tools/ocr/useOCRParameters.ts
James Brunton a6706fcb0c
V2 reduce boilerplate in param hooks (#4246)
# Description of Changes
Extend the base params in all tools param hooks, reducing boilerplate
code.
2025-08-21 07:48:25 +00:00

30 lines
797 B
TypeScript

import { BaseParameters } from '../../../types/parameters';
import { useBaseParameters, BaseParametersHook } from '../shared/useBaseParameters';
export interface OCRParameters extends BaseParameters {
languages: string[];
ocrType: string;
ocrRenderType: string;
additionalOptions: string[];
}
export type OCRParametersHook = BaseParametersHook<OCRParameters>;
const defaultParameters: OCRParameters = {
languages: [],
ocrType: 'skip-text',
ocrRenderType: 'hocr',
additionalOptions: [],
};
export const useOCRParameters = (): OCRParametersHook => {
return useBaseParameters({
defaultParameters,
endpointName: 'ocr-pdf',
validateFn: (params) => {
// At minimum, we need at least one language selected
return params.languages.length > 0;
},
});
};