33 lines
994 B
TypeScript
33 lines
994 B
TypeScript
import { generateAnonymizedText } from "@/app/utils/generateAnonymizedText";
|
|
import { EntityMapping } from "@/app/config/entityLabels";
|
|
|
|
interface DownloadActionsProps {
|
|
outputText: string;
|
|
entityMappings?: EntityMapping[];
|
|
}
|
|
|
|
export const useDownloadActions = ({
|
|
outputText,
|
|
entityMappings = [],
|
|
}: DownloadActionsProps) => {
|
|
const copyToClipboard = () => {
|
|
const anonymizedText = generateAnonymizedText(outputText, entityMappings);
|
|
navigator.clipboard.writeText(anonymizedText);
|
|
};
|
|
|
|
const downloadText = () => {
|
|
const anonymizedText = generateAnonymizedText(outputText, entityMappings);
|
|
const blob = new Blob([anonymizedText], { type: "text/plain" });
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement("a");
|
|
a.href = url;
|
|
a.download = "texte-anonymise.txt";
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
URL.revokeObjectURL(url);
|
|
};
|
|
|
|
return { copyToClipboard, downloadText };
|
|
};
|