From a119837c8a77a66dfc1a4f8af48f674f922ba3fc Mon Sep 17 00:00:00 2001 From: alam00000 Date: Sat, 21 Feb 2026 14:27:53 +0530 Subject: [PATCH] fix: improve error handling in performCondenseCompression function fix: routing --- nginx.conf | 4 ++-- src/js/utils/compress.ts | 27 ++++++++++++--------------- vite.config.ts | 17 +++++++++-------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/nginx.conf b/nginx.conf index e30d20d..77c0aea 100644 --- a/nginx.conf +++ b/nginx.conf @@ -84,7 +84,7 @@ http { add_header Cache-Control "public, immutable"; } - location ~ ^/(en|de|es|zh|zh-TW|vi|it|id|tr|fr|pt|be)(/.*)?$ { + location ~ ^/(en|ar|be|da|de|es|fr|id|it|nl|pt|tr|vi|zh|zh-TW)(/.*)?$ { try_files $uri $uri/ $uri.html /$1/index.html /index.html; expires 5m; add_header Cache-Control "public, must-revalidate"; @@ -92,7 +92,7 @@ http { add_header Cross-Origin-Opener-Policy "same-origin" always; } - location ~ ^/(.+?)/(en|de|es|zh|zh-TW|vi|it|id|tr|fr|pt|be)(/.*)?$ { + location ~ ^/(.+?)/(en|ar|be|da|de|es|fr|id|it|nl|pt|tr|vi|zh|zh-TW)(/.*)?$ { try_files $uri $uri/ $uri.html /$1/$2/index.html /$1/index.html /index.html; expires 5m; add_header Cache-Control "public, must-revalidate"; diff --git a/src/js/utils/compress.ts b/src/js/utils/compress.ts index e0a635d..ff4dbae 100644 --- a/src/js/utils/compress.ts +++ b/src/js/utils/compress.ts @@ -83,25 +83,22 @@ export async function performCondenseCompression( try { const result = await pymupdf.compressPdf(fileBlob, options); return result; - } catch (error: any) { - const errorMessage = error?.message || String(error); - if ( - errorMessage.includes('PatternType') || - errorMessage.includes('pattern') - ) { - const fallbackOptions = { - ...options, - images: { - ...options.images, - enabled: false, - }, - }; + } catch { + const fallbackOptions = { + ...options, + images: { + ...options.images, + enabled: false, + }, + }; + try { const result = await pymupdf.compressPdf(fileBlob, fallbackOptions); return { ...result, usedFallback: true }; + } catch (fallbackError: any) { + const msg = fallbackError?.message || String(fallbackError); + throw new Error(`PDF compression failed: ${msg}`); } - - throw new Error(`PDF compression failed: ${errorMessage}`); } } diff --git a/vite.config.ts b/vite.config.ts index 1dbb159..ff74d5f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -14,19 +14,20 @@ import type { OutputBundle } from 'rollup'; const SUPPORTED_LANGUAGES = [ 'en', + 'ar', 'be', + 'da', 'de', 'es', + 'fr', + 'id', + 'it', + 'nl', + 'pt', + 'tr', + 'vi', 'zh', 'zh-TW', - 'vi', - 'it', - 'id', - 'tr', - 'fr', - 'pt', - 'nl', - 'da', ] as const; const LANG_REGEX = new RegExp( `^/(${SUPPORTED_LANGUAGES.join('|')})(?:/(.*))?$`