CI / go-test (push) Canceled after 0s
CI / postgres-durable-first (push) Canceled after 0s
CI / codegen (push) Canceled after 0s
CI / govulncheck (push) Canceled after 0s
CI / race (push) Canceled after 0s
CI / fuzz-smoke (push) Canceled after 0s
CI / golangci (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CodeQL Advanced / Analyze (go) (push) Canceled after 0s
CodeQL Advanced / Analyze (actions) (push) Canceled after 0s
CodeQL Advanced / Analyze (javascript-typescript) (push) Canceled after 0s
Docs CI / build (push) Canceled after 0s
Docs Deploy (GitHub Pages) / build (push) Canceled after 0s
Release 3X-UI / build (386) (push) Canceled after 0s
Release 3X-UI / build (amd64) (push) Canceled after 0s
Release 3X-UI / build (arm64) (push) Canceled after 0s
Release 3X-UI / build (armv5) (push) Canceled after 0s
Release 3X-UI / build (armv6) (push) Canceled after 0s
Release 3X-UI / build (armv7) (push) Canceled after 0s
Release 3X-UI / build (s390x) (push) Canceled after 0s
Release 3X-UI / Build for Windows (amd64) (push) Canceled after 0s
Deploy Smoke Tests / noninteractive-install (ubuntu-24.04-arm) (push) Canceled after 0s
Deploy Smoke Tests / noninteractive-install (ubuntu-latest) (push) Canceled after 0s
Deploy Smoke Tests / release-tag-install (ubuntu-24.04-arm) (push) Canceled after 0s
Deploy Smoke Tests / release-tag-install (ubuntu-latest) (push) Canceled after 0s
Docs Deploy (GitHub Pages) / deploy (push) Canceled after 0s
Release 3X-UI / Publish rolling dev release (push) Canceled after 0s
82 lines
2.7 KiB
TypeScript
82 lines
2.7 KiB
TypeScript
'use client';
|
|
|
|
import { useId, useState } from 'react';
|
|
import {
|
|
buildCurl,
|
|
buildFetchSnippet,
|
|
type ApiRequestInput,
|
|
type HttpMethod,
|
|
} from '@/lib/xray/api-client';
|
|
import { ToolFrame } from './tool-frame';
|
|
import { TextField, SelectField } from './shared/fields';
|
|
import { OutputBlock } from './shared/output-block';
|
|
|
|
const METHODS: readonly HttpMethod[] = ['GET', 'POST', 'PUT', 'DELETE'];
|
|
|
|
export function ApiRequestBuilder() {
|
|
const [baseUrl, setBaseUrl] = useState('https://panel.example.com:2053');
|
|
const [token, setToken] = useState('');
|
|
const [path, setPath] = useState('/panel/api/inbounds/list');
|
|
const [method, setMethod] = useState<HttpMethod>('GET');
|
|
const [body, setBody] = useState('');
|
|
const bodyId = useId();
|
|
|
|
const showBody = method === 'POST' || method === 'PUT';
|
|
const input: ApiRequestInput = { baseUrl, token: token || '<token>', path, method, body };
|
|
|
|
function reset() {
|
|
setBaseUrl('https://panel.example.com:2053');
|
|
setToken('');
|
|
setPath('/panel/api/inbounds/list');
|
|
setMethod('GET');
|
|
setBody('');
|
|
}
|
|
|
|
return (
|
|
<ToolFrame
|
|
title="API request builder"
|
|
description="Build an authenticated cURL command or fetch() snippet for any 3x-ui panel API endpoint under /panel/api/*."
|
|
onReset={reset}
|
|
>
|
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
|
<TextField label="Panel base URL" value={baseUrl} onChange={setBaseUrl} />
|
|
<TextField
|
|
label="API token (Bearer)"
|
|
value={token}
|
|
onChange={setToken}
|
|
placeholder="Settings → Security → API Token"
|
|
/>
|
|
<TextField label="Endpoint path" value={path} onChange={setPath} />
|
|
<SelectField
|
|
label="Method"
|
|
value={method}
|
|
onChange={(v) => setMethod(v as HttpMethod)}
|
|
options={METHODS}
|
|
/>
|
|
</div>
|
|
|
|
{showBody ? (
|
|
<div className="mt-4 flex flex-col gap-1.5">
|
|
<label htmlFor={bodyId} className="text-sm font-medium">
|
|
Request body (JSON)
|
|
</label>
|
|
<textarea
|
|
id={bodyId}
|
|
dir="ltr"
|
|
value={body}
|
|
onChange={(e) => setBody(e.target.value)}
|
|
rows={4}
|
|
placeholder='{"id": 1}'
|
|
className="rounded-lg border bg-fd-background px-3 py-2 font-mono text-sm outline-none transition-colors focus-visible:border-fd-primary focus-visible:ring-2 focus-visible:ring-fd-ring/30"
|
|
/>
|
|
</div>
|
|
) : null}
|
|
|
|
<div className="mt-4 grid grid-cols-1 gap-4">
|
|
<OutputBlock label="cURL" value={buildCurl(input)} />
|
|
<OutputBlock label="fetch()" value={buildFetchSnippet(input)} />
|
|
</div>
|
|
</ToolFrame>
|
|
);
|
|
}
|