mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-25 10:08:29 +02:00
Lower large response confirm
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import type { HttpResponse } from '@yaakapp-internal/models';
|
import type { HttpResponse } from '@yaakapp-internal/models';
|
||||||
import { useMemo, type ReactNode } from 'react';
|
import { type ReactNode, useMemo } from 'react';
|
||||||
import { useSaveResponse } from '../hooks/useSaveResponse';
|
import { useSaveResponse } from '../hooks/useSaveResponse';
|
||||||
import { useToggle } from '../hooks/useToggle';
|
import { useToggle } from '../hooks/useToggle';
|
||||||
import { isProbablyTextContentType } from '../lib/contentType';
|
import { isProbablyTextContentType } from '../lib/contentType';
|
||||||
@@ -17,8 +17,7 @@ interface Props {
|
|||||||
response: HttpResponse;
|
response: HttpResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LARGE_TEXT_BYTES = 2 * 1000 * 1000;
|
const LARGE_BYTES = 2 * 1000 * 1000;
|
||||||
const LARGE_OTHER_BYTES = 10 * 1000 * 1000;
|
|
||||||
|
|
||||||
export function ConfirmLargeResponse({ children, response }: Props) {
|
export function ConfirmLargeResponse({ children, response }: Props) {
|
||||||
const { mutate: saveResponse } = useSaveResponse(response);
|
const { mutate: saveResponse } = useSaveResponse(response);
|
||||||
@@ -29,15 +28,14 @@ export function ConfirmLargeResponse({ children, response }: Props) {
|
|||||||
}, [response.headers]);
|
}, [response.headers]);
|
||||||
|
|
||||||
const contentLength = response.contentLength ?? 0;
|
const contentLength = response.contentLength ?? 0;
|
||||||
const tooLargeBytes = isProbablyText ? LARGE_TEXT_BYTES : LARGE_OTHER_BYTES;
|
const isLarge = contentLength > LARGE_BYTES;
|
||||||
const isLarge = contentLength > tooLargeBytes;
|
|
||||||
if (!showLargeResponse && isLarge) {
|
if (!showLargeResponse && isLarge) {
|
||||||
return (
|
return (
|
||||||
<Banner color="primary" className="flex flex-col gap-3">
|
<Banner color="primary" className="flex flex-col gap-3">
|
||||||
<p>
|
<p>
|
||||||
Showing responses over{' '}
|
Showing responses over{' '}
|
||||||
<InlineCode>
|
<InlineCode>
|
||||||
<SizeTag contentLength={tooLargeBytes} />
|
<SizeTag contentLength={LARGE_BYTES} />
|
||||||
</InlineCode>{' '}
|
</InlineCode>{' '}
|
||||||
may impact performance
|
may impact performance
|
||||||
</p>
|
</p>
|
||||||
@@ -49,7 +47,12 @@ export function ConfirmLargeResponse({ children, response }: Props) {
|
|||||||
Save to File
|
Save to File
|
||||||
</Button>
|
</Button>
|
||||||
{isProbablyText && (
|
{isProbablyText && (
|
||||||
<CopyButton color="secondary" variant="border" size="xs" text={() => getResponseBodyText(response)} />
|
<CopyButton
|
||||||
|
color="secondary"
|
||||||
|
variant="border"
|
||||||
|
size="xs"
|
||||||
|
text={() => getResponseBodyText(response)}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</HStack>
|
</HStack>
|
||||||
</Banner>
|
</Banner>
|
||||||
|
|||||||
Reference in New Issue
Block a user