fix: address CodeRabbit review feedback
- Handle Headers instance in TSA request detection (not just plain objects) - Wrap timestampPdf with createCorsAwareFetch for OCSP/cert chain requests - Pass 'success' type to showAlert on successful timestamp - Add TSA URL context to timestamp error messages with cause - Remove redundant Uint8Array wrapping in TimestampNode
This commit is contained in:
@@ -208,10 +208,12 @@ function createCorsAwareFetch(): {
|
||||
|
||||
const isTsaRequest =
|
||||
(init?.headers &&
|
||||
typeof init.headers === 'object' &&
|
||||
'Content-Type' in init.headers &&
|
||||
(init.headers as Record<string, string>)['Content-Type'] ===
|
||||
'application/timestamp-query') ||
|
||||
(init.headers instanceof Headers
|
||||
? init.headers.get('Content-Type') === 'application/timestamp-query'
|
||||
: typeof init.headers === 'object' &&
|
||||
!Array.isArray(init.headers) &&
|
||||
(init.headers as Record<string, string>)['Content-Type'] ===
|
||||
'application/timestamp-query')) ||
|
||||
url.includes('timestamp') ||
|
||||
url.includes('/tsa') ||
|
||||
url.includes('/tsr') ||
|
||||
@@ -350,8 +352,14 @@ export async function timestampPdf(
|
||||
|
||||
const signer = new PdfSigner(signOptions);
|
||||
|
||||
const timestampedPdfBytes = await signer.sign(pdfBytes);
|
||||
return new Uint8Array(timestampedPdfBytes);
|
||||
const { restore } = createCorsAwareFetch();
|
||||
|
||||
try {
|
||||
const timestampedPdfBytes = await signer.sign(pdfBytes);
|
||||
return new Uint8Array(timestampedPdfBytes);
|
||||
} finally {
|
||||
restore();
|
||||
}
|
||||
}
|
||||
|
||||
export function getCertificateInfo(certificate: forge.pki.Certificate): {
|
||||
|
||||
@@ -238,7 +238,8 @@ async function processTimestamp(): Promise<void> {
|
||||
|
||||
showAlert(
|
||||
'Success',
|
||||
'PDF timestamped successfully! The timestamp can be verified in Adobe Acrobat and other PDF readers.'
|
||||
'PDF timestamped successfully! The timestamp can be verified in Adobe Acrobat and other PDF readers.',
|
||||
'success'
|
||||
);
|
||||
|
||||
resetState();
|
||||
|
||||
Reference in New Issue
Block a user