mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 11:00:47 +02:00
feat(security): add RFC 3161 PDF timestamp tool (#5855)
Co-authored-by: Anthony Stirling <[email protected]>
This commit is contained in:
co-authored by
Anthony Stirling
parent
7b3985e34a
commit
8bbfbd63d7
@@ -0,0 +1,33 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ToolType, useToolOperation } from '@app/hooks/tools/shared/useToolOperation';
|
||||
import { createStandardErrorHandler } from '@app/utils/toolErrorHandler';
|
||||
import { TimestampPdfParameters, defaultParameters } from '@app/hooks/tools/timestampPdf/useTimestampPdfParameters';
|
||||
|
||||
export const buildTimestampPdfFormData = (parameters: TimestampPdfParameters, file: File): FormData => {
|
||||
const formData = new FormData();
|
||||
formData.append('fileInput', file);
|
||||
|
||||
formData.append('tsaUrl', parameters.tsaUrl);
|
||||
|
||||
return formData;
|
||||
};
|
||||
|
||||
export const timestampPdfOperationConfig = {
|
||||
toolType: ToolType.singleFile,
|
||||
buildFormData: buildTimestampPdfFormData,
|
||||
operationType: 'timestampPdf',
|
||||
endpoint: '/api/v1/security/timestamp-pdf',
|
||||
multiFileEndpoint: false,
|
||||
defaultParameters,
|
||||
} as const;
|
||||
|
||||
export const useTimestampPdfOperation = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return useToolOperation<TimestampPdfParameters>({
|
||||
...timestampPdfOperationConfig,
|
||||
getErrorMessage: createStandardErrorHandler(
|
||||
t('timestampPdf.error.failed', 'An error occurred while timestamping the PDF.')
|
||||
),
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
import { BaseParameters } from '@app/types/parameters';
|
||||
import { useBaseParameters, BaseParametersHook } from '@app/hooks/tools/shared/useBaseParameters';
|
||||
|
||||
// Fallback presets used only when AppConfig hasn't loaded yet.
|
||||
// The real presets are served by the backend via /api/v1/config/app-config
|
||||
// (field: timestampTsaPresets) — single source of truth.
|
||||
export const FALLBACK_TSA_PRESETS = [
|
||||
{ label: 'DigiCert', url: 'http://timestamp.digicert.com' },
|
||||
{ label: 'Sectigo', url: 'http://timestamp.sectigo.com' },
|
||||
{ label: 'SSL.com', url: 'http://ts.ssl.com' },
|
||||
{ label: 'FreeTSA', url: 'https://freetsa.org/tsr' },
|
||||
{ label: 'MeSign', url: 'http://tsa.mesign.com' },
|
||||
] as const;
|
||||
|
||||
export interface TimestampPdfParameters extends BaseParameters {
|
||||
tsaUrl: string;
|
||||
}
|
||||
|
||||
export const defaultParameters: TimestampPdfParameters = {
|
||||
tsaUrl: FALLBACK_TSA_PRESETS[0].url,
|
||||
};
|
||||
|
||||
export type TimestampPdfParametersHook = BaseParametersHook<TimestampPdfParameters>;
|
||||
|
||||
export const useTimestampPdfParameters = (): TimestampPdfParametersHook => {
|
||||
return useBaseParameters({
|
||||
defaultParameters,
|
||||
endpointName: 'timestamp-pdf',
|
||||
validateFn: (params) => {
|
||||
return params.tsaUrl.trim().length > 0;
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user