mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-18 17:39:24 +00:00

# Description of Changes Redesigns `ToolOperationConfig` so that the types of the functions are always known depending on whether the tool runs on single files, multiple files, or uses custom behaviour
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import { useTranslation } from 'react-i18next';
|
|
import { ToolType, useToolOperation } from '../shared/useToolOperation';
|
|
import { createStandardErrorHandler } from '../../../utils/toolErrorHandler';
|
|
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 = {
|
|
toolType: ToolType.singleFile,
|
|
buildFormData: buildRemovePasswordFormData,
|
|
operationType: 'removePassword',
|
|
endpoint: '/api/v1/security/remove-password',
|
|
filePrefix: 'decrypted_', // Will be overridden in hook with translation
|
|
defaultParameters,
|
|
} as const;
|
|
|
|
export const useRemovePasswordOperation = () => {
|
|
const { t } = useTranslation();
|
|
|
|
return useToolOperation<RemovePasswordParameters>({
|
|
...removePasswordOperationConfig,
|
|
filePrefix: t('removePassword.filenamePrefix', 'decrypted') + '_',
|
|
getErrorMessage: createStandardErrorHandler(t('removePassword.error.failed', 'An error occurred while removing the password from the PDF.'))
|
|
});
|
|
};
|