feat: добавлены компоненты для управления конфигурацией и логами

Добавлены новые компоненты для отображения и управления конфигурацией, логами и правилами маршрутизации. Реализована логика для работы с API, включая запросы на получение и сохранение данных. Также добавлены шаблоны правил и утилиты для валидации.

Refs: None
This commit is contained in:
2026-05-08 18:23:29 +03:00
parent 7d41dd86e7
commit 8789496ae6
24 changed files with 2987 additions and 364 deletions

33
src/web/api.js Normal file
View File

@@ -0,0 +1,33 @@
async function request(url, options = {}) {
const response = await fetch(url, {
...options,
headers: {
'content-type': 'application/json',
...(options.headers || {}),
},
});
const data = await response.json().catch(() => ({}));
if (!response.ok || (data && data.success === false)) {
throw new Error(data?.error || `Запрос ${url} завершился ошибкой ${response.status}`);
}
return data;
}
export const api = {
state: () => request('/api/state'),
config: () => request('/api/config'),
rules: {
get: () => request('/api/rules'),
save: (rules) => request('/api/rules', { method: 'PUT', body: JSON.stringify({ rules }) }),
},
subscription: {
fetch: (url) => request('/api/subscription/fetch', { method: 'POST', body: JSON.stringify({ url }) }),
forget: () => request('/api/subscription', { method: 'DELETE' }),
},
apply: (selectedTag) => request('/api/apply', { method: 'POST', body: JSON.stringify({ selectedTag }) }),
singbox: {
stop: () => request('/api/singbox/stop', { method: 'POST' }),
restart: () => request('/api/singbox/restart', { method: 'POST' }),
clear: () => request('/api/singbox/clear', { method: 'POST' }),
},
};