fix: improve error handling in performCondenseCompression function

fix: routing
This commit is contained in:
alam00000
2026-02-21 14:27:53 +05:30
parent b9499b228a
commit a119837c8a
3 changed files with 23 additions and 25 deletions

View File

@@ -84,7 +84,7 @@ http {
add_header Cache-Control "public, immutable"; 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; try_files $uri $uri/ $uri.html /$1/index.html /index.html;
expires 5m; expires 5m;
add_header Cache-Control "public, must-revalidate"; add_header Cache-Control "public, must-revalidate";
@@ -92,7 +92,7 @@ http {
add_header Cross-Origin-Opener-Policy "same-origin" always; 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; try_files $uri $uri/ $uri.html /$1/$2/index.html /$1/index.html /index.html;
expires 5m; expires 5m;
add_header Cache-Control "public, must-revalidate"; add_header Cache-Control "public, must-revalidate";

View File

@@ -83,12 +83,7 @@ export async function performCondenseCompression(
try { try {
const result = await pymupdf.compressPdf(fileBlob, options); const result = await pymupdf.compressPdf(fileBlob, options);
return result; return result;
} catch (error: any) { } catch {
const errorMessage = error?.message || String(error);
if (
errorMessage.includes('PatternType') ||
errorMessage.includes('pattern')
) {
const fallbackOptions = { const fallbackOptions = {
...options, ...options,
images: { images: {
@@ -97,11 +92,13 @@ export async function performCondenseCompression(
}, },
}; };
try {
const result = await pymupdf.compressPdf(fileBlob, fallbackOptions); const result = await pymupdf.compressPdf(fileBlob, fallbackOptions);
return { ...result, usedFallback: true }; 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}`);
} }
} }

View File

@@ -14,19 +14,20 @@ import type { OutputBundle } from 'rollup';
const SUPPORTED_LANGUAGES = [ const SUPPORTED_LANGUAGES = [
'en', 'en',
'ar',
'be', 'be',
'da',
'de', 'de',
'es', 'es',
'fr',
'id',
'it',
'nl',
'pt',
'tr',
'vi',
'zh', 'zh',
'zh-TW', 'zh-TW',
'vi',
'it',
'id',
'tr',
'fr',
'pt',
'nl',
'da',
] as const; ] as const;
const LANG_REGEX = new RegExp( const LANG_REGEX = new RegExp(
`^/(${SUPPORTED_LANGUAGES.join('|')})(?:/(.*))?$` `^/(${SUPPORTED_LANGUAGES.join('|')})(?:/(.*))?$`