feat: добавить веб-интерфейс админ-панели для управления модпаками
All checks were successful
CI / lint (push) Successful in 1m1s
CI / test (push) Successful in 42s
CI / build (push) Successful in 18s
CI / docker (push) Successful in 1m16s

This commit is contained in:
2026-06-07 19:06:27 +03:00
parent f765fecf24
commit b9e986d25a
4 changed files with 352 additions and 17 deletions

View File

@@ -357,24 +357,63 @@
const username = localStorage.getItem('username');
const nav = document.getElementById('mainNav');
if (token && username) {
nav.innerHTML =
'<a href="/" id="nav-home">Главная</a>' +
'<a href="/profile" id="nav-profile">Профиль</a>' +
'<div class="nav-user"><div class="avatar"></div>' + escapeHtml(username) + '</div>' +
'<a href="#" id="nav-logout" class="btn btn-sm btn-danger" style="padding:0.35rem 0.75rem">Выйти</a>';
document.getElementById('nav-logout').addEventListener('click', function(e) {
e.preventDefault();
localStorage.removeItem('token');
localStorage.removeItem('uuid');
localStorage.removeItem('username');
window.location.href = '/';
// Fetch user info to check role
fetch('/api/web/me', {
headers: {'Authorization': 'Bearer ' + token}
})
.then(response => {
if (!response.ok) throw new Error('Not authenticated');
return response.json();
})
.then(data => {
let adminLink = '';
if (data.role === 'admin') {
adminLink = '<a href="/admin" id="nav-admin" class="btn btn-sm" style="background:var(--warning);color:#000">Админ-панель</a>';
}
nav.innerHTML =
'<a href="/" id="nav-home">Главная</a>' +
'<a href="/profile" id="nav-profile">Профиль</a>' +
adminLink +
'<div class="nav-user"><div class="avatar"></div>' + escapeHtml(username) + '</div>' +
'<a href="#" id="nav-logout" class="btn btn-sm btn-danger" style="padding:0.35rem 0.75rem">Выйти</a>';
document.getElementById('nav-logout').addEventListener('click', function(e) {
e.preventDefault();
localStorage.removeItem('token');
localStorage.removeItem('uuid');
localStorage.removeItem('username');
window.location.href = '/';
});
// Highlight active nav link
const path = window.location.pathname;
document.querySelectorAll('header nav a').forEach(function(a) {
if (a.getAttribute('href') === path) a.classList.add('active');
});
})
.catch(err => {
// If we can't fetch user info, still show basic nav
nav.innerHTML =
'<a href="/" id="nav-home">Главная</a>' +
'<a href="/profile" id="nav-profile">Профиль</a>' +
'<div class="nav-user"><div class="avatar"></div>' + escapeHtml(username) + '</div>' +
'<a href="#" id="nav-logout" class="btn btn-sm btn-danger" style="padding:0.35rem 0.75rem">Выйти</a>';
document.getElementById('nav-logout').addEventListener('click', function(e) {
e.preventDefault();
localStorage.removeItem('token');
localStorage.removeItem('uuid');
localStorage.removeItem('username');
window.location.href = '/';
});
// Highlight active nav link
const path = window.location.pathname;
document.querySelectorAll('header nav a').forEach(function(a) {
if (a.getAttribute('href') === path) a.classList.add('active');
});
});
}
// Highlight active nav link
const path = window.location.pathname;
document.querySelectorAll('header nav a').forEach(function(a) {
if (a.getAttribute('href') === path) a.classList.add('active');
});
})();
function escapeHtml(s) {
const d = document.createElement('div');