mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-13 17:54:19 +01:00
fix: PDF Timestamp bug
This commit is contained in:
1 parent
6f5c75b913
commit
ea53689bba
27 files changed
+201
-59
No files matched your search
@@ -153,8 +153,21 @@ async function generateProxySignature(
|
||||
.join('');
|
||||
}
|
||||
|
||||
function resolveProxyBase(): string {
|
||||
if (
|
||||
CORS_PROXY_URL.startsWith('http://') ||
|
||||
CORS_PROXY_URL.startsWith('https://')
|
||||
) {
|
||||
return CORS_PROXY_URL;
|
||||
}
|
||||
if (typeof window !== 'undefined' && window.location?.origin) {
|
||||
return new URL(CORS_PROXY_URL, window.location.origin).toString();
|
||||
}
|
||||
return CORS_PROXY_URL;
|
||||
}
|
||||
|
||||
async function buildCorsProxyUrl(url: string): Promise<string> {
|
||||
let proxyUrl = `${CORS_PROXY_URL}?url=${encodeURIComponent(url)}`;
|
||||
let proxyUrl = `${resolveProxyBase()}?url=${encodeURIComponent(url)}`;
|
||||
|
||||
if (!CORS_PROXY_SECRET) {
|
||||
return proxyUrl;
|
||||
@@ -196,6 +209,9 @@ function createCorsAwareFetch(): {
|
||||
? input.toString()
|
||||
: input.url;
|
||||
|
||||
const isAlreadyProxied =
|
||||
CORS_PROXY_URL.length > 0 && url.startsWith(CORS_PROXY_URL);
|
||||
|
||||
const isExternalCertificateUrl =
|
||||
(url.includes('.crt') ||
|
||||
url.includes('.cer') ||
|
||||
@@ -221,6 +237,7 @@ function createCorsAwareFetch(): {
|
||||
url.includes('RFC3161');
|
||||
|
||||
const shouldProxy =
|
||||
!isAlreadyProxied &&
|
||||
(isExternalCertificateUrl || isTsaRequest) &&
|
||||
!url.startsWith(window.location.origin);
|
||||
|
||||
@@ -332,6 +349,19 @@ export async function timestampPdf(
|
||||
pdfBytes: Uint8Array,
|
||||
tsaUrl: string
|
||||
): Promise<Uint8Array> {
|
||||
const pageIsHttps =
|
||||
typeof window !== 'undefined' && window.location?.protocol === 'https:';
|
||||
const tsaIsHttp = /^http:\/\//i.test(tsaUrl);
|
||||
|
||||
if (pageIsHttps && tsaIsHttp && !CORS_PROXY_URL) {
|
||||
throw new Error(
|
||||
`This TSA endpoint uses HTTP (${tsaUrl}). The browser blocks insecure ` +
|
||||
`requests from this HTTPS page. Either choose a TSA with an HTTPS ` +
|
||||
`endpoint or configure VITE_CORS_PROXY_URL at build time so the ` +
|
||||
`request can be relayed through your proxy.`
|
||||
);
|
||||
}
|
||||
|
||||
let effectiveUrl = tsaUrl;
|
||||
|
||||
if (CORS_PROXY_URL) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createIcons, icons } from 'lucide';
|
||||
import { showAlert, showLoader, hideLoader } from '../ui.js';
|
||||
import { t } from '../i18n/i18n';
|
||||
import {
|
||||
readFileAsArrayBuffer,
|
||||
formatBytes,
|
||||
@@ -197,13 +198,7 @@ function updateProcessButton(): void {
|
||||
const processBtn = getElement<HTMLButtonElement>('process-btn');
|
||||
if (!processBtn) return;
|
||||
|
||||
if (state.pdfBytes) {
|
||||
processBtn.classList.remove('hidden');
|
||||
processBtn.disabled = false;
|
||||
} else {
|
||||
processBtn.classList.add('hidden');
|
||||
processBtn.disabled = true;
|
||||
}
|
||||
processBtn.disabled = !state.pdfBytes;
|
||||
}
|
||||
|
||||
function getTsaUrl(): string | null {
|
||||
@@ -233,8 +228,8 @@ async function processTimestamp(): Promise<void> {
|
||||
downloadFile(blob, state.pdfFile.name);
|
||||
|
||||
showAlert(
|
||||
'Success',
|
||||
'PDF timestamped successfully! The timestamp can be verified in Adobe Acrobat and other PDF readers.',
|
||||
t('common.success'),
|
||||
t('tools:timestampPdf.successMessage'),
|
||||
'success'
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user