создание, правка, удаление, скрытие инструмента

This commit is contained in:
2025-12-12 23:50:38 +03:00
parent 8b38d69980
commit f85ca7d002
19 changed files with 1607 additions and 162 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

+16 -3
View File
@@ -1,14 +1,27 @@
// api.js
export async function apiRequest(url, payload = {}, method = 'POST') {
const res = await fetch(url, {
method = method.toUpperCase();
let finalUrl = url;
let options = {
method,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(payload),
credentials: 'same-origin'
});
};
// --- Если GET → добавляем payload в URL ---
if (method === 'GET') {
const params = new URLSearchParams(payload);
finalUrl = `${url}?${params.toString()}`;
} else {
// --- Для остальных методов → отправляем body ---
options.body = JSON.stringify(payload);
}
const res = await fetch(finalUrl, options);
if (!res.ok) {
const text = await res.text();
+17 -7
View File
@@ -23,16 +23,26 @@ export async function setCookie(name, value, days = 180) {
}
}
const secure = true; // TODO включить после тестов
const sameSite = 'Lax';
const expires = new Date(Date.now() + days * 864e5).toUTCString();
const encodedName = encodeURIComponent(name);
let cookie = `${encodeURIComponent(name)}=${cookieValue}; expires=${expires}; path=/`;
if (secure) cookie += '; Secure';
if (sameSite) cookie += `; SameSite=${sameSite}`;
// ---------- 1. Пытаемся установить безопасную куку ----------
let secureCookie = `${encodedName}=${cookieValue}; expires=${expires}; path=/; Secure; SameSite=Lax`;
document.cookie = secureCookie;
document.cookie = cookie;
// ---------- 2. Проверяем, записалась ли она ----------
const isSet = document.cookie.split('; ')
.some(c => c.startsWith(`${encodedName}=`));
if (isSet) {
return true; // безопасная кука успешно установлена
}
// ---------- 3. Фолбэк: ставим обычную (без Secure) ----------
let normalCookie = `${encodedName}=${cookieValue}; expires=${expires}; path=/; SameSite=Lax`;
document.cookie = normalCookie;
return false; // безопасную куку установить не удалось
}
export async function getCookie(name) {
+1373 -95
View File
File diff suppressed because it is too large Load Diff