2025-08-18 15:26:29 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { useToolOperation } from '../shared/useToolOperation';
|
|
|
|
import { createStandardErrorHandler } from '../../../utils/toolErrorHandler';
|
2025-08-22 14:40:27 +01:00
|
|
|
import { RemovePasswordParameters, defaultParameters } from './useRemovePasswordParameters';
|
|
|
|
|
|
|
|
// Static function that can be used by both the hook and automation executor
|
|
|
|
export const buildRemovePasswordFormData = (parameters: RemovePasswordParameters, file: File): FormData => {
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append("fileInput", file);
|
|
|
|
formData.append("password", parameters.password);
|
|
|
|
return formData;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Static configuration object
|
|
|
|
export const removePasswordOperationConfig = {
|
|
|
|
operationType: 'removePassword',
|
|
|
|
endpoint: '/api/v1/security/remove-password',
|
|
|
|
buildFormData: buildRemovePasswordFormData,
|
|
|
|
filePrefix: 'decrypted_', // Will be overridden in hook with translation
|
|
|
|
multiFileEndpoint: false,
|
|
|
|
defaultParameters,
|
|
|
|
} as const;
|
2025-08-18 15:26:29 +01:00
|
|
|
|
|
|
|
export const useRemovePasswordOperation = () => {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
return useToolOperation<RemovePasswordParameters>({
|
2025-08-22 14:40:27 +01:00
|
|
|
...removePasswordOperationConfig,
|
2025-08-18 15:26:29 +01:00
|
|
|
filePrefix: t('removePassword.filenamePrefix', 'decrypted') + '_',
|
|
|
|
getErrorMessage: createStandardErrorHandler(t('removePassword.error.failed', 'An error occurred while removing the password from the PDF.'))
|
|
|
|
});
|
|
|
|
};
|