mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-24 04:07:16 +00:00
Polish: Consistent API usage in SetupWizard
This commit is contained in:
@@ -2,6 +2,7 @@ import { Component, createSignal, createEffect, onCleanup, Show, For } from 'sol
|
||||
// Note: For is still used for connectedAgents list
|
||||
import { copyToClipboard } from '@/utils/clipboard';
|
||||
import { logger } from '@/utils/logger';
|
||||
import { apiFetchJSON } from '@/utils/apiClient';
|
||||
import { getPulseBaseUrl } from '@/utils/url';
|
||||
import { SecurityAPI } from '@/api/security';
|
||||
import { ProxmoxIcon } from '@/components/icons/ProxmoxIcon';
|
||||
@@ -37,17 +38,11 @@ export const CompleteStep: Component<CompleteStepProps> = (props) => {
|
||||
const checkForAgents = async () => {
|
||||
try {
|
||||
|
||||
const response = await fetch('/api/state', {
|
||||
const state = await apiFetchJSON<{ nodes: any[], hosts: any[] }>('/api/state', {
|
||||
headers: {
|
||||
'X-API-Token': props.state.apiToken,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
const state = await response.json();
|
||||
const nodes = state.nodes || [];
|
||||
const hosts = state.hosts || [];
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Component, createSignal, For, Show } from 'solid-js';
|
||||
import { showError, showSuccess } from '@/utils/toast';
|
||||
import { apiFetchJSON } from '@/utils/apiClient';
|
||||
import type { WizardState } from '../SetupWizard';
|
||||
|
||||
interface ConnectStepProps {
|
||||
@@ -77,10 +78,9 @@ export const ConnectStep: Component<ConnectStepProps> = (props) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/discover', {
|
||||
await apiFetchJSON('/api/discover', {
|
||||
method: 'POST',
|
||||
headers,
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ subnet: 'auto' }),
|
||||
});
|
||||
|
||||
@@ -89,18 +89,14 @@ export const ConnectStep: Component<ConnectStepProps> = (props) => {
|
||||
// Poll for results
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await new Promise(r => setTimeout(r, 2000));
|
||||
const results = await fetch('/api/discover/results', {
|
||||
const data = await apiFetchJSON<{ nodes: DiscoveredNode[] }>('/api/discover/results', {
|
||||
headers: props.state.apiToken ? { 'X-API-Token': props.state.apiToken } : {},
|
||||
credentials: 'include',
|
||||
});
|
||||
if (results.ok) {
|
||||
const data = await results.json();
|
||||
if (data.nodes && data.nodes.length > 0) {
|
||||
setDiscoveredNodes(data.nodes.filter((n: DiscoveredNode) =>
|
||||
selectedPlatform() === 'proxmox' ? ['pve', 'pbs', 'pmg'].includes(n.type) : true
|
||||
));
|
||||
break;
|
||||
}
|
||||
if (data.nodes && data.nodes.length > 0) {
|
||||
setDiscoveredNodes(data.nodes.filter((n: DiscoveredNode) =>
|
||||
selectedPlatform() === 'proxmox' ? ['pve', 'pbs', 'pmg'].includes(n.type) : true
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,15 +133,12 @@ export const ConnectStep: Component<ConnectStepProps> = (props) => {
|
||||
tokenValue: tokenSecret(),
|
||||
};
|
||||
|
||||
const response = await fetch('/api/nodes', {
|
||||
await apiFetchJSON('/api/nodes', {
|
||||
method: 'POST',
|
||||
headers,
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(nodeData),
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error(await response.text());
|
||||
|
||||
props.updateState({ nodeAdded: true, nodeName: nodeData.name });
|
||||
showSuccess(`Connected to ${nodeData.name}!`);
|
||||
props.onNext();
|
||||
|
||||
@@ -21,15 +21,12 @@ export const WelcomeStep: Component<WelcomeStepProps> = (props) => {
|
||||
// Fetch bootstrap info on mount
|
||||
const fetchBootstrapInfo = async () => {
|
||||
try {
|
||||
const response = await apiFetch('/api/security/status');
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data.bootstrapTokenPath) {
|
||||
setTokenPath(data.bootstrapTokenPath);
|
||||
setIsDocker(data.isDocker || false);
|
||||
setInContainer(data.inContainer || false);
|
||||
setLxcCtid(data.lxcCtid || '');
|
||||
}
|
||||
const data = await apiFetchJSON<{ bootstrapTokenPath?: string; isDocker?: boolean; inContainer?: boolean; lxcCtid?: string }>('/api/security/status');
|
||||
if (data?.bootstrapTokenPath) {
|
||||
setTokenPath(data.bootstrapTokenPath);
|
||||
setIsDocker(data.isDocker || false);
|
||||
setInContainer(data.inContainer || false);
|
||||
setLxcCtid(data.lxcCtid || '');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Failed to fetch bootstrap info:', error);
|
||||
|
||||
Reference in New Issue
Block a user