mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-19 01:49:24 +00:00
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { useTranslation } from 'react-i18next';
|
|
import { useToolOperation, ToolType } from '../shared/useToolOperation';
|
|
import { createStandardErrorHandler } from '../../../utils/toolErrorHandler';
|
|
import { RotateParameters, defaultParameters, normalizeAngle } from './useRotateParameters';
|
|
|
|
// Static configuration that can be used by both the hook and automation executor
|
|
export const buildRotateFormData = (parameters: RotateParameters, file: File): FormData => {
|
|
const formData = new FormData();
|
|
formData.append("fileInput", file);
|
|
// Normalize angle for backend (0, 90, 180, 270)
|
|
formData.append("angle", normalizeAngle(parameters.angle).toString());
|
|
return formData;
|
|
};
|
|
|
|
// Static configuration object
|
|
export const rotateOperationConfig = {
|
|
toolType: ToolType.singleFile,
|
|
buildFormData: buildRotateFormData,
|
|
operationType: 'rotate',
|
|
endpoint: '/api/v1/general/rotate-pdf',
|
|
defaultParameters,
|
|
} as const;
|
|
|
|
export const useRotateOperation = () => {
|
|
const { t } = useTranslation();
|
|
|
|
return useToolOperation<RotateParameters>({
|
|
...rotateOperationConfig,
|
|
getErrorMessage: createStandardErrorHandler(t('rotate.error.failed', 'An error occurred while rotating the PDF.'))
|
|
});
|
|
};
|