mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-13 17:54:19 +01:00
New Features: - Digital Signature tool: Sign PDFs with X.509 certificates (PFX/PEM) - Visible and invisible signatures - All pages, first page, last page, or custom page selection - Dynamic signature height based on text content - Custom signature text, image, and styling options - Validate Signature tool: Verify digital signatures in PDFs - Extract and parse PKCS#7 signatures - View signer and issuer certificate details - Check certificate validity and expiry - Optional custom X.509 certificate for trust verification - Full/partial coverage detection Infrastructure: - Added Cloudflare Worker CORS proxy for certificate chain fetching - Updated README with new tools and proxy deployment instructions Documentation: - Added Digital Signature and Validate Signature to README tools table - Added CORS proxy deployment guide for self-hosters
76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
/**
|
|
* WASM CDN Configuration
|
|
*
|
|
* Centralized configuration for loading WASM files from jsDelivr CDN or local paths.
|
|
* Supports environment-based toggling and automatic fallback mechanism.
|
|
*/
|
|
|
|
const USE_CDN = import.meta.env.VITE_USE_CDN === 'true';
|
|
import { CDN_URLS, PACKAGE_VERSIONS } from '../const/cdn-version';
|
|
|
|
const LOCAL_PATHS = {
|
|
ghostscript: import.meta.env.BASE_URL + 'ghostscript-wasm/',
|
|
pymupdf: import.meta.env.BASE_URL + 'pymupdf-wasm/',
|
|
} as const;
|
|
|
|
export type WasmPackage = 'ghostscript' | 'pymupdf';
|
|
|
|
export function getWasmBaseUrl(packageName: WasmPackage): string {
|
|
if (USE_CDN) {
|
|
return CDN_URLS[packageName];
|
|
}
|
|
return LOCAL_PATHS[packageName];
|
|
}
|
|
|
|
export function getWasmFallbackUrl(packageName: WasmPackage): string {
|
|
return LOCAL_PATHS[packageName];
|
|
}
|
|
|
|
|
|
export function isCdnEnabled(): boolean {
|
|
return USE_CDN;
|
|
}
|
|
|
|
/**
|
|
* Fetch a file with automatic CDN → local fallback
|
|
* @param packageName - WASM package name
|
|
* @param fileName - File name relative to package base
|
|
* @returns Response object
|
|
*/
|
|
export async function fetchWasmFile(
|
|
packageName: WasmPackage,
|
|
fileName: string
|
|
): Promise<Response> {
|
|
const cdnUrl = CDN_URLS[packageName] + fileName;
|
|
const localUrl = LOCAL_PATHS[packageName] + fileName;
|
|
|
|
if (USE_CDN) {
|
|
try {
|
|
console.log(`[WASM CDN] Fetching from CDN: ${cdnUrl}`);
|
|
const response = await fetch(cdnUrl);
|
|
if (response.ok) {
|
|
return response;
|
|
}
|
|
console.warn(`[WASM CDN] CDN fetch failed with status ${response.status}, trying local fallback...`);
|
|
} catch (error) {
|
|
console.warn(`[WASM CDN] CDN fetch error:`, error, `- trying local fallback...`);
|
|
}
|
|
}
|
|
|
|
const response = await fetch(localUrl);
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to fetch ${fileName}: HTTP ${response.status}`);
|
|
}
|
|
return response;
|
|
}
|
|
|
|
// use this to debug
|
|
export function getWasmConfigInfo() {
|
|
return {
|
|
cdnEnabled: USE_CDN,
|
|
packageVersions: PACKAGE_VERSIONS,
|
|
cdnUrls: CDN_URLS,
|
|
localPaths: LOCAL_PATHS,
|
|
};
|
|
}
|