import React, { useState } from "react"; import { HAREntry } from "../extended-request"; import { StolenDataEntry } from "../stolen-data-entry"; function handleNewFile( element: HTMLInputElement, marked_entries: StolenDataEntry[], setFiltered: (Blob) => void ) { const reader = new FileReader(); reader.addEventListener("load", () => { const content = JSON.parse(reader.result as string); content.log.entries = content.log.entries.filter((har_entry: HAREntry) => marked_entries.some((stolen_entry) => stolen_entry.matchesHAREntry(har_entry) ) ); setFiltered( new Blob([JSON.stringify(content)], { type: "application/json" }) ); }); reader.readAsText(element.files[0]); } export default function HARConverter({ marked_entries, }: { marked_entries: StolenDataEntry[]; }) { const [filtered, setFiltered] = useState(null); const [filename, setFilename] = useState(""); return (
{ setFilename(e.target.files[0].name); handleNewFile(e.target, marked_entries, setFiltered); }} /> {(filtered && ( Pobierz wyfiltrowany HAR )) || null}
); }