Загрузить файлы в «/»

This commit is contained in:
2026-07-02 20:28:27 +00:00
parent 33607bae6e
commit b83e07325d
5 changed files with 915 additions and 0 deletions

25
api.js Normal file
View File

@@ -0,0 +1,25 @@
const API = {
async request(path, options = {}) {
const res = await fetch(path, {
credentials: 'include',
headers: { 'Content-Type': 'application/json', ...options.headers },
...options,
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
const detail = data.detail;
const msg = Array.isArray(detail)
? detail.map((d) => d.msg).join(', ')
: detail || 'Ошибка запроса';
throw new Error(msg);
}
return data;
},
me: () => API.request('/api/auth/me'),
logout: () => API.request('/api/auth/logout', { method: 'POST' }),
getProfile: () => API.request('/api/profile'),
updateProfile: (body) => API.request('/api/profile', { method: 'PUT', body: JSON.stringify(body) }),
getRobots: () => API.request('/api/robots'),
saveRobots: (body) => API.request('/api/robots', { method: 'PUT', body: JSON.stringify(body) }),
getSessions: () => API.request('/api/sessions'),
};