diff --git a/src/hooks/custom/LoggerHook.ts b/src/hooks/custom/LoggerHook.ts index ec4b0c9d..f26e31b7 100644 --- a/src/hooks/custom/LoggerHook.ts +++ b/src/hooks/custom/LoggerHook.ts @@ -46,7 +46,6 @@ export class LoggerHook implements AfterSuccessHook, AfterErrorHook { afterSuccess(hookCtx: AfterSuccessContext, response: Response): Response { this.retriesCounter.delete(hookCtx.operationID); // NOTE: In case of split page partition this means - at least one of the splits was partitioned successfully - console.info("Successfully partitioned the document."); return response; } @@ -67,15 +66,14 @@ export class LoggerHook implements AfterSuccessHook, AfterErrorHook { this.logRetries(response, error, hookCtx.operationID); if (response && response.status === 200) { - console.info("Successfully partitioned the document."); - } else { - console.error("Failed to partition the document."); - if (response) { - console.error(`Server responded with ${response.status} - ${response.statusText}`); - } - if (error) { - console.error(`Following error occurred - ${(error as Error).message}`); - } + return { response, error }; + } + console.error("Failed to partition the document."); + if (response) { + console.error(`Server responded with ${response.status} - ${response.statusText}`); + } + if (error) { + console.error(`Following error occurred - ${(error as Error).message}`); } return { response, error }; } diff --git a/src/hooks/custom/SplitPdfHook.ts b/src/hooks/custom/SplitPdfHook.ts index c2d5e51e..aec9b8fb 100644 --- a/src/hooks/custom/SplitPdfHook.ts +++ b/src/hooks/custom/SplitPdfHook.ts @@ -110,11 +110,9 @@ export class SplitPdfHook const file = formData.get(PARTITION_FORM_FILES_KEY) as File | null; if (!splitPdfPage) { - console.info("Partitioning without split.") return request; } - console.info("Preparing to split document for partition.") if (!this.client) { console.warn("HTTP client not accessible! Partitioning without split."); return request; @@ -122,7 +120,6 @@ export class SplitPdfHook const [error, pdf, totalPages] = await loadPdf(file); if (file === null || pdf === null || error) { - console.info("Partitioning without split.") return request; } @@ -130,16 +127,12 @@ export class SplitPdfHook const pagesCount = pageRangeEnd - pageRangeStart + 1; const startingPageNumber = getStartingPageNumber(formData); - console.info("Starting page number set to %d", startingPageNumber); const concurrencyLevel = getSplitPdfConcurrencyLevel(formData); - console.info("Concurrency level set to %d", concurrencyLevel) this.allowFailed = getSplitPdfAllowFailed(formData); - console.info("Allow failed set to %s", this.allowFailed) const splitSize = await getOptimalSplitSize(pagesCount, concurrencyLevel); - console.info("Determined optimal split size of %d pages.", splitSize) // If user wants a specific page range, we need to call splitPdf, // even if this page count is too small to be split normally @@ -148,26 +141,11 @@ export class SplitPdfHook // Otherwise, if there are not enough pages, return the original request without splitting if (!isPageRangeRequested) { if (splitSize >= pagesCount || pagesCount < MIN_PAGES_PER_THREAD) { - console.info( - "Document has too few pages (%d) to be split efficiently. Partitioning without split.", - pagesCount, - ) return request; } } const splits = await splitPdf(pdf, splitSize, pageRangeStart, pageRangeEnd); - const numberOfSplits = splits.length - console.info( - "Document split into %d, %d-paged sets.", - numberOfSplits, - splitSize, - ) - console.info( - "Partitioning %d, %d-paged sets.", - numberOfSplits, - splitSize, - ) const oneSecond = 1000; const oneMinute = 1000 * 60; @@ -181,12 +159,6 @@ export class SplitPdfHook for (const { content, startPage } of splits) { // Both startPage and startingPageNumber are 1-based, so we need to subtract 1 const firstPageNumber = startPage + startingPageNumber - 1; - console.info( - "Partitioning set #%d (pages %d-%d).", - setIndex, - firstPageNumber, - Math.min(firstPageNumber + splitSize - 1, pagesCount), - ); const body = await prepareRequestBody( formData, @@ -261,8 +233,7 @@ export class SplitPdfHook concurrencyLevel ); - const dummyRequest = new Request("https://no-op/"); - return dummyRequest; + return new Request("https://no-op/"); } /** diff --git a/src/hooks/custom/utils/form.ts b/src/hooks/custom/utils/form.ts index 849b7054..2b6a287a 100644 --- a/src/hooks/custom/utils/form.ts +++ b/src/hooks/custom/utils/form.ts @@ -135,13 +135,6 @@ export function getSplitPdfConcurrencyLevel(formData: FormData): number { ); splitPdfConcurrencyLevel = DEFAULT_NUMBER_OF_PARALLEL_REQUESTS; } - - console.info( - `Splitting PDF by page on client. Using ${splitPdfConcurrencyLevel} threads when calling API.` - ); - console.info( - `Set ${PARTITION_FORM_SPLIT_PDF_CONCURRENCY_LEVEL} parameter if you want to change that.` - ); return splitPdfConcurrencyLevel; } @@ -165,25 +158,6 @@ export function getSplitPdfAllowFailed(formData: FormData): boolean { PARTITION_FORM_SPLIT_PDF_ALLOW_FAILED_KEY, DEFAULT_SPLIT_PDF_ALLOW_FAILED_KEY ); - - - if (splitPdfAllowFailed) { - console.info( - `Running split PDF requests in parallel with no-strict mode - - the failed requests will not stop the process, and the resulting elements might miss - some pages in case of failure.` - ); - } else { - console.info( - `Running split PDF requests in parallel with strict mode - - the failed requests will stop the process, and the resulting elements will have all pages - or error out.` - ) - } - - console.info( - `Set ${PARTITION_FORM_SPLIT_PDF_CONCURRENCY_LEVEL} parameter if you want to change that.` - ); return splitPdfAllowFailed; } diff --git a/src/hooks/custom/utils/pdf.ts b/src/hooks/custom/utils/pdf.ts index 7c28e95c..0b8cc7d7 100644 --- a/src/hooks/custom/utils/pdf.ts +++ b/src/hooks/custom/utils/pdf.ts @@ -109,7 +109,6 @@ export async function loadPdf( file: File | null ): Promise<[boolean, PDFDocument | null, number]> { if (!file) { - console.info("Given file is null, so splitting is not enabled."); return [true, null, 0]; } diff --git a/src/hooks/custom/utils/request.ts b/src/hooks/custom/utils/request.ts index dd55eb56..03a1dfde 100644 --- a/src/hooks/custom/utils/request.ts +++ b/src/hooks/custom/utils/request.ts @@ -31,9 +31,7 @@ export async function prepareResponseBody( const allElements: any[] = []; let index = 1; for (const res of responses) { - if (res.status == 200) { - console.info("Successfully partitioned set #%d, elements added to the final result.", index); - } else { + if (res.status != 200) { console.warn("Failed to partition set #%d, its elements will be omitted in the final result.", index); }