import type { HttpRequest } from "@yaakapp-internal/models"; import mime from "mime"; import { useKeyValue } from "../hooks/useKeyValue"; import { Banner } from "./core/Banner"; import { Button } from "./core/Button"; import { InlineCode } from "./core/InlineCode"; import { HStack, VStack } from "./core/Stacks"; import { SelectFile } from "./SelectFile"; type Props = { requestId: string; contentType: string | null; body: HttpRequest["body"]; onChange: (body: HttpRequest["body"]) => void; onChangeContentType: (contentType: string | null) => void; }; export function BinaryFileEditor({ contentType, body, onChange, onChangeContentType, requestId, }: Props) { const ignoreContentType = useKeyValue({ namespace: "global", key: ["ignore_content_type", requestId], fallback: false, }); const handleChange = async ({ filePath }: { filePath: string | null }) => { await ignoreContentType.set(false); onChange({ filePath: filePath ?? undefined }); }; const filePath = typeof body.filePath === "string" ? body.filePath : null; const mimeType = mime.getType(filePath ?? "") ?? "application/octet-stream"; return ( {filePath != null && mimeType !== contentType && !ignoreContentType.value && (
Set Content-Type header
{mimeType} for current request?
)}
); }