@@ -8,13 +8,14 @@ import {
88} from "solid-js" ;
99import { createStore } from "solid-js/store" ;
1010import { Portal } from "solid-js/web" ;
11- import { BODY_FORMAT_KEY , BodyFormat } from "../../server/server-functions-shared.ts" ;
11+ import { BODY_FORMAL_FILE , BODY_FORMAT_KEY , BodyFormat } from "../../server/server-functions-shared.ts" ;
1212import { Badge } from "../ui/Badge.tsx" ;
1313import Button from "../ui/Button.tsx" ;
1414import { Dialog , DialogOverlay , DialogPanel } from "../ui/Dialog.tsx" ;
1515import { Section } from "../ui/Section.tsx" ;
1616import { Select , SelectOption } from "../ui/Select.tsx" ;
1717import { Tab , TabGroup , TabList , TabPanel } from "../ui/Tabs.tsx" ;
18+ import { BlobViewer } from "./BlobViewer.tsx" ;
1819import { FormDataViewer } from "./FormDataViewer.tsx" ;
1920import { HeadersViewer } from "./HeadersViewer.tsx" ;
2021import { HexViewer } from "./HexViewer.tsx" ;
@@ -25,6 +26,21 @@ import {
2526 type ServerFunctionResponse ,
2627} from "./server-function-tracker.ts" ;
2728import "./styles.css" ;
29+ import { URLSearchParamsViewer } from "./URLSearchParamsViewer.tsx" ;
30+
31+ async function getFile ( source : Response | Request ) : Promise < File > {
32+ const formData = await source . formData ( ) ;
33+ const file = formData . get ( BODY_FORMAL_FILE ) ;
34+ if ( ! ( file && file instanceof File ) ) {
35+ throw new Error ( 'invalid file input' ) ;
36+ }
37+ return file ;
38+ }
39+
40+ async function getURLSearchParams ( source : Response | Request ) : Promise < URLSearchParams > {
41+ const text = await source . text ( ) ;
42+ return new URLSearchParams ( text ) ;
43+ }
2844
2945interface ContentViewerProps {
3046 source : ServerFunctionRequest | ServerFunctionResponse ;
@@ -46,20 +62,18 @@ function ContentViewer(props: ContentViewerProps): JSX.Element {
4662 case startType === BodyFormat . Seroval :
4763 return < SerovalViewer stream = { source } /> ;
4864 case startType === BodyFormat . String :
49- return undefined ;
50- case startType === BodyFormat . File : {
51- return undefined ;
52- }
65+ return < HexViewer bytes = { source . bytes ( ) } /> ;
66+ case startType === BodyFormat . File :
67+ return < BlobViewer source = { getFile ( source ) } /> ;
5368 case startType === BodyFormat . FormData :
5469 case contentType ?. startsWith ( "multipart/form-data" ) :
5570 return < FormDataViewer source = { source . formData ( ) } /> ;
5671 case startType === BodyFormat . URLSearchParams :
5772 case contentType ?. startsWith ( "application/x-www-form-urlencoded" ) :
58- return undefined ;
73+ return < URLSearchParamsViewer source = { getURLSearchParams ( source ) } /> ;
5974 case startType === BodyFormat . Blob :
60- return undefined ;
75+ return < BlobViewer source = { source . blob ( ) } /> ;
6176 case startType === BodyFormat . ArrayBuffer :
62- return undefined ;
6377 case startType === BodyFormat . Uint8Array :
6478 return < HexViewer bytes = { source . bytes ( ) } /> ;
6579 }
0 commit comments