feat!(web): migrate UI from SvelteKit to React + shadcn/ui + ReUI
CI / changes (push) Successful in 17s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 26s
CI / web (push) Successful in 46s
CI / go (push) Successful in 1m1s
CI / bird2 (push) Successful in 17s
CI / release (push) Failing after 2m22s
CI / changes (push) Successful in 17s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 26s
CI / web (push) Successful in 46s
CI / go (push) Successful in 1m1s
CI / bird2 (push) Successful in 17s
CI / release (push) Failing after 2m22s
Web UI полностью переведён с SvelteKit на новый стек: React 19, TanStack Router/Query/Table/Virtual, shadcn/ui (base-nova) и ReUI enterprise-компоненты (data-grid, filters, autocomplete). Новый код разложен по слоям: packages/ui (shadcn-примитивы), apps/web (роуты, shared-обёртки, ReUI-адаптации). BREAKING CHANGE: меняется структура и инструментинг фронтенда. - apps/web/ — новый Vite + React-проект (@evobgp/web), file-based роуты TanStack Router; экраны dashboard, modules, monitoring, network, operations, schedule, settings, tenant-settings, access, directories. - packages/ui/ — shadcn/ui-примитивы (@evobgp/ui) с общими стилями globals.css и cn-утилитой; CLI shadcn запускается из apps/web. - apps/web/src/components/reui/ — enterprise-паттерны ReUI. - pnpm workspace (pnpm-workspace.yaml, pnpm-lock.yaml, tsconfig.base.json) заменяет npm-проект в web/. - web/ переименован в web-legacy-svelte/ (архив-референс для миграции); импорты оттуда запрещены правилом WEB-22. - CI (.gitea/workflows/ci.yaml): job web переведён на Node 22 + pnpm 10 (typecheck/lint/build через pnpm --filter @evobgp/web); пути триггеров обновлены под apps/web|packages/ui. - deploy/docker/evobgp-web/Dockerfile: сборка из корня репозитория, pnpm install --frozen-lockfile, выход dist из apps/web/dist. - .cursor/rules/web-shadcn.mdc, context7-stack.mdc, engineering.mdc, AGENTS.md — обновлены под React-стек (WEB-01..WEB-22, DOC-SYNC-06/07). Проверки WEB-19 локально: typecheck, lint, build — exit 0. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { apiJSON } from '@/lib/api-client'
|
||||
import type { ApiKey, ApiKeysResponse } from '@/types/api'
|
||||
|
||||
export const apiKeysKeys = {
|
||||
all: ['api-keys'] as const,
|
||||
list: () => [...apiKeysKeys.all, 'list'] as const,
|
||||
}
|
||||
|
||||
export function apiKeysQueryOptions() {
|
||||
return queryOptions<ApiKey[]>({
|
||||
queryKey: apiKeysKeys.list(),
|
||||
queryFn: async () => {
|
||||
const page = await apiJSON<ApiKeysResponse>('/v1/api-keys?limit=500')
|
||||
return page.items ?? []
|
||||
},
|
||||
staleTime: 60_000,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { apiJSON } from '@/lib/api-client'
|
||||
import type { AuthSession } from '@/types/api'
|
||||
|
||||
export const authKeys = {
|
||||
all: ['auth'] as const,
|
||||
session: () => [...authKeys.all, 'session'] as const,
|
||||
}
|
||||
|
||||
export function authSessionQueryOptions() {
|
||||
return queryOptions<AuthSession>({
|
||||
queryKey: authKeys.session(),
|
||||
queryFn: () => apiJSON<AuthSession>('/v1/auth/session'),
|
||||
retry: false,
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { apiJSON } from '@/lib/api-client'
|
||||
import type { CommunitiesResponse, DohProfilesResponse } from '@/types/api'
|
||||
|
||||
export const directoriesKeys = {
|
||||
all: ['directories'] as const,
|
||||
communities: () => [...directoriesKeys.all, 'communities'] as const,
|
||||
doh: () => [...directoriesKeys.all, 'doh'] as const,
|
||||
}
|
||||
|
||||
export function directoriesCommunitiesQueryOptions() {
|
||||
return queryOptions<CommunitiesResponse>({
|
||||
queryKey: directoriesKeys.communities(),
|
||||
queryFn: () => apiJSON<CommunitiesResponse>('/v1/communities?limit=200'),
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function directoriesDohQueryOptions() {
|
||||
return queryOptions<DohProfilesResponse>({
|
||||
queryKey: directoriesKeys.doh(),
|
||||
queryFn: () => apiJSON<DohProfilesResponse>('/v1/doh-profiles?limit=200'),
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { apiJSON } from '@/lib/api-client'
|
||||
import type {
|
||||
ModuleRow,
|
||||
ModulesResponse,
|
||||
Page,
|
||||
} from '@/types/api'
|
||||
|
||||
export const modulesKeys = {
|
||||
all: ['modules'] as const,
|
||||
list: () => [...modulesKeys.all, 'list'] as const,
|
||||
detail: (id: string) => [...modulesKeys.all, 'detail', id] as const,
|
||||
domainEntries: (id: string) => [...modulesKeys.all, 'domain-entries', id] as const,
|
||||
asEntries: (id: string) => [...modulesKeys.all, 'as-entries', id] as const,
|
||||
cdnSources: (id: string) => [...modulesKeys.all, 'cdn-sources', id] as const,
|
||||
ipRangeEntries: (id: string) => [...modulesKeys.all, 'ip-range-entries', id] as const,
|
||||
}
|
||||
|
||||
export function modulesListQueryOptions() {
|
||||
return queryOptions<ModulesResponse>({
|
||||
queryKey: modulesKeys.list(),
|
||||
queryFn: () => apiJSON<ModulesResponse>('/v1/modules?limit=200'),
|
||||
})
|
||||
}
|
||||
|
||||
export function moduleDetailQueryOptions(id: string) {
|
||||
return queryOptions<ModuleRow>({
|
||||
queryKey: modulesKeys.detail(id),
|
||||
queryFn: () => apiJSON<ModuleRow>(`/v1/modules/${id}`),
|
||||
})
|
||||
}
|
||||
|
||||
export type ModuleEntriesPage = Page<Record<string, unknown>>
|
||||
|
||||
export function moduleEntriesQueryOptions(id: string, type: ModuleRow['type']) {
|
||||
const pathByType: Record<ModuleRow['type'], string> = {
|
||||
DOMAINS: `/v1/modules/${id}/domain-entries?limit=500`,
|
||||
AS_PREFIXES: `/v1/modules/${id}/as-entries?limit=500`,
|
||||
CDN_CIDRS: `/v1/modules/${id}/cdn-sources?limit=500`,
|
||||
IP_RANGES: `/v1/modules/${id}/ip-range-entries?limit=500`,
|
||||
}
|
||||
const path = pathByType[type]
|
||||
const keyByType: Record<ModuleRow['type'], readonly string[]> = {
|
||||
DOMAINS: modulesKeys.domainEntries(id),
|
||||
AS_PREFIXES: modulesKeys.asEntries(id),
|
||||
CDN_CIDRS: modulesKeys.cdnSources(id),
|
||||
IP_RANGES: modulesKeys.ipRangeEntries(id),
|
||||
}
|
||||
return queryOptions<ModuleEntriesPage>({
|
||||
queryKey: keyByType[type],
|
||||
queryFn: () => apiJSON<ModuleEntriesPage>(path),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { apiFetch, apiJSON, apiMutate } from '@/lib/api-client'
|
||||
|
||||
export interface HealthStatus {
|
||||
ok: boolean
|
||||
status?: string
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface ReadyStatus {
|
||||
status?: string
|
||||
checks?: Record<string, boolean | { ok?: boolean; error?: string }>
|
||||
}
|
||||
|
||||
export interface VersionInfo {
|
||||
version?: string
|
||||
app?: string
|
||||
git_sha?: string
|
||||
build_time?: string
|
||||
}
|
||||
|
||||
export const monitoringKeys = {
|
||||
all: ['monitoring'] as const,
|
||||
health: () => [...monitoringKeys.all, 'health'] as const,
|
||||
ready: () => [...monitoringKeys.all, 'ready'] as const,
|
||||
version: () => [...monitoringKeys.all, 'version'] as const,
|
||||
}
|
||||
|
||||
async function fetchHealth(): Promise<HealthStatus> {
|
||||
const res = await apiFetch('/v1/health', { method: 'GET' })
|
||||
let body: { status?: string } = {}
|
||||
try {
|
||||
body = (await res.json()) as { status?: string }
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
return { ok: res.ok, status: body.status, error: res.ok ? undefined : `HTTP ${res.status}` }
|
||||
}
|
||||
|
||||
export function monitoringHealthQueryOptions() {
|
||||
return queryOptions<HealthStatus>({
|
||||
queryKey: monitoringKeys.health(),
|
||||
queryFn: fetchHealth,
|
||||
staleTime: 15_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function monitoringReadyQueryOptions() {
|
||||
return queryOptions<ReadyStatus>({
|
||||
queryKey: monitoringKeys.ready(),
|
||||
queryFn: () => apiJSON<ReadyStatus>('/v1/ready'),
|
||||
staleTime: 15_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function monitoringVersionQueryOptions() {
|
||||
return queryOptions<VersionInfo>({
|
||||
queryKey: monitoringKeys.version(),
|
||||
queryFn: () => apiJSON<VersionInfo>('/v1/version'),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
}
|
||||
|
||||
export async function fetchLog(endpoint: string): Promise<string> {
|
||||
const res = await apiFetch(endpoint, { method: 'GET' })
|
||||
return await res.text()
|
||||
}
|
||||
|
||||
export async function clearLog(endpoint: string): Promise<void> {
|
||||
await apiMutate(endpoint, 'DELETE', {})
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { apiJSON } from '@/lib/api-client'
|
||||
import type { BirdStatus, PeersResponse, SpeakersResponse } from '@/types/api'
|
||||
|
||||
export const NETWORK_AUTO_REFRESH_MS = 30_000
|
||||
|
||||
export const networkKeys = {
|
||||
all: ['network'] as const,
|
||||
peers: () => [...networkKeys.all, 'peers'] as const,
|
||||
speakers: () => [...networkKeys.all, 'speakers'] as const,
|
||||
bird: () => [...networkKeys.all, 'bird'] as const,
|
||||
}
|
||||
|
||||
export function networkPeersQueryOptions() {
|
||||
return queryOptions<PeersResponse>({
|
||||
queryKey: networkKeys.peers(),
|
||||
queryFn: () => apiJSON<PeersResponse>('/v1/peers?limit=200&live=1'),
|
||||
staleTime: 15_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function networkSpeakersQueryOptions() {
|
||||
return queryOptions<SpeakersResponse>({
|
||||
queryKey: networkKeys.speakers(),
|
||||
queryFn: () => apiJSON<SpeakersResponse>('/v1/speakers?limit=200&live=1'),
|
||||
staleTime: 15_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function networkBirdQueryOptions() {
|
||||
return queryOptions<BirdStatus>({
|
||||
queryKey: networkKeys.bird(),
|
||||
queryFn: () => apiJSON<BirdStatus>('/v1/bird/status'),
|
||||
staleTime: 15_000,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { apiJSON } from '@/lib/api-client'
|
||||
import type { JobsResponse, RevisionsResponse, RevisionDiff } from '@/types/api'
|
||||
|
||||
export const operationsKeys = {
|
||||
all: ['operations'] as const,
|
||||
revisions: () => [...operationsKeys.all, 'revisions'] as const,
|
||||
jobs: (params?: { status?: string; kind?: string }) =>
|
||||
[...operationsKeys.all, 'jobs', params ?? {}] as const,
|
||||
diff: (a: string, b: string) => [...operationsKeys.all, 'diff', a, b] as const,
|
||||
}
|
||||
|
||||
export function operationsRevisionsQueryOptions() {
|
||||
return queryOptions<RevisionsResponse>({
|
||||
queryKey: operationsKeys.revisions(),
|
||||
queryFn: () => apiJSON<RevisionsResponse>('/v1/revisions?limit=100'),
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function operationsJobsQueryOptions(params?: { status?: string; kind?: string }) {
|
||||
return queryOptions<JobsResponse>({
|
||||
queryKey: operationsKeys.jobs(params),
|
||||
queryFn: () => {
|
||||
const sp = new URLSearchParams({ limit: '200' })
|
||||
if (params?.status) sp.set('status', params.status)
|
||||
if (params?.kind) sp.set('kind', params.kind)
|
||||
return apiJSON<JobsResponse>(`/v1/jobs?${sp.toString()}`)
|
||||
},
|
||||
staleTime: 10_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function operationsDiffQueryOptions(a: string, b: string) {
|
||||
return queryOptions<RevisionDiff>({
|
||||
queryKey: operationsKeys.diff(a, b),
|
||||
queryFn: () => apiJSON<RevisionDiff>(`/v1/revisions/${a}/diff/${b}`),
|
||||
enabled: Boolean(a) && Boolean(b),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { apiJSON } from '@/lib/api-client'
|
||||
import type {
|
||||
JobRow,
|
||||
JobsResponse,
|
||||
ModuleRow,
|
||||
ModulesResponse,
|
||||
PeerRow,
|
||||
PeersResponse,
|
||||
RevisionRow,
|
||||
RevisionsResponse,
|
||||
SpeakerRow,
|
||||
SpeakersResponse,
|
||||
} from '@/types/api'
|
||||
|
||||
export const overviewKeys = {
|
||||
all: ['overview'] as const,
|
||||
modules: () => [...overviewKeys.all, 'modules'] as const,
|
||||
peers: () => [...overviewKeys.all, 'peers'] as const,
|
||||
speakers: () => [...overviewKeys.all, 'speakers'] as const,
|
||||
revisions: () => [...overviewKeys.all, 'revisions'] as const,
|
||||
jobs: () => [...overviewKeys.all, 'jobs'] as const,
|
||||
health: () => [...overviewKeys.all, 'health'] as const,
|
||||
}
|
||||
|
||||
export function overviewModulesQueryOptions() {
|
||||
return queryOptions<ModulesResponse>({
|
||||
queryKey: overviewKeys.modules(),
|
||||
queryFn: () => apiJSON<ModulesResponse>('/v1/modules?limit=200'),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function overviewPeersQueryOptions() {
|
||||
return queryOptions<PeersResponse>({
|
||||
queryKey: overviewKeys.peers(),
|
||||
queryFn: () => apiJSON<PeersResponse>('/v1/peers?limit=200&live=1'),
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function overviewSpeakersQueryOptions() {
|
||||
return queryOptions<SpeakersResponse>({
|
||||
queryKey: overviewKeys.speakers(),
|
||||
queryFn: () => apiJSON<SpeakersResponse>('/v1/speakers?limit=200&live=1'),
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function overviewRevisionsQueryOptions() {
|
||||
return queryOptions<RevisionsResponse>({
|
||||
queryKey: overviewKeys.revisions(),
|
||||
queryFn: () => apiJSON<RevisionsResponse>('/v1/revisions?limit=10'),
|
||||
staleTime: 60_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function overviewJobsQueryOptions() {
|
||||
return queryOptions<JobsResponse>({
|
||||
queryKey: overviewKeys.jobs(),
|
||||
queryFn: () => apiJSON<JobsResponse>('/v1/jobs?limit=10'),
|
||||
staleTime: 15_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function overviewHealthQueryOptions() {
|
||||
return queryOptions<boolean>({
|
||||
queryKey: overviewKeys.health(),
|
||||
queryFn: async () => {
|
||||
const res = await fetch('/v1/health')
|
||||
return res.ok
|
||||
},
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
|
||||
// Selectors / helpers
|
||||
export type NetworkMetrics = {
|
||||
peersTotal: number
|
||||
peersEnabled: number
|
||||
peersEstablished: number
|
||||
peersMismatch: number
|
||||
speakersTotal: number
|
||||
speakersOnline: number
|
||||
}
|
||||
|
||||
export function aggregateNetworkMetrics(
|
||||
peers: PeerRow[],
|
||||
speakers: SpeakerRow[],
|
||||
): NetworkMetrics {
|
||||
const peersEnabled = peers.filter((p) => p.enabled !== false).length
|
||||
const peersEstablished = peers.filter((p) => p.session_state === 'Established').length
|
||||
const peersMismatch = peers.filter((p) => p.session_mismatch).length
|
||||
const speakersOnline = speakers.filter((s) => s.live?.agent_ok).length
|
||||
return {
|
||||
peersTotal: peers.length,
|
||||
peersEnabled,
|
||||
peersEstablished,
|
||||
peersMismatch,
|
||||
speakersTotal: speakers.length,
|
||||
speakersOnline,
|
||||
}
|
||||
}
|
||||
|
||||
export function runningJobCount(jobs: JobRow[]): number {
|
||||
return jobs.filter((j) => j.status === 'running' || j.status === 'queued').length
|
||||
}
|
||||
|
||||
export function moduleNameById(modules: ModuleRow[]): Map<string, string> {
|
||||
return new Map(modules.map((m) => [m.id, m.name]))
|
||||
}
|
||||
|
||||
export function recentRevisions(revisions: RevisionRow[], n = 10): RevisionRow[] {
|
||||
return revisions.slice(0, n)
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { apiJSON } from '@/lib/api-client'
|
||||
|
||||
export type AppSettings = Record<string, unknown>
|
||||
|
||||
export const BIRD_SETTING_KEYS = [
|
||||
'bird_router_id',
|
||||
'bird_local_ipv4',
|
||||
'bird_local_ipv6',
|
||||
'bird_local_asn',
|
||||
'bird_bgp_source_ipv4',
|
||||
'bird_bgp_source_ipv6',
|
||||
] as const
|
||||
|
||||
export const REVISION_SETTING_KEYS = ['revision_retention_minutes'] as const
|
||||
|
||||
export const RUNTIME_LOGS_SETTING_KEYS = [
|
||||
'runtime_logs_auto_enabled',
|
||||
'runtime_logs_max_file_mb',
|
||||
'runtime_logs_auto_schedule',
|
||||
'runtime_logs_auto_mode',
|
||||
] as const
|
||||
|
||||
export const KNOWN_SETTING_KEYS = [
|
||||
...BIRD_SETTING_KEYS,
|
||||
...REVISION_SETTING_KEYS,
|
||||
...RUNTIME_LOGS_SETTING_KEYS,
|
||||
] as const
|
||||
|
||||
export type KnownSettingKey = (typeof KNOWN_SETTING_KEYS)[number]
|
||||
export type BirdSettingKey = (typeof BIRD_SETTING_KEYS)[number]
|
||||
export type RevisionSettingKey = (typeof REVISION_SETTING_KEYS)[number]
|
||||
export type RuntimeLogsSettingKey = (typeof RUNTIME_LOGS_SETTING_KEYS)[number]
|
||||
|
||||
export const NUMERIC_SETTING_KEYS = new Set<KnownSettingKey>([
|
||||
'bird_local_asn',
|
||||
'revision_retention_minutes',
|
||||
'runtime_logs_max_file_mb',
|
||||
])
|
||||
|
||||
export const BOOLEAN_SETTING_KEYS = new Set<KnownSettingKey>(['runtime_logs_auto_enabled'])
|
||||
|
||||
export const settingsKeys = {
|
||||
all: ['settings'] as const,
|
||||
}
|
||||
|
||||
export function settingsQueryOptions() {
|
||||
return queryOptions<AppSettings>({
|
||||
queryKey: settingsKeys.all,
|
||||
queryFn: () => apiJSON<AppSettings>('/v1/settings'),
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function parseKnownValue(key: KnownSettingKey, value: unknown): string {
|
||||
if (NUMERIC_SETTING_KEYS.has(key)) {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) return String(value)
|
||||
if (typeof value === 'string') return value
|
||||
return ''
|
||||
}
|
||||
if (typeof value === 'string') return value
|
||||
return ''
|
||||
}
|
||||
|
||||
export interface PartitionedSettings {
|
||||
bird: Partial<Record<BirdSettingKey, string>>
|
||||
revision: Partial<Record<RevisionSettingKey, string>>
|
||||
runtimeLogs: Partial<Record<RuntimeLogsSettingKey, string>>
|
||||
additional: { id: number; key: string; value: string }[]
|
||||
}
|
||||
|
||||
export function partitionSettings(settings: AppSettings): PartitionedSettings {
|
||||
const bird: Partial<Record<BirdSettingKey, string>> = {}
|
||||
const revision: Partial<Record<RevisionSettingKey, string>> = {}
|
||||
const runtimeLogs: Partial<Record<RuntimeLogsSettingKey, string>> = {}
|
||||
const additional: { id: number; key: string; value: string }[] = []
|
||||
let id = 1
|
||||
|
||||
for (const [key, value] of Object.entries(settings)) {
|
||||
if ((BIRD_SETTING_KEYS as readonly string[]).includes(key)) {
|
||||
bird[key as BirdSettingKey] = parseKnownValue(key as KnownSettingKey, value)
|
||||
} else if (key === 'revision_retention_minutes') {
|
||||
revision.revision_retention_minutes = parseKnownValue(
|
||||
key as RevisionSettingKey,
|
||||
value,
|
||||
)
|
||||
} else if ((RUNTIME_LOGS_SETTING_KEYS as readonly string[]).includes(key)) {
|
||||
const rk = key as RuntimeLogsSettingKey
|
||||
if (rk === 'runtime_logs_auto_enabled') {
|
||||
runtimeLogs.runtime_logs_auto_enabled =
|
||||
value === true || value === 1 || value === 'true' || value === '1'
|
||||
? 'true'
|
||||
: 'false'
|
||||
} else if (rk === 'runtime_logs_auto_mode') {
|
||||
const m = String(value ?? '').trim()
|
||||
runtimeLogs.runtime_logs_auto_mode = m === 'delete' ? 'delete' : m === 'truncate' ? 'truncate' : ''
|
||||
} else {
|
||||
runtimeLogs[rk] = parseKnownValue(rk, value)
|
||||
}
|
||||
} else {
|
||||
additional.push({
|
||||
id: id++,
|
||||
key,
|
||||
value: typeof value === 'string' ? value : String(value),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return { bird, revision, runtimeLogs, additional }
|
||||
}
|
||||
|
||||
export function buildPayload(
|
||||
keys: readonly KnownSettingKey[],
|
||||
form: Record<string, string>,
|
||||
): Record<string, string | number | boolean> {
|
||||
const payload: Record<string, string | number | boolean> = {}
|
||||
for (const key of keys) {
|
||||
const value = String(form[key] ?? '').trim()
|
||||
if (BOOLEAN_SETTING_KEYS.has(key)) {
|
||||
payload[key] = value === 'true'
|
||||
continue
|
||||
}
|
||||
if (!value) continue
|
||||
if (NUMERIC_SETTING_KEYS.has(key)) payload[key] = Number(value)
|
||||
else payload[key] = value
|
||||
}
|
||||
return payload
|
||||
}
|
||||
Reference in New Issue
Block a user