This commit is contained in:
2026-01-09 11:56:40 +01:00
parent 1ee0afa088
commit 4ab192418e
30 changed files with 3455 additions and 16 deletions

76
web/src/lib/api.js Normal file
View File

@@ -0,0 +1,76 @@
const API_BASE = '/api';
async function request(endpoint, options = {}) {
try {
const response = await fetch(`${API_BASE}${endpoint}`, {
...options,
headers: {
'Content-Type': 'application/json',
...options.headers,
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('API request failed:', error);
throw error;
}
}
export const api = {
// Status
getStatus: () => request('/status'),
getConfig: () => request('/config'),
// WebSwitch
webswitch: {
relayOn: (relay) => request(`/webswitch/relay/on?relay=${relay}`, { method: 'POST' }),
relayOff: (relay) => request(`/webswitch/relay/off?relay=${relay}`, { method: 'POST' }),
allOn: () => request('/webswitch/all/on', { method: 'POST' }),
allOff: () => request('/webswitch/all/off', { method: 'POST' }),
},
// Rotator
rotator: {
move: (rotator, azimuth) => request('/rotator/move', {
method: 'POST',
body: JSON.stringify({ rotator, azimuth }),
}),
cw: (rotator) => request(`/rotator/cw?rotator=${rotator}`, { method: 'POST' }),
ccw: (rotator) => request(`/rotator/ccw?rotator=${rotator}`, { method: 'POST' }),
stop: () => request('/rotator/stop', { method: 'POST' }),
},
// Tuner
tuner: {
operate: (operate) => request('/tuner/operate', {
method: 'POST',
body: JSON.stringify({ operate }),
}),
tune: () => request('/tuner/tune', { method: 'POST' }),
antenna: (antenna) => request('/tuner/antenna', {
method: 'POST',
body: JSON.stringify({ antenna }),
}),
},
// Antenna Genius
antenna: {
set: (radio, antenna) => request('/antenna/set', {
method: 'POST',
body: JSON.stringify({ radio, antenna }),
}),
},
// Power Genius
power: {
setFanMode: (mode) => request('/power/fanmode', {
method: 'POST',
body: JSON.stringify({ mode }),
}),
},
};