Upload files to "templates/admin"
This commit is contained in:
102
templates/admin/avatar_items_view.html
Normal file
102
templates/admin/avatar_items_view.html
Normal file
@@ -0,0 +1,102 @@
|
||||
{% extends 'admin/custom_base.html' %}
|
||||
{% block body %}
|
||||
<div class="container-fluid mt-3">
|
||||
<h4 class="mb-1">Custom Avatar Items</h4>
|
||||
<p class="text-muted small mb-3">Register new avatar items added to the backend DLL. These are added to the item pool alongside the base game items.</p>
|
||||
|
||||
{% if error %}
|
||||
<div class="alert alert-danger alert-dismissible">{{ error }}<button type="button" class="close" data-dismiss="alert">×</button></div>
|
||||
{% endif %}
|
||||
{% if success %}
|
||||
<div class="alert alert-success alert-dismissible">{{ success }}<button type="button" class="close" data-dismiss="alert">×</button></div>
|
||||
{% endif %}
|
||||
|
||||
{% if SCOPE_ADMIN in scopes %}
|
||||
<div class="card mb-4">
|
||||
<div class="card-header bg-primary text-white"><strong>+ Add New Avatar Item</strong></div>
|
||||
<div class="card-body">
|
||||
<form method="POST">
|
||||
<input type="hidden" name="action_type" value="add">
|
||||
<div class="form-row align-items-end">
|
||||
<div class="form-group col-md-4 mb-2">
|
||||
<label class="small font-weight-bold">Item ID/GUID <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="item_id"
|
||||
placeholder="e.g. xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx or custom-id" required>
|
||||
<small class="form-text text-muted">Unique identifier matching the DLL.</small>
|
||||
</div>
|
||||
<div class="form-group col-md-4 mb-2">
|
||||
<label class="small font-weight-bold">Friendly Name <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="friendly_name" placeholder="e.g. Space Helmet" required maxlength="128">
|
||||
</div>
|
||||
<div class="form-group col-md-2 mb-2 d-flex align-items-end">
|
||||
<div class="custom-control custom-switch mb-2">
|
||||
<input type="checkbox" class="custom-control-input" id="starter-check" name="starter" value="1">
|
||||
<label class="custom-control-label" for="starter-check">Default / Starter</label>
|
||||
<small class="form-text text-muted">Unlocked for all new players at level 1.</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-2 mb-2">
|
||||
<button type="submit" class="btn btn-success btn-block">Add Item</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<strong>Registered Custom Items</strong>
|
||||
<span class="badge badge-secondary ml-1">{{ custom_items|length }}</span>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm table-hover mb-0">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th>Friendly Name</th>
|
||||
<th>Item ID (AvatarItemDesc)</th>
|
||||
<th>Default / Starter</th>
|
||||
{% if SCOPE_ADMIN in scopes %}<th>Actions</th>{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if not custom_items %}
|
||||
<tr><td colspan="4" class="text-center text-muted py-4">No custom items registered yet.</td></tr>
|
||||
{% else %}
|
||||
{% for item in custom_items %}
|
||||
{% set item_guid = item.AvatarItemDesc.split(',')[0] %}
|
||||
<tr>
|
||||
<td><strong>{{ item.FriendlyName }}</strong></td>
|
||||
<td><small class="text-monospace">{{ item.AvatarItemDesc }}</small></td>
|
||||
<td>
|
||||
{% if item.get('Starter', false) %}
|
||||
<span class="badge badge-success">Default</span>
|
||||
{% else %}
|
||||
<span class="badge badge-secondary">No</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% if SCOPE_ADMIN in scopes %}
|
||||
<td>
|
||||
<form method="POST" style="display:inline">
|
||||
<input type="hidden" name="action_type" value="toggle_starter">
|
||||
<input type="hidden" name="item_id" value="{{ item_guid }}">
|
||||
<button type="submit" class="btn btn-xs btn-outline-info">
|
||||
{% if item.get('Starter', false) %}Remove Default{% else %}Set Default{% endif %}
|
||||
</button>
|
||||
</form>
|
||||
<form method="POST" style="display:inline" onsubmit="return confirm('Delete this item? Players who own it will keep their unlock.')">
|
||||
<input type="hidden" name="action_type" value="delete">
|
||||
<input type="hidden" name="item_id" value="{{ item_guid }}">
|
||||
<button type="submit" class="btn btn-xs btn-outline-danger">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
98
templates/admin/bans.html
Normal file
98
templates/admin/bans.html
Normal file
@@ -0,0 +1,98 @@
|
||||
{% extends "admin/admin_base.html" %}
|
||||
{% block title %}Bans — KittyRec Admin{% endblock %}
|
||||
{% block head %}
|
||||
<style>
|
||||
.ban-reason { color:var(--text2); font-size:.82rem; max-width:280px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
||||
.until-perm { color:var(--red); font-weight:700; font-size:.78rem; }
|
||||
.until-temp { color:var(--yellow); font-size:.78rem; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-header">
|
||||
<div class="flex items-center gap-2">
|
||||
<h1>Bans</h1>
|
||||
<span class="badge badge-red ml-auto">{{ banned|length }} active</span>
|
||||
</div>
|
||||
<p>Manage active bans and review moderation history</p>
|
||||
</div>
|
||||
|
||||
<div class="grid-2" style="gap:1.5rem">
|
||||
<div class="card">
|
||||
<div class="section-head"><h2>Active Bans</h2></div>
|
||||
{% if banned %}
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead><tr><th>Player</th><th>Reason</th><th>Until</th><th>By</th><th>Actions</th></tr></thead>
|
||||
<tbody>
|
||||
{% for p in banned %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="#" onclick="KR.openDrawer({{ p.id }});return false" style="font-weight:600;color:var(--text);text-decoration:none">{{ p.username }}</a>
|
||||
<div style="color:var(--text3);font-size:.72rem">#{{ p.id }}</div>
|
||||
</td>
|
||||
<td class="ban-reason" title="{{ p.ban_reason }}">{{ p.ban_reason or '—' }}</td>
|
||||
<td>
|
||||
{% if not p.banned_until %}
|
||||
<span class="until-perm">PERMANENT</span>
|
||||
{% else %}
|
||||
<span class="until-temp">{{ p.banned_until[:16] if p.banned_until else '—' }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td style="color:var(--text3);font-size:.8rem">{{ p.banned_by or '—' }}</td>
|
||||
<td>
|
||||
<div class="flex gap-1">
|
||||
{% if SCOPE_ADMIN in scopes %}
|
||||
<button class="btn btn-green btn-sm" onclick="unban({{ p.id }}, '{{ p.username }}', this)">Unban</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<p style="color:var(--text3);font-size:.85rem;text-align:center;padding:2rem 0">No active bans</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="section-head"><h2>Recent Ban Log</h2></div>
|
||||
{% if ban_log %}
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<thead><tr><th>When</th><th>Action</th><th>Player</th><th>Reason</th><th>Admin</th></tr></thead>
|
||||
<tbody>
|
||||
{% for b in ban_log %}
|
||||
<tr>
|
||||
<td style="color:var(--text3);font-size:.75rem;white-space:nowrap">{{ b.created_at[:16] if b.created_at else '—' }}</td>
|
||||
<td>
|
||||
{% if b.action == 'ban' %}<span class="badge badge-red">Ban</span>
|
||||
{% else %}<span class="badge badge-green">Unban</span>{% endif %}
|
||||
</td>
|
||||
<td><a href="#" onclick="KR.openDrawer({{ b.profile_id }});return false" style="color:var(--text);text-decoration:none;font-weight:600">{{ b.username }}</a></td>
|
||||
<td style="color:var(--text2);font-size:.8rem;max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">{{ b.reason or '—' }}</td>
|
||||
<td style="color:var(--text3);font-size:.78rem">{{ b.admin_name or '—' }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<p style="color:var(--text3);font-size:.85rem;text-align:center;padding:2rem 0">No moderation history</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
async function unban(pid, name, btn) {
|
||||
if (!confirm(`Unban ${name}?`)) return;
|
||||
const d = await api('/admin/api/unban/' + pid);
|
||||
if (d.ok) { btn.closest('tr').remove(); toast(`${name} unbanned`); }
|
||||
else toast(d.error || 'Error', 'error');
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
138
templates/admin/cdn_view.html
Normal file
138
templates/admin/cdn_view.html
Normal file
@@ -0,0 +1,138 @@
|
||||
{% extends 'admin/custom_base.html' %}
|
||||
{% block body %}
|
||||
<div class="container-fluid mt-3">
|
||||
<h4 class="mb-3">CDN / File Hosting</h4>
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header bg-primary text-white"><strong>Upload File</strong></div>
|
||||
<div class="card-body">
|
||||
<div class="form-row align-items-end">
|
||||
<div class="form-group col-md-3 mb-2">
|
||||
<label class="small font-weight-bold">Custom Name <span class="text-muted">(optional)</span></label>
|
||||
<input type="text" class="form-control" id="cdn-name" placeholder="my-file.dll">
|
||||
<small class="text-muted">Leave blank for auto-generated name</small>
|
||||
</div>
|
||||
<div class="form-group col-md-3 mb-2">
|
||||
<label class="small font-weight-bold">Label <span class="text-muted">(optional)</span></label>
|
||||
<input type="text" class="form-control" id="cdn-label" placeholder="Description">
|
||||
</div>
|
||||
<div class="form-group col-md-4 mb-2">
|
||||
<label class="small font-weight-bold">File <span class="text-danger">*</span></label>
|
||||
<div class="custom-file">
|
||||
<input type="file" class="custom-file-input" id="cdn-file"
|
||||
onchange="document.getElementById('cdn-file-label').textContent = this.files[0]?.name || 'Choose file'">
|
||||
<label class="custom-file-label" id="cdn-file-label">Choose file (max 10MB)</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-2 mb-2">
|
||||
<label class="small font-weight-bold"> </label>
|
||||
<button class="btn btn-success btn-block d-block" onclick="cdnUpload()">Upload</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="cdn-result" class="alert mt-2" style="display:none"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header"><strong>Hosted Files</strong></div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm table-striped mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Label</th>
|
||||
<th>Size</th>
|
||||
<th>Uploaded</th>
|
||||
<th>URL</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="cdn-table"></tbody>
|
||||
</table>
|
||||
<div id="cdn-empty" class="text-center text-muted py-3" style="display:none">No files uploaded yet.</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const BASE = 'https://kittyrec.tabbycluster.net';
|
||||
|
||||
function formatSize(b) {
|
||||
if (b < 1024) return b + ' B';
|
||||
if (b < 1048576) return (b/1024).toFixed(1) + ' KB';
|
||||
return (b/1048576).toFixed(1) + ' MB';
|
||||
}
|
||||
|
||||
async function loadFiles() {
|
||||
const res = await fetch('/admin/api/cdn/files');
|
||||
const files = await res.json();
|
||||
const tbody = document.getElementById('cdn-table');
|
||||
const empty = document.getElementById('cdn-empty');
|
||||
tbody.innerHTML = '';
|
||||
if (!files.length) { empty.style.display = ''; return; }
|
||||
empty.style.display = 'none';
|
||||
for (const f of files) {
|
||||
const url = BASE + '/' + f.name;
|
||||
const tr = document.createElement('tr');
|
||||
tr.innerHTML = `
|
||||
<td><code>${f.name}</code></td>
|
||||
<td>${f.label || '<span class="text-muted">-</span>'}</td>
|
||||
<td>${formatSize(f.size)}</td>
|
||||
<td><small>${(f.created_at||'').slice(0,16)}</small></td>
|
||||
<td>
|
||||
<div class="input-group input-group-sm" style="width:340px">
|
||||
<input type="text" class="form-control form-control-sm" value="${url}" readonly onclick="this.select()">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-info btn-sm" onclick="navigator.clipboard.writeText('${url}')">Copy</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td><button class="btn btn-xs btn-outline-danger" onclick="cdnDelete('${f.name}')">Del</button></td>
|
||||
`;
|
||||
tbody.appendChild(tr);
|
||||
}
|
||||
}
|
||||
|
||||
async function cdnUpload() {
|
||||
const fileInput = document.getElementById('cdn-file');
|
||||
const result = document.getElementById('cdn-result');
|
||||
if (!fileInput.files.length) {
|
||||
result.className = 'alert alert-danger mt-2';
|
||||
result.textContent = 'Select a file first.';
|
||||
result.style.display = '';
|
||||
return;
|
||||
}
|
||||
const fd = new FormData();
|
||||
fd.append('file', fileInput.files[0]);
|
||||
const name = document.getElementById('cdn-name').value.trim();
|
||||
const label = document.getElementById('cdn-label').value.trim();
|
||||
if (name) fd.append('name', name);
|
||||
if (label) fd.append('label', label);
|
||||
const res = await fetch('/admin/api/cdn/upload', {method: 'POST', body: fd});
|
||||
const d = await res.json();
|
||||
if (d.error) {
|
||||
result.className = 'alert alert-danger mt-2';
|
||||
result.textContent = d.error;
|
||||
} else {
|
||||
result.className = 'alert alert-success mt-2';
|
||||
result.innerHTML = 'Uploaded! URL: <code>' + d.url + '</code> <button class="btn btn-sm btn-outline-info ml-2" onclick="navigator.clipboard.writeText(\'' + d.url + '\')">Copy</button>';
|
||||
fileInput.value = '';
|
||||
document.getElementById('cdn-file-label').textContent = 'Choose file (max 10MB)';
|
||||
document.getElementById('cdn-name').value = '';
|
||||
document.getElementById('cdn-label').value = '';
|
||||
loadFiles();
|
||||
}
|
||||
result.style.display = '';
|
||||
}
|
||||
|
||||
async function cdnDelete(name) {
|
||||
if (!confirm('Delete ' + name + '?')) return;
|
||||
const d = await KR.apiPost('/admin/api/cdn/delete', {name});
|
||||
if (d.error) { KR.toast(d.error, 'error'); return; }
|
||||
KR.toast('Deleted ' + name);
|
||||
loadFiles();
|
||||
}
|
||||
|
||||
loadFiles();
|
||||
</script>
|
||||
{% endblock %}
|
||||
137
templates/admin/chat.html
Normal file
137
templates/admin/chat.html
Normal file
@@ -0,0 +1,137 @@
|
||||
{% extends "admin/admin_base.html" %}
|
||||
{% block title %}Chat Moderation — KittyRec Admin{% endblock %}
|
||||
{% block head %}
|
||||
<style>
|
||||
.thread-row { cursor:pointer; }
|
||||
.thread-row:hover td { background:var(--bg3); }
|
||||
.msg-bubble { padding:.55rem .85rem; border-radius:8px; background:var(--bg3); border:1px solid var(--border); font-size:.85rem; line-height:1.45; word-break:break-word; }
|
||||
.msg-wrap { display:flex; flex-direction:column; gap:.6rem; max-height:500px; overflow-y:auto; }
|
||||
.msg-item { display:flex; align-items:flex-start; gap:.6rem; }
|
||||
.msg-meta { font-size:.7rem; color:var(--text3); white-space:nowrap; margin-top:.25rem; }
|
||||
.msg-system .msg-bubble { background:rgba(124,58,237,.08); border-color:rgba(124,58,237,.2); color:var(--text2); font-style:italic; }
|
||||
#thread-panel { position:fixed; top:0; right:0; width:480px; max-width:100vw; height:100vh; background:var(--bg2); border-left:1px solid var(--border); z-index:800; display:none; flex-direction:column; box-shadow:-8px 0 32px rgba(0,0,0,.5); }
|
||||
#thread-panel.open { display:flex; }
|
||||
#thread-header { padding:1rem 1.25rem; border-bottom:1px solid var(--border); display:flex; align-items:center; gap:.75rem; flex-shrink:0; }
|
||||
#thread-body { flex:1; overflow-y:auto; padding:1rem 1.25rem; }
|
||||
#thread-panel-close { background:none; border:none; color:var(--text3); font-size:1.3rem; cursor:pointer; margin-left:auto; }
|
||||
#thread-panel-close:hover { color:var(--text); }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-header">
|
||||
<div class="flex items-center gap-2">
|
||||
<h1>Chat Moderation</h1>
|
||||
<span class="badge badge-gray ml-auto">{{ threads|length }} threads</span>
|
||||
</div>
|
||||
<p>All player chat threads — click a row to view messages</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="search-bar">
|
||||
<input type="text" id="search" placeholder="Filter by player username…" oninput="filterThreads()">
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table id="threads-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Players</th>
|
||||
<th>Messages</th>
|
||||
<th>Last Activity</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for t in threads %}
|
||||
<tr class="thread-row" id="trow-{{ t.id }}" data-players="{{ t.players|map(attribute='username')|join(' ')|lower }}" onclick="openThread({{ t.id }})">
|
||||
<td class="mono" style="color:var(--text3)">#{{ t.id }}</td>
|
||||
<td>
|
||||
{% for p in t.players %}
|
||||
<a href="/admin/players/{{ p.id }}" onclick="event.stopPropagation()" style="color:var(--text2);text-decoration:none;font-size:.82rem">{{ p.username }}</a>{% if not loop.last %}<span style="color:var(--border)"> · </span>{% endif %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td style="color:var(--text2)">{{ t.message_count }}</td>
|
||||
<td style="color:var(--text3);font-size:.78rem">{{ t.last_message_at[:16] if t.last_message_at else '—' }}</td>
|
||||
<td>
|
||||
<button class="btn btn-ghost btn-sm" onclick="openThread({{ t.id }});event.stopPropagation()">View</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="thread-panel">
|
||||
<div id="thread-header">
|
||||
<div>
|
||||
<div style="font-weight:700" id="thread-panel-title">Thread</div>
|
||||
<div style="font-size:.75rem;color:var(--text3)" id="thread-panel-sub"></div>
|
||||
</div>
|
||||
<button id="thread-panel-close" onclick="closeThread()">×</button>
|
||||
</div>
|
||||
<div id="thread-body">
|
||||
<p style="color:var(--text3);text-align:center;padding:2rem 0">Loading…</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
function filterThreads() {
|
||||
const q = document.getElementById('search').value.toLowerCase();
|
||||
document.querySelectorAll('#threads-table tbody tr').forEach(r => {
|
||||
r.style.display = r.dataset.players.includes(q) ? '' : 'none';
|
||||
});
|
||||
}
|
||||
|
||||
let _currentThread = null;
|
||||
|
||||
async function openThread(tid) {
|
||||
_currentThread = tid;
|
||||
document.getElementById('thread-panel').classList.add('open');
|
||||
document.getElementById('thread-panel-title').textContent = 'Thread #' + tid;
|
||||
document.getElementById('thread-panel-sub').textContent = '';
|
||||
const body = document.getElementById('thread-body');
|
||||
body.innerHTML = '<p style="color:var(--text3);text-align:center;padding:2rem 0">Loading…</p>';
|
||||
const d = await KR.apiGet('/admin/api/chat_thread/' + tid);
|
||||
if (!d || d.error) { body.innerHTML = '<p style="color:var(--red);padding:1rem">Error loading</p>'; return; }
|
||||
const msgs = d.messages || [];
|
||||
document.getElementById('thread-panel-sub').textContent = msgs.length + ' messages';
|
||||
if (!msgs.length) { body.innerHTML = '<p style="color:var(--text3);text-align:center;padding:2rem 0">No messages</p>'; return; }
|
||||
body.innerHTML = '<div class="msg-wrap">' + msgs.map(m => {
|
||||
const isSystem = m.sender_id <= 23;
|
||||
const ts = (m.sent_at || '').slice(0, 16);
|
||||
return `<div class="msg-item ${isSystem ? 'msg-system' : ''}" id="msg-${m.id}">
|
||||
<div style="flex:1">
|
||||
<div style="font-size:.72rem;color:var(--purple-l);font-weight:600;margin-bottom:.2rem">${KR.escapeHtml(m.sender_username || '#' + m.sender_id)}</div>
|
||||
<div class="msg-bubble">${KR.escapeHtml(m.contents)}</div>
|
||||
<div class="msg-meta">${ts}</div>
|
||||
</div>
|
||||
{% if SCOPE_ADMIN in scopes %}
|
||||
<button class="btn btn-ghost btn-sm" style="color:var(--red);padding:2px 7px;flex-shrink:0;margin-top:.25rem" onclick="deleteMsg(${m.id})">Del</button>
|
||||
{% endif %}
|
||||
</div>`;
|
||||
}).join('') + '</div>';
|
||||
}
|
||||
|
||||
function closeThread() {
|
||||
document.getElementById('thread-panel').classList.remove('open');
|
||||
_currentThread = null;
|
||||
}
|
||||
|
||||
async function deleteMsg(mid) {
|
||||
if (!confirm('Delete this message?')) return;
|
||||
const r = await fetch('/admin/api/chat_message/' + mid, { method: 'DELETE' });
|
||||
const d = await r.json();
|
||||
if (d.ok) {
|
||||
const el = document.getElementById('msg-' + mid);
|
||||
if (el) el.remove();
|
||||
KR.toast('Message deleted');
|
||||
} else KR.toast(d.error || 'Error', 'error');
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeThread(); });
|
||||
</script>
|
||||
{% endblock %}
|
||||
129
templates/admin/console_view.html
Normal file
129
templates/admin/console_view.html
Normal file
@@ -0,0 +1,129 @@
|
||||
{% extends 'admin/custom_base.html' %}
|
||||
|
||||
{% block head_css %}{{ super() }}
|
||||
<style>
|
||||
.console-wrap {
|
||||
background: #0b0b0b;
|
||||
border: 1px solid #2a2a2a;
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: calc(100vh - 160px);
|
||||
min-height: 400px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.console-bar {
|
||||
background: #161616;
|
||||
border-bottom: 1px solid #2a2a2a;
|
||||
padding: .45rem .85rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .6rem;
|
||||
flex-shrink: 0;
|
||||
font-size: .75rem;
|
||||
color: #888;
|
||||
}
|
||||
.console-bar .dot {
|
||||
width: 8px; height: 8px; border-radius: 50%; background: #333; flex-shrink: 0;
|
||||
}
|
||||
.console-bar .dot.live { background: #22c55e; box-shadow: 0 0 5px #22c55e99; }
|
||||
.console-bar .dot.away { background: #f59e0b; box-shadow: 0 0 5px #f59e0b66; }
|
||||
.console-bar .sep { flex: 1; }
|
||||
.console-bar button {
|
||||
background: #222; border: 1px solid #383838; color: #bbb;
|
||||
font-size: .7rem; padding: 2px 9px; border-radius: 4px; cursor: pointer;
|
||||
}
|
||||
.console-bar button:hover { background: #2e2e2e; }
|
||||
.console-bar .status-text { font-size: .68rem; }
|
||||
#log {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: .5rem .75rem;
|
||||
font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
|
||||
font-size: .77rem;
|
||||
line-height: 1.5;
|
||||
color: #d4d4d4;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
{{ super() }}
|
||||
<div class="container-fluid" style="padding:1.25rem 1.5rem 0;">
|
||||
<div class="d-flex align-items-center mb-3" style="gap:.75rem;">
|
||||
<h4 style="margin:0;font-weight:800;">Console</h4>
|
||||
<span style="font-size:.75rem;color:#666;" id="info"></span>
|
||||
</div>
|
||||
<div class="console-wrap">
|
||||
<div class="console-bar">
|
||||
<span class="dot" id="dot"></span>
|
||||
<span class="status-text" id="status-text">connecting…</span>
|
||||
<span class="sep"></span>
|
||||
<button onclick="logEl.textContent='';">Clear</button>
|
||||
<button onclick="logEl.scrollTop=logEl.scrollHeight">↓ Bottom</button>
|
||||
</div>
|
||||
<div id="log"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const logEl = document.getElementById('log');
|
||||
const dot = document.getElementById('dot');
|
||||
const stxt = document.getElementById('status-text');
|
||||
const info = document.getElementById('info');
|
||||
|
||||
let totalBytes = 0;
|
||||
let retryDelay = 1000;
|
||||
let ws = null;
|
||||
|
||||
function atBottom() {
|
||||
return logEl.scrollHeight - logEl.scrollTop - logEl.clientHeight < 80;
|
||||
}
|
||||
|
||||
function append(text) {
|
||||
if (!text) return;
|
||||
const wasBot = atBottom();
|
||||
logEl.textContent += text;
|
||||
totalBytes += text.length;
|
||||
info.textContent = (totalBytes / 1024).toFixed(0) + ' KB';
|
||||
if (wasBot) logEl.scrollTop = logEl.scrollHeight;
|
||||
}
|
||||
|
||||
function connect() {
|
||||
const proto = location.protocol === 'https:' ? 'wss' : 'ws';
|
||||
ws = new WebSocket(proto + '://' + location.host + '/admin/ws/console');
|
||||
|
||||
ws.onopen = function() {
|
||||
dot.className = 'dot live';
|
||||
stxt.textContent = 'live';
|
||||
retryDelay = 1000;
|
||||
};
|
||||
|
||||
ws.onmessage = function(e) {
|
||||
append(e.data);
|
||||
};
|
||||
|
||||
ws.onclose = function() {
|
||||
dot.className = 'dot away';
|
||||
stxt.textContent = 'reconnecting in ' + (retryDelay / 1000).toFixed(0) + 's…';
|
||||
setTimeout(connect, retryDelay);
|
||||
retryDelay = Math.min(retryDelay * 2, 16000);
|
||||
};
|
||||
|
||||
ws.onerror = function() {
|
||||
dot.className = 'dot';
|
||||
stxt.textContent = 'error';
|
||||
};
|
||||
}
|
||||
|
||||
document.addEventListener('visibilitychange', function() {
|
||||
if (!document.hidden && ws && ws.readyState === WebSocket.CLOSED) {
|
||||
connect();
|
||||
}
|
||||
});
|
||||
|
||||
connect();
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user