Primeiro commit

This commit is contained in:
root
2025-06-06 08:46:00 +01:00
commit cf2ac9caca
35 changed files with 4954 additions and 0 deletions

50
src/api.js Executable file
View File

@@ -0,0 +1,50 @@
const API_BASE = ''; // Ex: http://192.168.4.1 ou leave empty for relative
let credentials = '';
export function setCredentials(user, pass) {
credentials = btoa(`${user}:${pass}`);
}
function getHeaders(isJson = true) {
const headers = {
Authorization: `Basic ${credentials}`,
};
if (isJson) headers['Content-Type'] = 'application/json';
return headers;
}
export async function get(path) {
const res = await fetch(`${API_BASE}${path}`, {
headers: getHeaders(false),
});
if (!res.ok) throw new Error(`GET ${path} failed`);
return await res.json();
}
export async function post(path, body) {
const res = await fetch(`${API_BASE}${path}`, {
method: 'POST',
headers: getHeaders(),
body: JSON.stringify(body),
});
if (!res.ok) throw new Error(`POST ${path} failed`);
return await res.text();
}
export async function postPlain(path) {
const res = await fetch(`${API_BASE}${path}`, {
method: 'POST',
headers: getHeaders(false),
});
if (!res.ok) throw new Error(`POST ${path} failed`);
return await res.text();
}
export async function fetchLogs(index = 0) {
const res = await fetch(`${API_BASE}/api/v1/log?index=${index}`, {
headers: getHeaders(false),
});
if (!res.ok) throw new Error('Failed to fetch logs');
return await res.text();
}