Многопользовательский режим: авторизация, изоляция данных, лимиты генераций, деплой без VNC

This commit is contained in:
apuc committed 2026-09-12 16:42:35 +03:00
1 parent 0ca55f3818
commit 25b46a0b2a
10 files changed
+1195 -154

No files matched your search

+83 -4
View File
@@ -79,6 +79,13 @@
.link:hover { text-decoration: underline; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.actions-cell button { padding: 4px 10px; font-size: 12px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex;
align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: var(--card); border: 1px solid var(--border);
border-radius: 12px; padding: 20px; max-width: 920px; width: 94%;
max-height: 92vh; overflow: auto; }
.modal-box img { max-width: 100%; border: 1px solid var(--border);
border-radius: 8px; display: block; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
@@ -92,6 +99,10 @@
<button id="tab-btn-accounts" class="active" onclick="showTab('accounts')">Аккаунты</button>
<button id="tab-btn-vacancies" onclick="showTab('vacancies')">Вакансии</button>
</nav>
<div style="margin-left:auto; display:flex; align-items:center; gap:12px">
<span class="muted" id="current-user"></span>
<button class="secondary" onclick="logout()">Выйти</button>
</div>
</header>
<main>
@@ -229,10 +240,29 @@
</section>
</main>
<!-- ============ МОДАЛКА: ПРОВЕРКА ОТКЛИКА ============ -->
<div id="shot-modal" class="modal hidden" onclick="if(event.target===this) closeShot()">
<div class="modal-box">
<div class="toolbar">
<h2 style="margin:0">Проверьте отклик</h2>
<div class="spacer"></div>
<button class="secondary" onclick="closeShot()">Закрыть</button>
</div>
<div id="shot-note" class="muted" style="margin-bottom:8px"></div>
<img id="shot-img" alt="Скриншот вакансии">
<div class="toolbar" style="margin-top:12px">
<button id="btn-send" onclick="confirmSend()">Отправить отклик</button>
<button class="secondary" onclick="markDone(currentShotId)">Отправил (отметить)</button>
<span id="send-note" class="muted"></span>
</div>
</div>
</div>
<script>
let currentAccount = null;
let vacancies = [];
let generatedTexts = {};
let currentShotId = null;
// ---------- Вкладки ----------
function showTab(name) {
@@ -249,12 +279,20 @@ async function api(url, opts = {}) {
headers: { 'Content-Type': 'application/json' },
...opts,
});
if (resp.status === 401) { window.location = '/login'; throw new Error('Требуется вход'); }
const data = await resp.json().catch(() => ({}));
if (!resp.ok) throw new Error(data.error || `HTTP ${resp.status}`);
return data;
}
function logout() { window.location = '/logout'; }
async function loadAccounts() {
try {
const me = await api('/api/me');
const lim = me.limit ? ` · генерации сегодня: ${me.used}/${me.limit}` : '';
document.getElementById('current-user').textContent = me.user + lim;
} catch (e) { /* 401 уже редиректит */ }
const list = await api('/api/accounts');
const sel = document.getElementById('acc-select');
const prev = sel.value;
@@ -543,21 +581,57 @@ function escapeHtml(s) {
.replace(/"/g,'&quot;');
}
// ---------- Открытие и отметка ----------
// ---------- Открытие, проверка и отправка ----------
async function openVacancy(id) {
const ta = document.querySelector(`textarea[data-id="${id}"]`);
const message = ta ? ta.value : (generatedTexts[id] || '');
const note = document.getElementById(`note-${id}`);
if (note) { note.textContent = 'Открываю браузер...'; }
try {
await api(`/api/accounts/${currentAccount}/open`, {
const data = await api(`/api/accounts/${currentAccount}/open`, {
method: 'POST', body: JSON.stringify({ id, message }),
});
if (note) note.textContent = data.note || '';
if (data.screenshot) {
currentShotId = id;
document.getElementById('shot-img').src = data.screenshot + '?t=' + Date.now();
document.getElementById('shot-note').textContent = data.note || '';
document.getElementById('send-note').textContent = '';
document.getElementById('btn-send').disabled = false;
document.getElementById('shot-modal').classList.remove('hidden');
} else {
alert(data.note || 'Не удалось открыть вакансию');
}
} catch (e) {
if (note) note.textContent = 'Ошибка: ' + e.message;
alert('Ошибка: ' + e.message);
}
}
function closeShot() {
document.getElementById('shot-modal').classList.add('hidden');
}
async function confirmSend() {
const btn = document.getElementById('btn-send');
const note = document.getElementById('send-note');
btn.disabled = true; note.textContent = 'Отправляю...';
try {
const data = await api(`/api/accounts/${currentAccount}/send`, {
method: 'POST', body: JSON.stringify({ id: currentShotId }),
});
note.textContent = data.note || '';
if (data.ok) {
const v = vacancies.find(x => x.id === currentShotId);
if (v) v.responded = true;
renderVacancies();
}
} catch (e) {
note.textContent = 'Ошибка: ' + e.message;
}
btn.disabled = false;
}
async function markDone(id) {
await api(`/api/accounts/${currentAccount}/done`, {
method: 'POST', body: JSON.stringify({ id }),
@@ -575,9 +649,14 @@ async function resetProgress() {
await runSearch();
}
function openLogin() {
async function openLogin() {
if (!currentAccount) return;
window.open(`/api/accounts/${currentAccount}/login`, '_blank');
try {
const data = await api(`/api/accounts/${currentAccount}/login`);
alert(data.note || 'Вход через cookies');
} catch (e) {
alert('Ошибка: ' + e.message);
}
}
// ---------- Старт ----------