phase 2 rework
This commit is contained in:
1 parent
20054198f3
commit
b397ea9256
44 files changed
+5528
-1377
No files matched your search
@@ -0,0 +1,120 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
const section = document.getElementById('current-downloads');
|
||||
if (!section) return;
|
||||
const workerList = document.getElementById('activity-workers');
|
||||
const unknownList = document.getElementById('activity-unassigned-jobs');
|
||||
const manage = document.getElementById('activity-manage');
|
||||
const scrollHint = document.getElementById('activity-scroll-hint');
|
||||
const text = (node, value) => { const next = String(value ?? ''); if (node.textContent !== next) node.textContent = next; };
|
||||
const element = (tag, className, parent) => {
|
||||
const node = document.createElement(tag); if (className) node.className = className; if (parent) parent.append(node); return node;
|
||||
};
|
||||
function updateScrollHint() {
|
||||
const overflowing = workerList.scrollWidth > workerList.clientWidth + 1;
|
||||
scrollHint.hidden = !overflowing;
|
||||
workerList.tabIndex = overflowing ? 0 : -1;
|
||||
text(scrollHint, 'Scroll sideways to view all ' + workerList.children.length + ' workers.');
|
||||
}
|
||||
function safeSource(value) {
|
||||
return typeof value === 'string' && /^https:\/\/proxer\.me\/watch\/[1-9]\d*\/[1-9]\d*\/(engsub|engdub|gersub|gerdub)$/.test(value) ? value : '';
|
||||
}
|
||||
function bytes(value) {
|
||||
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) return 'Size unavailable';
|
||||
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
|
||||
const index = value ? Math.min(Math.floor(Math.log(value) / Math.log(1024)), 4) : 0;
|
||||
return (value / 1024 ** index).toFixed(index ? 1 : 0) + ' ' + units[index] + ' on disk';
|
||||
}
|
||||
function elapsed(value) {
|
||||
const date = new Date(value);
|
||||
if (!value || !Number.isFinite(date.getTime())) return 'Start time unavailable';
|
||||
const seconds = Math.max(0, Math.floor((Date.now() - date.getTime()) / 1000));
|
||||
const duration = seconds < 60 ? '<1m' : seconds < 3600 ? Math.floor(seconds / 60) + 'm'
|
||||
: Math.floor(seconds / 3600) + 'h ' + Math.floor(seconds % 3600 / 60) + 'm';
|
||||
return 'Started ' + date.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }) + ' · ' + duration;
|
||||
}
|
||||
function validJob(job) { return job && typeof job._id === 'string' && typeof job.filename === 'string'; }
|
||||
function valid(data) {
|
||||
return data && typeof data.available === 'boolean' && Array.isArray(data.workers) && data.workers.length <= 50
|
||||
&& Array.isArray(data.unassigned) && data.unassigned.length <= 50 && data.unassigned.every(validJob)
|
||||
&& data.workers.every(worker => worker && typeof worker.key === 'string' && typeof worker.name === 'string'
|
||||
&& typeof worker.status === 'string' && Array.isArray(worker.jobs) && worker.jobs.length <= 50 && worker.jobs.every(validJob));
|
||||
}
|
||||
function reconcile(list, entries, key, create, update, dataKey) {
|
||||
const existing = new Map(Array.from(list.children, row => [row.dataset[dataKey], row]));
|
||||
let cursor = list.firstElementChild;
|
||||
for (const entry of entries) {
|
||||
const id = String(key(entry)); const row = existing.get(id) || create();
|
||||
existing.delete(id); row.dataset[dataKey] = id; update(row, entry);
|
||||
if (row === cursor) cursor = cursor.nextElementSibling; else list.insertBefore(row, cursor);
|
||||
}
|
||||
for (const row of existing.values()) {
|
||||
if (row.contains(document.activeElement)) manage.focus({ preventScroll: true });
|
||||
row.remove();
|
||||
}
|
||||
}
|
||||
function newJob() {
|
||||
const row = element('li', 'active-job');
|
||||
element('strong', 'active-job-name', row); element('a', 'active-job-source', row);
|
||||
const metrics = element('div', 'active-job-metrics', row);
|
||||
element('span', 'active-job-size', metrics); element('span', 'active-job-time', metrics);
|
||||
element('p', 'active-job-attribution field-hint', row);
|
||||
return row;
|
||||
}
|
||||
function updateJob(row, job, unassigned = false) {
|
||||
text(row.querySelector('.active-job-name'), job.filename);
|
||||
const link = row.querySelector('.active-job-source'); const source = safeSource(job.url);
|
||||
if (source) { link.href = source; link.target = '_blank'; link.rel = 'noopener noreferrer'; }
|
||||
else { link.removeAttribute('href'); link.removeAttribute('target'); link.removeAttribute('rel'); }
|
||||
const parts = source.split('/');
|
||||
text(link, source ? 'Series ' + parts[4] + ' · Episode ' + parts[5] + ' · ' + parts[6] : 'Source unavailable');
|
||||
text(row.querySelector('.active-job-size'), bytes(job.fileSize));
|
||||
const time = row.querySelector('.active-job-time'); time.dataset.startedAt = job.started_at || ''; text(time, elapsed(job.started_at));
|
||||
const attribution = row.querySelector('.active-job-attribution'); attribution.hidden = !unassigned;
|
||||
text(attribution, !unassigned ? '' : job.worker && typeof job.worker.name === 'string'
|
||||
? 'Saved worker: ' + job.worker.name + ' · live assignment unconfirmed' : 'Worker was not recorded for this claim.');
|
||||
}
|
||||
function newWorker() {
|
||||
const card = element('li', 'worker-card'); const heading = element('div', 'worker-card-heading', card);
|
||||
element('strong', 'worker-card-name', heading); element('span', 'worker-card-state badge', heading);
|
||||
element('ul', 'worker-card-jobs', card); element('p', 'worker-card-empty', card); return card;
|
||||
}
|
||||
function render(data, paused) {
|
||||
if (!valid(data)) return false;
|
||||
reconcile(workerList, data.workers, worker => worker.key, newWorker, (card, worker) => {
|
||||
const state = worker.jobs.length ? 'Active' : worker.status !== 'online'
|
||||
? (worker.status === 'errored' ? 'Error' : worker.status === 'stopped' ? 'Stopped' : 'Not ready')
|
||||
: worker.activityUnknown ? 'Activity unknown' : paused ? 'Paused' : 'Idle';
|
||||
text(card.querySelector('.worker-card-name'), worker.name);
|
||||
const badge = card.querySelector('.worker-card-state'); text(badge, state);
|
||||
badge.className = 'worker-card-state badge ' + (state === 'Active' ? 'badge-info'
|
||||
: ['Paused', 'Activity unknown'].includes(state) ? 'badge-warning' : state === 'Idle' ? 'badge-success' : 'badge-neutral');
|
||||
reconcile(card.querySelector('.worker-card-jobs'), worker.jobs, job => job._id, newJob, updateJob, 'activeJobId');
|
||||
const empty = card.querySelector('.worker-card-empty'); empty.hidden = worker.jobs.length > 0;
|
||||
text(empty, worker.activityUnknown && worker.status === 'online' ? 'No current job could be reliably linked to this worker.'
|
||||
: worker.status !== 'online' ? 'Start the worker to take queued episodes.' : paused ? 'Waiting for verification to clear.' : 'Ready for the next queued episode.');
|
||||
}, 'workerKey');
|
||||
reconcile(unknownList, data.unassigned, job => job._id, newJob, (row, job) => updateJob(row, job, true), 'activeJobId');
|
||||
document.getElementById('activity-unassigned').hidden = !data.unassigned.length;
|
||||
const empty = document.getElementById('activity-empty'); empty.hidden = data.workers.length > 0;
|
||||
text(empty.querySelector('strong'), data.available ? 'No managed workers yet' : 'Worker inventory unavailable');
|
||||
text(empty.querySelector('span'), data.available ? 'Quick-add a worker to start taking queued episodes.' : 'Check the worker supervisor, then refresh.');
|
||||
const warning = document.getElementById('activity-warning');
|
||||
warning.hidden = data.available && !data.truncated && !data.workersTruncated;
|
||||
text(warning, !data.available ? 'Worker status is unavailable. Saved active claims are still shown below.'
|
||||
: 'Showing up to 50 workers and 50 active claims. Open the Active queue for the full list; empty cards may have unlisted activity.');
|
||||
text(document.getElementById('activity-freshness'), 'Current claims by worker · updated ' + new Date().toLocaleTimeString());
|
||||
document.getElementById('activity-freshness').classList.remove('feedback-error');
|
||||
updateScrollHint();
|
||||
return true;
|
||||
}
|
||||
document.addEventListener('proxer:status', event => { if (event.detail?.activity) render(event.detail.activity, event.detail.global?.captcha_blocked === true); });
|
||||
document.addEventListener('proxer:status-error', () => {
|
||||
const freshness = document.getElementById('activity-freshness');
|
||||
text(freshness, 'Refresh unavailable · showing the last loaded activity'); freshness.classList.add('feedback-error');
|
||||
});
|
||||
for (const time of section.querySelectorAll('[data-started-at]')) text(time, elapsed(time.dataset.startedAt));
|
||||
updateScrollHint();
|
||||
window.addEventListener('resize', updateScrollHint);
|
||||
window.ProxerActivity = Object.freeze({ valid });
|
||||
})();
|
||||
@@ -0,0 +1,94 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
const main = document.getElementById('main-content');
|
||||
const alert = document.getElementById('captcha-alert');
|
||||
const message = document.getElementById('captcha-message');
|
||||
const status = document.getElementById('global-status');
|
||||
const statusText = document.getElementById('global-status-text');
|
||||
const queueCount = document.getElementById('nav-queue-count');
|
||||
let inFlight = false;
|
||||
let timer = null;
|
||||
let controller = null;
|
||||
let disposed = false;
|
||||
let lastPaused = alert ? !alert.hidden : false;
|
||||
|
||||
function updateStatus(snapshot) {
|
||||
if (!snapshot || typeof snapshot.global !== 'object' || snapshot.global === null) return;
|
||||
lastPaused = snapshot.global.captcha_blocked === true;
|
||||
if (message) message.textContent = snapshot.global.pause_reason === 'resolution'
|
||||
? 'The video link could not be resolved. Possible causes include CAPTCHA or login verification, an unavailable video, or a source change. Workers are paused for verification.'
|
||||
: 'Authentication or access needs verification on Proxer. Workers are paused until verification is complete.';
|
||||
if (alert) alert.hidden = !lastPaused;
|
||||
if (status) {
|
||||
status.classList.toggle('is-paused', lastPaused);
|
||||
status.classList.toggle('is-ready', !lastPaused);
|
||||
status.classList.remove('is-stale');
|
||||
status.removeAttribute('title');
|
||||
}
|
||||
if (statusText) statusText.textContent = lastPaused ? 'Downloads paused' : 'Queue ready';
|
||||
if (queueCount && snapshot.counts) {
|
||||
const queued = Number(snapshot.counts.queued);
|
||||
const processing = Number(snapshot.counts.processing);
|
||||
if (Number.isFinite(queued) && queued >= 0 && Number.isFinite(processing) && processing >= 0) {
|
||||
queueCount.textContent = (queued + processing).toLocaleString();
|
||||
queueCount.hidden = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function markUnavailable() {
|
||||
if (status) {
|
||||
status.classList.remove('is-ready');
|
||||
status.classList.add('is-stale');
|
||||
status.title = 'The latest queue status could not be loaded. The last known information is still shown.';
|
||||
}
|
||||
if (statusText) statusText.textContent = lastPaused ? 'Paused · status unavailable' : 'Status unavailable';
|
||||
}
|
||||
|
||||
async function refreshSummary() {
|
||||
if (disposed || inFlight || document.hidden || ['queue', 'dashboard'].includes(main?.dataset.page)) return;
|
||||
inFlight = true;
|
||||
controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller?.abort(), 8000);
|
||||
try {
|
||||
const response = await fetch('/status-summary', { cache: 'no-store', signal: controller.signal });
|
||||
if (!response.ok) throw new Error('Status unavailable');
|
||||
const snapshot = await response.json();
|
||||
if (!snapshot || typeof snapshot.global !== 'object' || !snapshot.counts) throw new Error('Invalid status');
|
||||
if (!disposed) updateStatus(snapshot);
|
||||
} catch {
|
||||
if (!disposed && !document.hidden) markUnavailable();
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
inFlight = false;
|
||||
controller = null;
|
||||
if (!disposed) timer = setTimeout(refreshSummary, 10000);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('proxer:status', event => updateStatus(event.detail));
|
||||
document.addEventListener('proxer:status-error', markUnavailable);
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
clearTimeout(timer);
|
||||
if (document.hidden) controller?.abort();
|
||||
else refreshSummary();
|
||||
});
|
||||
document.addEventListener('submit', event => {
|
||||
const confirmation = event.target?.dataset?.confirm;
|
||||
if (!event.defaultPrevented && confirmation && !window.confirm(confirmation)) event.preventDefault();
|
||||
});
|
||||
window.addEventListener('pagehide', () => {
|
||||
disposed = true;
|
||||
clearTimeout(timer);
|
||||
controller?.abort();
|
||||
});
|
||||
window.addEventListener('pageshow', event => {
|
||||
if (event.persisted) {
|
||||
disposed = false;
|
||||
refreshSummary();
|
||||
}
|
||||
});
|
||||
window.ProxerUI = Object.freeze({ updateStatus, markUnavailable });
|
||||
refreshSummary();
|
||||
})();
|
||||
@@ -0,0 +1,79 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
const refreshButton = document.getElementById('dashboard-refresh');
|
||||
if (!refreshButton) return;
|
||||
const feedback = document.getElementById('dashboard-feedback');
|
||||
const states = ['queued', 'processing', 'done', 'failed'];
|
||||
let activeRequest = null;
|
||||
let disposed = false;
|
||||
let generation = 0;
|
||||
let failed = false;
|
||||
function text(node, value) { const next = String(value ?? ''); if (node.textContent !== next) node.textContent = next; }
|
||||
function displayTime(value) {
|
||||
const date = new Date(value);
|
||||
return value && Number.isFinite(date.getTime()) ? date.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' }) : 'Time not recorded';
|
||||
}
|
||||
function valid(data) {
|
||||
return data && data.counts && states.every(state => Number.isSafeInteger(data.counts[state]) && data.counts[state] >= 0)
|
||||
&& data.global && typeof data.global.captcha_blocked === 'boolean' && window.ProxerActivity?.valid(data.activity)
|
||||
&& data.recent && ['done', 'failed'].every(state => Array.isArray(data.recent[state]) && data.recent[state].length <= 5
|
||||
&& data.recent[state].every(job => job && typeof job._id === 'string' && typeof job.filename === 'string'));
|
||||
}
|
||||
function updateRecent(state, jobs) {
|
||||
const list = document.getElementById('recent-' + state);
|
||||
const previous = new Map(Array.from(list.children, row => [row.dataset.recentId, row]));
|
||||
let cursor = list.firstElementChild;
|
||||
for (const job of jobs) {
|
||||
const row = previous.get(job._id) || document.createElement('li');
|
||||
previous.delete(job._id);
|
||||
if (!row.className) {
|
||||
row.className = 'recent-job'; const primary = document.createElement('div'); primary.className = 'recent-primary';
|
||||
const title = document.createElement('strong'); title.className = 'recent-name'; primary.append(title);
|
||||
const time = document.createElement('time'); time.className = 'muted'; primary.append(time); row.append(primary);
|
||||
const badge = document.createElement('span'); badge.className = 'badge ' + (state === 'done' ? 'badge-success' : 'badge-danger'); row.append(badge);
|
||||
}
|
||||
row.dataset.recentId = job._id; text(row.querySelector('.recent-name'), job.filename);
|
||||
const time = row.querySelector('time'); const stamp = job[state === 'done' ? 'finished_at' : 'failed_at'] || job.created_at;
|
||||
if (stamp && Number.isFinite(new Date(stamp).getTime())) time.dateTime = stamp; else time.removeAttribute('datetime');
|
||||
text(time, displayTime(stamp)); text(row.querySelector('.badge'), state === 'done' ? 'Completed' : job.error_category || 'Failed');
|
||||
if (row === cursor) cursor = cursor.nextElementSibling; else list.insertBefore(row, cursor);
|
||||
}
|
||||
for (const row of previous.values()) row.remove();
|
||||
document.getElementById('recent-' + state + '-empty').hidden = jobs.length > 0;
|
||||
}
|
||||
async function refresh(manual = false) {
|
||||
if (disposed || activeRequest || (!manual && document.hidden)) return;
|
||||
const request = new AbortController(); const requestGeneration = ++generation;
|
||||
activeRequest = request; refreshButton.disabled = true;
|
||||
const timeout = setTimeout(() => request.abort(), 15000);
|
||||
try {
|
||||
const response = await fetch('/dashboard-data', { cache: 'no-store', signal: request.signal });
|
||||
if (!response.ok) throw new Error('Unavailable');
|
||||
const data = await response.json(); if (!valid(data)) throw new Error('Invalid response');
|
||||
if (disposed || requestGeneration !== generation) return;
|
||||
for (const state of states) text(document.querySelector('[data-dashboard-count="' + state + '"]'), data.counts[state].toLocaleString());
|
||||
for (const state of ['done', 'failed']) updateRecent(state, data.recent[state]);
|
||||
document.dispatchEvent(new CustomEvent('proxer:status', { detail: data }));
|
||||
if (manual || failed) text(feedback, 'Updated at ' + new Date().toLocaleTimeString() + '. Auto refresh is on.');
|
||||
feedback.classList.remove('feedback-error'); failed = false;
|
||||
} catch {
|
||||
if (disposed || requestGeneration !== generation) return;
|
||||
text(feedback, 'Could not refresh the dashboard. The last loaded results are still shown. Try Refresh to reconnect.');
|
||||
feedback.classList.add('feedback-error'); failed = true;
|
||||
document.dispatchEvent(new CustomEvent('proxer:status-error'));
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
if (requestGeneration === generation) { activeRequest = null; refreshButton.disabled = false; }
|
||||
}
|
||||
}
|
||||
refreshButton.addEventListener('click', () => refresh(true));
|
||||
document.addEventListener('visibilitychange', () => { if (!document.hidden) refresh(); });
|
||||
let timer = setInterval(() => refresh(), 10000);
|
||||
window.addEventListener('pagehide', () => { disposed = true; generation++; clearInterval(timer); activeRequest?.abort(); });
|
||||
window.addEventListener('pageshow', event => {
|
||||
if (!event.persisted) return;
|
||||
disposed = false; activeRequest = null; refreshButton.disabled = false;
|
||||
timer = setInterval(() => refresh(), 10000); refresh();
|
||||
});
|
||||
for (const time of document.querySelectorAll('.recent-list time[datetime]')) text(time, displayTime(time.dateTime));
|
||||
})();
|
||||
@@ -0,0 +1,143 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
const form = document.getElementById('jobForm');
|
||||
if (!form) return;
|
||||
const modePicker = document.getElementById('download-mode');
|
||||
const modes = Array.from(form.querySelectorAll('input[name="mode"]'));
|
||||
const seriesFields = document.getElementById('series-fields');
|
||||
const videoFields = document.getElementById('video-fields');
|
||||
const id = document.getElementById('series-id');
|
||||
const season = document.getElementById('series-season');
|
||||
const first = document.getElementById('episode-from');
|
||||
const last = document.getElementById('episode-to');
|
||||
const url = document.getElementById('episode-url');
|
||||
const language = document.getElementById('language');
|
||||
const name = document.getElementById('download-name');
|
||||
const token = document.getElementById('download-token');
|
||||
const submit = document.getElementById('queue-download');
|
||||
const toggleToken = document.getElementById('toggle-token');
|
||||
const maximum = Number(form.dataset.maxEpisodes) || 500;
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
function positive(value) {
|
||||
return /^[1-9]\d*$/.test(value) && Number.isSafeInteger(Number(value));
|
||||
}
|
||||
|
||||
function watchSource(value) {
|
||||
if (!value || value.length > 2048 || /[\s\\\u0000-\u001f\u007f-\u009f]/u.test(value)) return null;
|
||||
try {
|
||||
const source = new URL(value);
|
||||
if (source.protocol !== 'https:' || !['proxer.me', 'www.proxer.me'].includes(source.hostname)
|
||||
|| /^https:\/\/[^/?#]*@/i.test(value) || source.username || source.password
|
||||
|| (source.port && source.port !== '443') || source.search) return null;
|
||||
const match = source.pathname.match(/^\/watch\/([1-9]\d*)\/([1-9]\d*)\/(engsub|engdub|gersub|gerdub)\/?$/);
|
||||
return match && positive(match[1]) && positive(match[2])
|
||||
? { id: String(Number(match[1])), episode: String(Number(match[2])), language: match[3] } : null;
|
||||
} catch { return null; }
|
||||
}
|
||||
|
||||
function validFilename(value) {
|
||||
return value && value !== '.' && value !== '..'
|
||||
&& !/[\/\\\u0000-\u001f\u007f-\u009f\uD800-\uDFFF]/u.test(value)
|
||||
&& encoder.encode(`${value}.mp4`).length <= 255;
|
||||
}
|
||||
|
||||
function preview() {
|
||||
const series = modes.find(input => input.checked)?.value !== 'video';
|
||||
for (const input of [id, season, first, last, url, name, token]) input.setCustomValidity('');
|
||||
let count = null;
|
||||
let firstFilename = '';
|
||||
let lastFilename = '';
|
||||
let invalidMessage = '';
|
||||
const title = name.value.trim();
|
||||
if (series) {
|
||||
const validSeason = /^(0|[1-9]\d*)$/.test(season.value) && Number.isSafeInteger(Number(season.value));
|
||||
if (season.value && !validSeason) season.setCustomValidity('Season must be a whole number of zero or greater within the supported range.');
|
||||
for (const [input, label] of [[id, 'Series ID'], [first, 'First episode'], [last, 'Last episode']]) {
|
||||
if (input.value && !positive(input.value)) input.setCustomValidity(`${label} must be a positive whole number within the supported range.`);
|
||||
}
|
||||
if (positive(first.value) && positive(last.value)) {
|
||||
const from = Number(first.value), to = Number(last.value);
|
||||
if (to < from) invalidMessage = 'The last episode must be greater than or equal to the first.';
|
||||
else if (to - from + 1 > maximum) invalidMessage = `Choose no more than ${maximum.toLocaleString()} episodes per submission.`;
|
||||
else count = to - from + 1;
|
||||
last.setCustomValidity(invalidMessage);
|
||||
if (count !== null && positive(id.value) && validSeason) {
|
||||
const base = title || String(Number(id.value));
|
||||
const seasonText = String(Number(season.value)).padStart(3, '0');
|
||||
firstFilename = `${base}S${seasonText}E${String(from).padStart(3, '0')}_${language.value}`;
|
||||
lastFilename = `${base}S${seasonText}E${String(to).padStart(3, '0')}_${language.value}`;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const source = watchSource(url.value);
|
||||
if (url.value && !source) url.setCustomValidity('Enter an HTTPS Proxer watch URL with a series ID, episode and supported language.');
|
||||
if (source) {
|
||||
count = 1;
|
||||
firstFilename = title || `${source.id} E${source.episode} ${source.language}`;
|
||||
}
|
||||
}
|
||||
if ((title && /[\/\\\u0000-\u001f\u007f-\u009f\uD800-\uDFFF]/u.test(title))
|
||||
|| (firstFilename && !validFilename(firstFilename)) || (lastFilename && !validFilename(lastFilename))) {
|
||||
invalidMessage = 'Choose a shorter filename without slashes or control characters. The full name including .mp4 must fit within 255 bytes.';
|
||||
name.setCustomValidity(invalidMessage);
|
||||
}
|
||||
if (token.value && /[\s;\u0000-\u001f\u007f-\u009f\uD800-\uDFFF]/u.test(token.value)) {
|
||||
token.setCustomValidity('Enter the token value without spaces, control characters or cookie separators.');
|
||||
}
|
||||
document.getElementById('preview-count').textContent = count === null ? '—' : count.toLocaleString();
|
||||
document.getElementById('preview-count-label').textContent = count === 1 ? 'episode to queue' : 'episodes to queue';
|
||||
document.getElementById('filename-preview').textContent = firstFilename ? `${firstFilename}.mp4` : 'Fill in the episode details to see your filenames.';
|
||||
const final = document.getElementById('preview-last');
|
||||
final.hidden = !lastFilename || lastFilename === firstFilename;
|
||||
final.textContent = final.hidden ? '' : `… through ${lastFilename}.mp4`;
|
||||
document.getElementById('preview-validation').textContent = invalidMessage;
|
||||
}
|
||||
|
||||
function updateMode() {
|
||||
const series = modes.find(input => input.checked)?.value !== 'video';
|
||||
seriesFields.hidden = seriesFields.disabled = !series;
|
||||
videoFields.hidden = videoFields.disabled = series;
|
||||
document.getElementById('preview-mode').textContent = series ? 'Series' : 'Single episode';
|
||||
document.getElementById('name-label').textContent = series ? 'Series title' : 'Filename';
|
||||
name.placeholder = series ? 'e.g. My Series' : 'e.g. My SeriesS001E001_engsub';
|
||||
document.getElementById('name-hint').textContent = series
|
||||
? 'Enter the title without season or episode numbers. Season, episode and language are added automatically. Leave blank to use the series ID.'
|
||||
: 'Enter a filename without .mp4. Leave blank to use the series ID, episode and language.';
|
||||
preview();
|
||||
}
|
||||
|
||||
modes.forEach(input => input.addEventListener('change', updateMode));
|
||||
form.addEventListener('input', preview);
|
||||
language.addEventListener('change', preview);
|
||||
toggleToken.hidden = false;
|
||||
toggleToken.addEventListener('click', () => {
|
||||
const showing = token.type === 'password';
|
||||
token.type = showing ? 'text' : 'password';
|
||||
toggleToken.textContent = showing ? 'Hide' : 'Show';
|
||||
toggleToken.setAttribute('aria-pressed', String(showing));
|
||||
});
|
||||
form.addEventListener('submit', event => {
|
||||
preview();
|
||||
if (!form.checkValidity()) {
|
||||
event.preventDefault();
|
||||
form.reportValidity();
|
||||
return;
|
||||
}
|
||||
token.type = 'password';
|
||||
toggleToken.textContent = 'Show';
|
||||
toggleToken.setAttribute('aria-pressed', 'false');
|
||||
submit.disabled = true;
|
||||
submit.textContent = 'Checking access and adding…';
|
||||
});
|
||||
window.addEventListener('pageshow', () => {
|
||||
submit.disabled = false;
|
||||
submit.textContent = 'Add to queue →';
|
||||
updateMode();
|
||||
});
|
||||
modePicker.hidden = false;
|
||||
const checkedAt = document.getElementById('token-checked-at');
|
||||
if (checkedAt) checkedAt.textContent = new Date(checkedAt.dateTime).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' });
|
||||
updateMode();
|
||||
document.getElementById('form-error')?.focus();
|
||||
})();
|
||||
@@ -0,0 +1,324 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const view = document.getElementById("queue-view");
|
||||
if (!view) return;
|
||||
const list = document.getElementById("queue-jobs");
|
||||
const form = document.getElementById("queue-filter-form");
|
||||
const feedback = document.getElementById("queue-feedback");
|
||||
const refreshButton = document.getElementById("queue-refresh");
|
||||
const autoButton = document.getElementById("queue-auto-refresh");
|
||||
const clearForm = document.getElementById("queue-clear-state-form");
|
||||
const clearButton = document.getElementById("queue-clear-state-button");
|
||||
const clearActions = {
|
||||
queued: { label: "Clear waiting queue", confirmation: "Remove every waiting episode from the queue, including episodes outside this filter or page? Active downloads will continue." },
|
||||
done: { label: "Clear completed history", confirmation: "Clear all completed download records, including records outside this filter or page? Downloaded files will remain on disk." },
|
||||
failed: { label: "Clear failed history", confirmation: "Clear all failed-attempt records, including records outside this filter or page? Retained queued episodes and files will remain unchanged." }
|
||||
};
|
||||
const states = {
|
||||
queued: { label: "Queued", badge: "badge-neutral", date: "created_at", dateLabel: "Queued",
|
||||
note: "Waiting episodes are taken by available workers when verification is clear.",
|
||||
empty: "Add a series or a single episode to get started." },
|
||||
processing: { label: "Active", badge: "badge-info", date: "started_at", dateLabel: "Started",
|
||||
note: "File size shows the current file on disk. A claimed item may be resolving its source or transferring.",
|
||||
empty: "No episodes are currently claimed by a worker." },
|
||||
done: { label: "Completed", badge: "badge-success", date: "finished_at", dateLabel: "Finished",
|
||||
note: "Completed downloads stay in history until you clear their records.",
|
||||
empty: "Successful downloads will appear here." },
|
||||
failed: { label: "Failed attempts", badge: "badge-danger", date: "failed_at", dateLabel: "Failed",
|
||||
note: "An attempt can appear here even when its retained episode later completes. Check the queue and completed downloads before resubmitting.",
|
||||
empty: "No failed attempts are recorded." }
|
||||
};
|
||||
const languages = { engsub: "English sub", engdub: "English dub", gersub: "German sub", gerdub: "German dub" };
|
||||
let current = {
|
||||
state: view.dataset.state, q: view.dataset.query,
|
||||
page: Number(view.dataset.page), pageSize: Number(view.dataset.pageSize)
|
||||
};
|
||||
let auto = true;
|
||||
let activeRequest = null;
|
||||
let generation = 0;
|
||||
let disposed = false;
|
||||
let lastRefreshFailed = false;
|
||||
let clearAllowed = !clearButton.disabled;
|
||||
|
||||
function parameters(selection) {
|
||||
return new URLSearchParams({
|
||||
state: selection.state, q: selection.q,
|
||||
page: String(selection.page), pageSize: String(selection.pageSize)
|
||||
});
|
||||
}
|
||||
function pageUrl(selection) { return "/status?" + parameters(selection); }
|
||||
function setText(element, value) {
|
||||
const text = String(value == null ? "" : value);
|
||||
if (element.textContent !== text) element.textContent = text;
|
||||
}
|
||||
function element(tag, className, parent) {
|
||||
const node = document.createElement(tag);
|
||||
if (className) node.className = className;
|
||||
if (parent) parent.append(node);
|
||||
return node;
|
||||
}
|
||||
function safeSource(value) {
|
||||
return typeof value === "string" && /^https:\/\/proxer\.me\/watch\/[1-9]\d*\/[1-9]\d*\/(engsub|engdub|gersub|gerdub)$/.test(value) ? value : "";
|
||||
}
|
||||
function sourceLabel(value) {
|
||||
const parts = safeSource(value).split("/");
|
||||
return parts.length === 7
|
||||
? "Series " + parts[4] + " · Episode " + parts[5] + " · " + languages[parts[6]]
|
||||
: "Source unavailable";
|
||||
}
|
||||
function formatBytes(value) {
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) return "—";
|
||||
const units = ["B", "KiB", "MiB", "GiB", "TiB"];
|
||||
const index = value > 0 ? Math.min(Math.floor(Math.log(value) / Math.log(1024)), units.length - 1) : 0;
|
||||
return (value / Math.pow(1024, index)).toFixed(index === 0 ? 0 : 1) + " " + units[index];
|
||||
}
|
||||
function formatTime(value) {
|
||||
const date = new Date(value);
|
||||
return value && Number.isFinite(date.getTime())
|
||||
? date.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" })
|
||||
: "Not recorded";
|
||||
}
|
||||
|
||||
function createRow() {
|
||||
const row = element("li", "job-row");
|
||||
const primary = element("div", "job-primary", row);
|
||||
element("strong", "job-filename", primary);
|
||||
element("a", "job-source", primary);
|
||||
const status = element("div", "job-state", row);
|
||||
element("span", "badge", status);
|
||||
element("span", "job-error-category muted", status);
|
||||
const time = element("div", "job-time", row);
|
||||
element("span", "job-time-label muted", time);
|
||||
element("time", "", time);
|
||||
const size = element("div", "job-size", row);
|
||||
element("span", "job-size-value", size);
|
||||
element("small", "muted", size);
|
||||
const details = element("details", "job-log", row);
|
||||
element("summary", "", details);
|
||||
element("pre", "log-output", details).tabIndex = 0;
|
||||
return row;
|
||||
}
|
||||
|
||||
function updateRow(row, job, state) {
|
||||
const info = states[state];
|
||||
row.dataset.jobId = String(job._id);
|
||||
row.dataset.jobState = state;
|
||||
setText(row.querySelector(".job-filename"), job.filename);
|
||||
const source = row.querySelector(".job-source");
|
||||
const sourceUrl = safeSource(job.url);
|
||||
if (sourceUrl) {
|
||||
source.href = sourceUrl;
|
||||
source.target = "_blank";
|
||||
source.rel = "noopener noreferrer";
|
||||
} else {
|
||||
source.removeAttribute("href");
|
||||
source.removeAttribute("target");
|
||||
source.removeAttribute("rel");
|
||||
}
|
||||
setText(source, sourceLabel(job.url));
|
||||
const badge = row.querySelector(".badge");
|
||||
badge.className = "badge " + info.badge;
|
||||
setText(badge, info.label);
|
||||
setText(row.querySelector(".job-error-category"), job.error_category || "");
|
||||
setText(row.querySelector(".job-time-label"), state === "processing" && !job.started_at ? "Queued" : info.dateLabel);
|
||||
const time = row.querySelector("time");
|
||||
const timestamp = job[info.date] || job.created_at;
|
||||
if (timestamp && Number.isFinite(new Date(timestamp).getTime())) time.dateTime = timestamp;
|
||||
else time.removeAttribute("datetime");
|
||||
setText(time, formatTime(timestamp));
|
||||
setText(row.querySelector(".job-size-value"), formatBytes(job.fileSize));
|
||||
setText(row.querySelector(".job-size small"), typeof job.fileSize === "number" ? "on disk" : "not available");
|
||||
const details = row.querySelector(".job-log");
|
||||
details.hidden = !job.output_log;
|
||||
setText(details.querySelector("summary"), state === "failed" ? "View attempt log" : "View log");
|
||||
const log = details.querySelector("pre");
|
||||
const scrollTop = log.scrollTop;
|
||||
setText(log, job.output_log || "");
|
||||
log.scrollTop = scrollTop;
|
||||
}
|
||||
|
||||
function renderRows(items, state) {
|
||||
const existing = new Map(Array.from(list.children, row => [
|
||||
row.dataset.jobState + ":" + row.dataset.jobId, row
|
||||
]));
|
||||
let cursor = list.firstElementChild;
|
||||
for (const job of items) {
|
||||
const key = state + ":" + String(job._id);
|
||||
const row = existing.get(key) || createRow();
|
||||
existing.delete(key);
|
||||
updateRow(row, job, state);
|
||||
// Leave unchanged nodes in place so focus, expanded logs and log scrolling survive polling.
|
||||
if (row === cursor) cursor = cursor.nextElementSibling;
|
||||
else list.insertBefore(row, cursor);
|
||||
}
|
||||
for (const row of existing.values()) {
|
||||
if (row.contains(document.activeElement)) refreshButton.focus({ preventScroll: true });
|
||||
row.remove();
|
||||
}
|
||||
list.setAttribute("aria-label", states[state].label);
|
||||
}
|
||||
|
||||
function validSnapshot(data) {
|
||||
const whole = value => Number.isSafeInteger(value) && value >= 0;
|
||||
return data && Array.isArray(data.items) && data.items.length <= 50
|
||||
&& data.items.every(job => job && typeof job._id === "string" && typeof job.filename === "string")
|
||||
&& data.filters && Object.hasOwn(states, data.filters.state) && typeof data.filters.q === "string"
|
||||
&& data.pagination && whole(data.pagination.total) && whole(data.pagination.page)
|
||||
&& data.pagination.page >= 1 && whole(data.pagination.totalPages) && data.pagination.totalPages >= 1
|
||||
&& [10, 25, 50].includes(data.pagination.pageSize)
|
||||
&& data.counts && Object.keys(states).every(state => whole(data.counts[state]))
|
||||
&& window.ProxerActivity?.valid(data.activity);
|
||||
}
|
||||
|
||||
function renderSnapshot(data) {
|
||||
const info = states[current.state];
|
||||
const clearAction = clearActions[current.state];
|
||||
clearForm.hidden = !clearAction;
|
||||
clearForm.dataset.confirm = clearAction?.confirmation || "";
|
||||
document.getElementById("queue-clear-state").value = current.state;
|
||||
setText(clearButton, clearAction?.label || "Clear records");
|
||||
document.getElementById("queue-active-protected").hidden = Boolean(clearAction);
|
||||
clearAllowed = Boolean(clearAction) && data.counts[current.state] > 0;
|
||||
setText(document.getElementById("queue-title"), info.label);
|
||||
setText(document.getElementById("queue-state-note"), info.note);
|
||||
for (const link of document.querySelectorAll("[data-state-link]")) {
|
||||
const state = link.dataset.stateLink;
|
||||
const selected = state === current.state;
|
||||
link.classList.toggle("is-selected", selected);
|
||||
if (selected) link.setAttribute("aria-current", "page");
|
||||
else link.removeAttribute("aria-current");
|
||||
link.href = pageUrl({ ...current, state, page: 1 });
|
||||
setText(link.querySelector("[data-state-count]"), data.counts[state]);
|
||||
}
|
||||
document.getElementById("queue-state").value = current.state;
|
||||
const clearLink = document.getElementById("queue-clear-filter");
|
||||
clearLink.hidden = !current.q;
|
||||
clearLink.href = pageUrl({ ...current, q: "", page: 1 });
|
||||
renderRows(data.items, current.state);
|
||||
document.getElementById("queue-empty").hidden = data.items.length !== 0;
|
||||
setText(document.getElementById("queue-empty-title"), current.q ? "No matching filenames" : "No " + info.label.toLowerCase());
|
||||
setText(document.getElementById("queue-empty-message"), current.q ? "Try a shorter search or choose another state." : info.empty);
|
||||
const pagination = data.pagination;
|
||||
const start = (pagination.page - 1) * pagination.pageSize + 1;
|
||||
const end = Math.min(pagination.page * pagination.pageSize, pagination.total);
|
||||
setText(document.getElementById("queue-range"), pagination.total
|
||||
? start + "–" + end + " of " + pagination.total + (current.q ? " matches" : "")
|
||||
: "0 results");
|
||||
setText(document.getElementById("queue-page-label"), "Page " + pagination.page + " of " + pagination.totalPages);
|
||||
for (const link of document.querySelectorAll("[data-page-link]")) {
|
||||
const previous = link.dataset.pageLink === "previous";
|
||||
const disabled = previous ? current.page <= 1 : current.page >= pagination.totalPages;
|
||||
link.setAttribute("aria-disabled", String(disabled));
|
||||
link.tabIndex = disabled ? -1 : 0;
|
||||
link.href = pageUrl({ ...current, page: previous ? Math.max(1, current.page - 1) : Math.min(pagination.totalPages, current.page + 1) });
|
||||
}
|
||||
Object.assign(view.dataset, { state: current.state, page: String(current.page), pageSize: String(current.pageSize), query: current.q });
|
||||
document.dispatchEvent(new CustomEvent("proxer:status", { detail: data }));
|
||||
}
|
||||
|
||||
async function refresh(next = current, mode = "auto") {
|
||||
if (disposed || (mode === "auto" && (document.hidden || !auto || activeRequest))) return;
|
||||
if (activeRequest) activeRequest.abort();
|
||||
const request = new AbortController();
|
||||
const requestGeneration = ++generation;
|
||||
activeRequest = request;
|
||||
refreshButton.disabled = true;
|
||||
clearButton.disabled = true;
|
||||
view.setAttribute("aria-busy", "true");
|
||||
const timeout = setTimeout(() => request.abort(), 15000);
|
||||
try {
|
||||
const response = await fetch("/status-data?" + parameters(next), { cache: "no-store", signal: request.signal });
|
||||
if (!response.ok) throw new Error("Unavailable");
|
||||
const data = await response.json();
|
||||
if (!validSnapshot(data)) throw new Error("Invalid response");
|
||||
if (requestGeneration !== generation || disposed) return;
|
||||
current = { ...data.filters, page: data.pagination.page, pageSize: data.pagination.pageSize };
|
||||
renderSnapshot(data);
|
||||
if (mode === "navigate" || mode === "popstate") {
|
||||
document.getElementById("queue-query").value = current.q;
|
||||
document.getElementById("queue-page-size").value = String(current.pageSize);
|
||||
}
|
||||
if (mode === "navigate") history.pushState(null, "", pageUrl(current));
|
||||
else if (mode === "popstate" || current.page !== next.page) history.replaceState(null, "", pageUrl(current));
|
||||
if (mode !== "auto" || lastRefreshFailed) {
|
||||
setText(feedback, "Updated at " + new Date().toLocaleTimeString() + (auto ? ". Auto refresh is on." : ". Auto refresh is off."));
|
||||
}
|
||||
feedback.classList.remove("feedback-error");
|
||||
lastRefreshFailed = false;
|
||||
} catch {
|
||||
if (requestGeneration !== generation || disposed) return;
|
||||
setText(feedback, "Could not refresh the queue. The last loaded results are still shown. Try Refresh to reconnect.");
|
||||
feedback.classList.add("feedback-error");
|
||||
lastRefreshFailed = true;
|
||||
document.dispatchEvent(new CustomEvent("proxer:status-error"));
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
if (requestGeneration === generation) {
|
||||
activeRequest = null;
|
||||
refreshButton.disabled = false;
|
||||
clearButton.disabled = !clearAllowed || lastRefreshFailed;
|
||||
view.setAttribute("aria-busy", "false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
form.addEventListener("submit", event => {
|
||||
event.preventDefault();
|
||||
if (!form.reportValidity()) return;
|
||||
refresh({
|
||||
state: current.state,
|
||||
q: document.getElementById("queue-query").value.trim(),
|
||||
pageSize: Number(document.getElementById("queue-page-size").value), page: 1
|
||||
}, "navigate");
|
||||
});
|
||||
clearForm.addEventListener("submit", event => {
|
||||
if (activeRequest || lastRefreshFailed || !clearAllowed) event.preventDefault();
|
||||
});
|
||||
document.addEventListener("click", event => {
|
||||
const link = event.target.closest("[data-state-link], [data-page-link], #queue-clear-filter");
|
||||
if (!link || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
||||
event.preventDefault();
|
||||
if (link.getAttribute("aria-disabled") === "true") return;
|
||||
const params = new URL(link.href).searchParams;
|
||||
refresh({
|
||||
state: params.get("state") || "queued", q: params.get("q") || "",
|
||||
page: Number(params.get("page") || 1), pageSize: Number(params.get("pageSize") || 25)
|
||||
}, "navigate");
|
||||
});
|
||||
refreshButton.addEventListener("click", () => refresh(current, "manual"));
|
||||
autoButton.addEventListener("click", () => {
|
||||
auto = !auto;
|
||||
autoButton.setAttribute("aria-pressed", String(auto));
|
||||
setText(autoButton, "Auto refresh: " + (auto ? "on" : "off"));
|
||||
setText(feedback, auto ? "Updates every 10 seconds while this page is visible." : "Auto refresh is off. Use Refresh when you are ready.");
|
||||
if (auto) refresh();
|
||||
});
|
||||
window.addEventListener("popstate", () => {
|
||||
const params = new URLSearchParams(location.search);
|
||||
refresh({
|
||||
state: params.get("state") || "queued", q: params.get("q") || "",
|
||||
page: Number(params.get("page") || 1), pageSize: Number(params.get("pageSize") || 25)
|
||||
}, "popstate");
|
||||
});
|
||||
document.addEventListener("visibilitychange", () => { if (!document.hidden) refresh(); });
|
||||
let timer = setInterval(() => refresh(), 10000);
|
||||
window.addEventListener("pagehide", () => {
|
||||
disposed = true;
|
||||
generation++;
|
||||
clearInterval(timer);
|
||||
activeRequest?.abort();
|
||||
});
|
||||
window.addEventListener("pageshow", event => {
|
||||
if (!event.persisted) return;
|
||||
disposed = false;
|
||||
activeRequest = null;
|
||||
refreshButton.disabled = false;
|
||||
clearButton.disabled = !clearAllowed || lastRefreshFailed;
|
||||
view.setAttribute("aria-busy", "false");
|
||||
timer = setInterval(() => refresh(), 10000);
|
||||
refresh();
|
||||
});
|
||||
// Server-rendered timestamps are immediately localized without changing row identity.
|
||||
for (const time of list.querySelectorAll("time[datetime]")) setText(time, formatTime(time.dateTime));
|
||||
})();
|
||||
+446
-216
@@ -1,222 +1,452 @@
|
||||
/* ===============================
|
||||
GLOBAL STYLING — Dark Grey Theme
|
||||
=============================== */
|
||||
/* Shared application shell. Assets stay local so the UI also works without a CDN. */
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--background: #101519;
|
||||
--surface: #181f25;
|
||||
--surface-raised: #202a32;
|
||||
--surface-input: #11191f;
|
||||
--border: #2d3943;
|
||||
--border-soft: #26313a;
|
||||
--text: #edf2f5;
|
||||
--muted: #a2b1bd;
|
||||
--faint: #8696a3;
|
||||
--accent: #80ddca;
|
||||
--accent-ink: #102a25;
|
||||
--accent-soft: #213d37;
|
||||
--blue: #a6caff;
|
||||
--warning: #efc77e;
|
||||
--danger: #ffaaa0;
|
||||
--radius: 12px;
|
||||
--content-width: 1320px;
|
||||
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||
font-size: 15px;
|
||||
line-height: 1.55;
|
||||
font-synthesis: none;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
[hidden] { display: none !important; }
|
||||
body { margin: 0; min-width: 300px; background: var(--background); color: var(--text); }
|
||||
button, input, select, textarea { font: inherit; }
|
||||
button, input, select, textarea, a, summary { -webkit-tap-highlight-color: transparent; }
|
||||
button { cursor: pointer; }
|
||||
button:disabled { cursor: not-allowed; opacity: .5; }
|
||||
a { color: var(--accent); text-underline-offset: 3px; }
|
||||
a:hover { color: #b1f3e5; }
|
||||
h1, h2, h3, p, dl { margin: 0; }
|
||||
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
|
||||
legend { padding: 0; }
|
||||
button, a, summary, input, select { touch-action: manipulation; }
|
||||
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
|
||||
::selection { background: var(--accent-soft); color: #fff; }
|
||||
input::placeholder { color: var(--faint); opacity: 1; }
|
||||
input[type="number"] { appearance: textfield; }
|
||||
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
|
||||
.visually-hidden, .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
|
||||
.muted { color: var(--muted); }
|
||||
.small, small { font-size: .82rem; }
|
||||
.skip-link { position: fixed; z-index: 100; top: 10px; left: 14px; transform: translateY(-160%); background: var(--accent); color: var(--accent-ink); padding: 10px 16px; border-radius: 6px; font-weight: 700; }
|
||||
.skip-link:focus { transform: translateY(0); }
|
||||
|
||||
body {
|
||||
background: #2C2C2C; /* dark grey */
|
||||
color: #E0E0E0; /* soft light grey text */
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
/* Navigation and shared state */
|
||||
.topbar { position: sticky; top: 0; z-index: 20; background: #151c22; border-bottom: 1px solid var(--border); }
|
||||
.topbar-inner { display: flex; align-items: center; gap: 38px; max-width: var(--content-width); min-height: 80px; padding: 0 32px; margin: auto; }
|
||||
.brand { display: flex; align-items: center; flex: 0 0 auto; gap: 11px; color: var(--text); text-decoration: none; }
|
||||
.brand:hover { color: var(--text); }
|
||||
.brand-mark { display: grid; place-items: center; width: 37px; height: 37px; background: var(--accent); border-radius: 10px; color: var(--accent-ink); }
|
||||
.brand-mark svg { width: 25px; height: 25px; }
|
||||
.brand-text { display: flex; flex-direction: column; font-size: 1.12rem; font-weight: 750; line-height: 1.17; letter-spacing: -.02em; }
|
||||
.brand-text > span { color: var(--muted); font-size: .73rem; font-weight: 500; letter-spacing: .035em; }
|
||||
.main-nav { display: flex; align-self: stretch; align-items: stretch; gap: 8px; }
|
||||
.nav-link { display: flex; align-items: center; gap: 8px; position: relative; padding: 0 16px; color: var(--muted); font-size: .9rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
|
||||
.nav-link:hover { color: var(--text); background: #1b242b; }
|
||||
.nav-link.is-active { color: var(--accent); }
|
||||
.nav-link.is-active::after { content: ""; position: absolute; bottom: -1px; height: 3px; left: 16px; right: 16px; background: var(--accent); border-radius: 3px 3px 0 0; }
|
||||
.nav-count { display: inline-flex; justify-content: center; min-width: 21px; padding: 1px 6px; border-radius: 5px; background: var(--surface-raised); font-size: .7rem; line-height: 1.5; font-variant-numeric: tabular-nums; color: var(--muted); }
|
||||
.nav-link.is-active .nav-count { background: var(--accent-soft); color: var(--accent); }
|
||||
.connection-status { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; padding: 6px 10px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; font-size: .76rem; white-space: nowrap; }
|
||||
.status-dot { width: 6px; height: 6px; flex: 0 0 auto; border-radius: 50%; background: var(--faint); }
|
||||
.connection-status.is-ready .status-dot { background: var(--accent); }
|
||||
.connection-status.is-paused { color: var(--warning); border-color: #65502d; }
|
||||
.connection-status.is-paused .status-dot, .connection-status.is-stale .status-dot { background: var(--warning); }
|
||||
.connection-status.is-stale { color: var(--warning); }
|
||||
.notice-wrap { max-width: var(--content-width); padding: 0 32px; margin: auto; }
|
||||
.verification-notice { display: flex; gap: 24px; align-items: center; justify-content: space-between; margin-top: 24px; padding: 18px 22px; background: #2d281e; border: 1px solid #65502d; border-radius: var(--radius); }
|
||||
.notice-copy { display: flex; flex-direction: column; gap: 5px; }
|
||||
.notice-copy > strong { color: var(--warning); font-size: .92rem; }
|
||||
.notice-copy > span { color: #e1ceb0; font-size: .85rem; }
|
||||
.verification-notice form { flex-shrink: 0; }
|
||||
|
||||
/* Layout and common controls */
|
||||
.app-main { max-width: var(--content-width); min-height: calc(100vh - 180px); margin: 0 auto; padding: 36px 32px 48px; }
|
||||
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
|
||||
.eyebrow { color: var(--faint); font-size: .67rem; font-weight: 700; letter-spacing: .14em; margin-bottom: 9px; }
|
||||
.page-title { font-size: clamp(1.8rem, 3vw, 2.18rem); line-height: 1.2; letter-spacing: -.035em; font-weight: 650; }
|
||||
.page-description { color: var(--muted); margin-top: 9px; max-width: 750px; font-size: .9rem; }
|
||||
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; overflow: clip; }
|
||||
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 24px; border-bottom: 1px solid var(--border-soft); }
|
||||
.panel-header h2 { font-size: 1rem; font-weight: 650; letter-spacing: -.015em; }
|
||||
.panel-body { padding: 24px; }
|
||||
.button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 42px; padding: 9px 16px; border: 1px solid transparent; border-radius: 7px; font-size: .86rem; font-weight: 650; line-height: 1.4; color: var(--text); background: var(--surface-raised); text-decoration: none; transition: background-color .15s, border-color .15s; }
|
||||
.button:hover { background: #2b3740; color: var(--text); }
|
||||
.button-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
|
||||
.button-primary:hover { background: #a0ebdc; color: var(--accent-ink); border-color: #a0ebdc; }
|
||||
.button-secondary { background: transparent; border-color: #3b4a56; }
|
||||
.button-secondary:hover { background: var(--surface-raised); border-color: #5c7180; }
|
||||
.button-ghost { background: transparent; color: var(--muted); }
|
||||
.button-ghost:hover { background: var(--surface-raised); }
|
||||
.button-danger { color: var(--danger); background: #372724; border-color: #64413b; }
|
||||
.button-danger:hover { color: #ffd6cf; background: #4a2d29; border-color: #996056; }
|
||||
.button-warning { color: #f7d69d; background: #48391e; border-color: #856839; }
|
||||
.button-warning:hover { color: #ffdfac; background: #5a4623; }
|
||||
.button-small { min-height: 34px; padding: 6px 11px; font-size: .79rem; }
|
||||
.button[aria-disabled="true"] { pointer-events: none; opacity: .45; }
|
||||
.button-group, .toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
|
||||
.page-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: end; gap: 14px; }
|
||||
.badge { display: inline-flex; align-items: center; justify-content: center; padding: 3px 8px; border: 1px solid transparent; border-radius: 5px; font-size: .7rem; font-weight: 600; line-height: 1.6; white-space: nowrap; }
|
||||
.badge-neutral { background: #27323c; color: #c4d0db; border-color: #354451; }
|
||||
.badge-success, .status-online { background: #203a32; color: #9de4c3; border-color: #315645; }
|
||||
.badge-warning, .status-pending { background: #3e3321; color: #f1d399; border-color: #5f4d30; }
|
||||
.badge-danger, .status-stopped { background: #3f2a2a; color: #ffb7ad; border-color: #5d3a36; }
|
||||
.badge-info, .badge-active { background: #23374b; color: #adceff; border-color: #35516c; }
|
||||
.field { min-width: 0; }
|
||||
.field-label { display: block; font-size: .83rem; font-weight: 550; color: #d5dfe6; margin-bottom: 8px; }
|
||||
.field-label > span[aria-hidden] { color: var(--accent); }
|
||||
.field-input, .input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #3c4b57; border-radius: 7px; background: var(--surface-input); color: var(--text); line-height: 1.4; font-size: .9rem; }
|
||||
select.field-input { padding-right: 30px; }
|
||||
.field-input:focus, .input:focus { border-color: var(--accent); outline: 2px solid #80ddca33; outline-offset: 1px; }
|
||||
.field-input[aria-invalid="true"] { border-color: var(--danger); }
|
||||
.field-hint { color: var(--muted); font-size: .77rem; line-height: 1.6; margin-top: 7px; overflow-wrap: anywhere; }
|
||||
.optional { margin-left: 5px; color: var(--faint); font-size: .73rem; font-weight: 400; }
|
||||
.inline-notice, .notice { margin-bottom: 20px; padding: 14px 16px; border: 1px solid var(--border); background: var(--surface-raised); border-radius: 8px; font-size: .88rem; }
|
||||
.inline-notice p { margin-top: 5px; }
|
||||
.notice-error, .notice-danger { color: #ffc2b8; border-color: #6f4540; background: #3b2928; }
|
||||
.notice-success { color: #afe6cc; border-color: #35624e; background: #203b30; }
|
||||
.notice-warning { color: #f1d399; border-color: #65502d; background: #352d20; }
|
||||
.empty-state { text-align: center; padding: 56px 24px; color: var(--muted); }
|
||||
.empty-state h2, .empty-state h3, .empty-state strong { color: var(--text); font-size: 1.05rem; font-weight: 550; }
|
||||
.empty-state p { margin: 7px auto 16px; max-width: 450px; font-size: .85rem; }
|
||||
.app-footer { display: flex; justify-content: space-between; gap: 20px; max-width: var(--content-width); margin: 0 auto; padding: 20px 32px 26px; color: var(--faint); font-size: .73rem; border-top: 1px solid var(--border-soft); }
|
||||
.error-panel { max-width: 760px; margin: 40px auto; }
|
||||
.error-panel .panel-body { padding: 36px; }
|
||||
.error-panel .button-group { margin-top: 26px; }
|
||||
|
||||
/* Download form */
|
||||
.download-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; gap: 24px; }
|
||||
.download-sidebar { display: grid; gap: 20px; position: sticky; top: 104px; }
|
||||
.mode-switch { display: flex; gap: 12px; margin-bottom: 29px; }
|
||||
.mode-choice { position: relative; flex: 1; cursor: pointer; }
|
||||
.mode-choice input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; }
|
||||
.mode-choice > span { display: flex; flex-direction: column; gap: 3px; padding: 13px 16px; border: 1px solid #3c4b57; border-radius: 8px; background: var(--surface-input); }
|
||||
.mode-choice strong { font-size: .88rem; font-weight: 650; }
|
||||
.mode-choice small { color: var(--muted); font-size: .73rem; }
|
||||
.mode-choice input:checked + span { border-color: var(--accent); background: #21342f; }
|
||||
.mode-choice input:checked + span > strong { color: var(--accent); }
|
||||
.mode-choice input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; }
|
||||
.mode-choice:hover > span { border-color: #718d9c; }
|
||||
.form-section { padding-top: 25px; margin-top: 24px; border-top: 1px solid var(--border-soft); }
|
||||
#series-fields, #video-fields { padding-top: 0; margin-top: 0; border-top: 0; }
|
||||
.section-label { display: flex; align-items: center; gap: 9px; margin-bottom: 18px; color: var(--faint); font-size: .72rem; font-weight: 500; }
|
||||
.section-label > span { color: var(--text); font-size: .9rem; font-weight: 600; }
|
||||
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
|
||||
.input-with-action { display: flex; align-items: stretch; position: relative; }
|
||||
.input-with-action .field-input { padding-right: 64px; }
|
||||
.input-action { position: absolute; right: 7px; top: 7px; bottom: 7px; border: 0; border-radius: 4px; padding: 2px 8px; color: var(--muted); background: var(--surface-raised); font-size: .72rem; }
|
||||
.input-action:hover { color: var(--text); }
|
||||
.form-actions { display: flex; align-items: center; gap: 18px; border-top: 1px solid var(--border-soft); margin-top: 26px; padding-top: 24px; }
|
||||
.form-actions > .button { flex-shrink: 0; }
|
||||
.preview-count { display: flex; flex-direction: column; gap: 7px; margin-bottom: 24px; }
|
||||
.preview-count > strong { font-size: 2.8rem; line-height: 1.15; font-weight: 600; letter-spacing: -.04em; color: var(--accent); }
|
||||
.preview-count > span { color: var(--muted); font-size: .85rem; }
|
||||
.preview-section { padding-top: 20px; margin-top: 20px; border-top: 1px solid var(--border-soft); }
|
||||
.preview-section h3 { color: var(--faint); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; font-weight: 650; margin-bottom: 10px; }
|
||||
.preview-filename, .destination-path { overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .8rem; line-height: 1.75; }
|
||||
.destination-path { color: var(--accent); }
|
||||
.preview-validation { font-size: .8rem; line-height: 1.6; color: var(--warning); }
|
||||
.preview-validation:not(:empty) { margin-top: 18px; }
|
||||
.help-card { display: flex; align-items: start; gap: 12px; padding: 20px 8px; }
|
||||
.help-icon { display: grid; place-items: center; flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%; color: var(--muted); border: 1px solid #59707d; font-size: .75rem; font-family: Georgia, serif; font-style: italic; }
|
||||
.help-card h2 { font-size: .85rem; font-weight: 600; margin-bottom: 8px; }
|
||||
.help-card p { color: var(--muted); font-size: .8rem; line-height: 1.75; }
|
||||
.help-card strong { font-weight: 550; color: #c4d2dc; }
|
||||
|
||||
/* Queue and history */
|
||||
.queue-overview { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 26px; }
|
||||
.queue-stat { display: flex; flex-direction: column; gap: 5px; padding: 18px 21px; color: var(--text); text-decoration: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
|
||||
.queue-stat:hover { color: var(--text); border-color: #657c8c; background: #1c262d; }
|
||||
.queue-stat.is-selected { background: #1d302d; border-color: #68b9a8; }
|
||||
.queue-stat-label { color: #bac8d2; font-size: .8rem; font-weight: 550; }
|
||||
.queue-stat-count { font-size: 2rem; line-height: 1.25; font-weight: 600; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
|
||||
.queue-stat.is-selected .queue-stat-count { color: var(--accent); }
|
||||
.queue-stat-note { color: var(--faint); font-size: .72rem; }
|
||||
.queue-filters { display: flex; flex-wrap: wrap; align-items: end; gap: 14px; padding: 20px 24px; border-bottom: 1px solid var(--border-soft); }
|
||||
.queue-filters > .field:first-child, .queue-filters .field-grow { flex: 1 1 260px; }
|
||||
.queue-filters > .field:not(:first-child) { flex: 0 0 130px; }
|
||||
.queue-filters > .field.queue-search { flex: 1 1 260px; }
|
||||
.queue-filters .field-label { font-size: .75rem; margin-bottom: 7px; }
|
||||
.queue-filters .button { min-height: 44px; }
|
||||
.panel-body > .queue-filters { padding: 0; border: 0; }
|
||||
#queue-state-note { font-size: .79rem; margin-top: 5px; }
|
||||
.job-error-category { display: block; font-size: .69rem; margin-top: 5px; overflow-wrap: anywhere; }
|
||||
.queue-columns, .job-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px 175px 110px; column-gap: 22px; align-items: center; }
|
||||
.queue-columns { padding: 13px 24px; color: var(--faint); font-size: .67rem; letter-spacing: .07em; text-transform: uppercase; border-bottom: 1px solid var(--border-soft); }
|
||||
.job-list { margin: 0; padding: 0; list-style: none; }
|
||||
.job-row { padding: 20px 24px; border-bottom: 1px solid var(--border-soft); }
|
||||
.job-row:last-child { border-bottom: 0; }
|
||||
.job-row:hover { background: #1a242b; }
|
||||
.job-primary, .job-time, .job-size, .job-state { min-width: 0; }
|
||||
.job-filename { display: block; color: var(--text); font-size: .9rem; font-weight: 600; overflow-wrap: anywhere; }
|
||||
.job-source { display: block; margin-top: 5px; color: var(--muted); font-size: .73rem; overflow-wrap: anywhere; }
|
||||
.job-source:hover { color: var(--accent); }
|
||||
.job-id { display: block; margin-top: 3px; color: var(--faint); font-size: .7rem; overflow-wrap: anywhere; }
|
||||
.job-time { font-size: .77rem; color: #bfccd5; }
|
||||
.job-time time { display: block; }
|
||||
.job-time-label { display: block; color: var(--faint); font-size: .69rem; margin-bottom: 3px; }
|
||||
.job-size-value { display: block; color: #d4dfe7; font-size: .8rem; font-variant-numeric: tabular-nums; }
|
||||
.job-size small { display: block; margin-top: 3px; color: var(--faint); font-size: .69rem; }
|
||||
.job-log { grid-column: 1 / -1; margin-top: 12px; }
|
||||
details > summary { cursor: pointer; font-size: .78rem; color: var(--muted); }
|
||||
details > summary:hover { color: var(--text); }
|
||||
.job-log[open] > summary { color: var(--accent); margin-bottom: 10px; }
|
||||
.log-output, .log-view { margin: 0; padding: 18px; overflow: auto; border: 1px solid var(--border-soft); border-radius: 8px; color: #cad9e3; background: #10171c; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .77rem; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; tab-size: 2; max-height: 26rem; }
|
||||
.queue-pagination { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px; padding: 18px 24px; border-top: 1px solid var(--border-soft); color: var(--muted); font-size: .8rem; }
|
||||
.queue-pagination > div, .queue-pagination nav { display: flex; align-items: center; gap: 10px; }
|
||||
.queue-actions { margin-top: 24px; border-top: 1px solid var(--border-soft); padding-top: 18px; }
|
||||
.queue-actions > summary { color: var(--faint); font-size: .8rem; }
|
||||
.queue-actions[open] > summary { margin-bottom: 15px; }
|
||||
.queue-actions p { color: var(--muted); font-size: .8rem; max-width: 780px; margin: 10px 0 16px; }
|
||||
.queue-actions form { display: inline-block; margin: 0 8px 8px 0; }
|
||||
#queue-feedback { color: var(--muted); font-size: .77rem; }
|
||||
#queue-feedback.is-error { color: var(--warning); }
|
||||
#queue-feedback.feedback-error { color: var(--warning); }
|
||||
|
||||
/* Worker management */
|
||||
.workers-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 24px; align-items: start; }
|
||||
.worker-workspace { display: grid; gap: 24px; min-width: 0; }
|
||||
.workers-layout > .panel > .panel-body { padding: 0; }
|
||||
.worker-list { list-style: none; padding: 12px; margin: 0; display: grid; gap: 7px; max-height: 440px; overflow-y: auto; }
|
||||
.worker-list-item { min-width: 0; }
|
||||
.worker-row { width: 100%; text-align: left; padding: 14px; background: transparent; color: var(--text); border: 1px solid transparent; border-radius: 8px; }
|
||||
.worker-row:hover { background: var(--surface-raised); border-color: var(--border); }
|
||||
.worker-row.is-selected { border-color: #68b9a8; background: #21352f; }
|
||||
.worker-row-heading, .worker-summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
|
||||
.worker-name { color: var(--text); font-size: .88rem; font-weight: 600; overflow-wrap: anywhere; }
|
||||
.worker-row-meta, .worker-metrics, .worker-counts { color: var(--muted); font-size: .74rem; margin-top: 6px; }
|
||||
.worker-row-meta { display: block; }
|
||||
.worker-metrics { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
|
||||
.worker-create { padding: 20px 24px; border-top: 1px solid var(--border-soft); }
|
||||
.worker-create h3 { font-size: .9rem; font-weight: 600; margin-bottom: 17px; }
|
||||
.worker-create > .button { margin-top: 15px; }
|
||||
.inline-form { display: flex; gap: 8px; align-items: end; }
|
||||
.inline-form .field { flex: 1; min-width: 0; }
|
||||
.worker-create .field-hint { margin-top: 9px; }
|
||||
.worker-controls { min-width: 0; }
|
||||
.worker-actions { display: flex; flex-wrap: wrap; gap: 9px; margin: 0 0 22px; }
|
||||
.worker-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 20px 0; }
|
||||
.worker-stats > div { padding: 13px 15px; border: 1px solid var(--border-soft); background: var(--surface-input); border-radius: 8px; }
|
||||
.worker-stats dt { color: var(--faint); font-size: .71rem; }
|
||||
.worker-stats dd { margin: 5px 0 0; color: var(--text); font-size: 1.1rem; font-weight: 550; font-variant-numeric: tabular-nums; }
|
||||
.worker-details { font-size: .8rem; }
|
||||
.worker-details > dl { display: grid; gap: 9px; margin-top: 14px; }
|
||||
.worker-details > dl > div { display: grid; grid-template-columns: 110px minmax(0, 1fr); column-gap: 18px; }
|
||||
.worker-details dt { color: var(--faint); }
|
||||
.worker-details dd { margin: 0; color: #c8d5df; overflow-wrap: anywhere; }
|
||||
.worker-selection-empty { padding: 42px 24px; color: var(--muted); text-align: center; }
|
||||
.worker-selection-empty .empty-state { padding: 0; }
|
||||
.worker-selection-empty h2 { color: var(--text); font-size: 1rem; font-weight: 550; margin-bottom: 8px; }
|
||||
.worker-selection-empty p { font-size: .85rem; }
|
||||
.action-message { padding: 12px 15px; border: 1px solid var(--border); background: var(--surface-input); color: var(--muted); border-radius: 8px; font-size: .8rem; overflow-wrap: anywhere; }
|
||||
.action-message.is-error { border-color: #70443e; background: #3a2926; color: var(--danger); }
|
||||
.action-message.is-success { border-color: #3e6555; background: #20372e; color: #b4e7ce; }
|
||||
.log-panel { min-width: 0; }
|
||||
.log-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
|
||||
.log-toolbar .button-group { gap: 7px; }
|
||||
.log-toolbar .worker-actions { margin: 0; gap: 7px; }
|
||||
.log-toolbar { margin-bottom: 14px; }
|
||||
.checkbox-label { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .77rem; }
|
||||
.checkbox-label input { accent-color: var(--accent); }
|
||||
.log-view { height: 28rem; max-height: 28rem; }
|
||||
.log-panel .panel-body { padding: 16px; }
|
||||
.log-panel .panel-header { flex-wrap: wrap; }
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.topbar-inner { gap: 22px; }
|
||||
.nav-link { padding: 0 12px; }
|
||||
.download-layout { grid-template-columns: minmax(0, 1fr) 290px; gap: 20px; }
|
||||
.workers-layout { grid-template-columns: 310px minmax(0, 1fr); gap: 20px; }
|
||||
.queue-columns, .job-row { grid-template-columns: minmax(0, 1fr) 100px 145px 90px; gap: 16px; }
|
||||
.worker-stats > div { padding: 11px; }
|
||||
}
|
||||
@media (max-width: 850px) {
|
||||
.topbar-inner { flex-wrap: wrap; padding-top: 16px; gap: 12px 20px; }
|
||||
.brand { margin-bottom: 3px; }
|
||||
.main-nav { order: 3; flex-basis: 100%; height: 48px; gap: 8px; }
|
||||
.nav-link { padding: 0 14px; }
|
||||
.connection-status { margin-bottom: 3px; }
|
||||
.app-main { padding-top: 28px; }
|
||||
.download-layout { grid-template-columns: minmax(0, 1fr) 270px; gap: 16px; }
|
||||
.panel-header, .panel-body { padding: 20px; }
|
||||
.panel-header { flex-wrap: wrap; gap: 7px; }
|
||||
.download-sidebar { top: 142px; }
|
||||
.form-actions { align-items: start; flex-direction: column; gap: 10px; }
|
||||
.mode-choice > span { padding: 12px 11px; }
|
||||
.mode-choice small { font-size: .67rem; }
|
||||
.workers-layout { grid-template-columns: 270px minmax(0, 1fr); gap: 16px; }
|
||||
.worker-stats { gap: 7px; }
|
||||
.worker-stats dd { font-size: .95rem; }
|
||||
.worker-details > dl > div { grid-template-columns: 80px minmax(0, 1fr); gap: 8px; }
|
||||
}
|
||||
@media (max-width: 740px) {
|
||||
.topbar-inner, .notice-wrap { padding-left: 20px; padding-right: 20px; }
|
||||
.app-main { padding: 25px 20px 36px; }
|
||||
.app-footer { padding-left: 20px; padding-right: 20px; }
|
||||
.page-heading { align-items: start; gap: 16px; margin-bottom: 24px; }
|
||||
.page-heading > .button { flex-shrink: 0; }
|
||||
.page-heading .page-description { font-size: .84rem; }
|
||||
.download-layout, .workers-layout { grid-template-columns: minmax(0, 1fr); }
|
||||
.download-sidebar { position: static; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
|
||||
.help-card { padding: 15px 5px; }
|
||||
.queue-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
|
||||
.queue-stat { padding: 15px 17px; }
|
||||
.queue-stat-count { font-size: 1.8rem; }
|
||||
.queue-columns { display: none; }
|
||||
.job-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px 20px; }
|
||||
.job-primary { grid-column: 1 / -1; }
|
||||
.job-state { grid-column: 2; grid-row: 2; justify-self: end; }
|
||||
.job-time { grid-column: 1; grid-row: 2; }
|
||||
.job-size { grid-column: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
||||
.job-size small { margin-top: 0; }
|
||||
.job-log { margin-top: 0; }
|
||||
.queue-filters { padding: 18px 20px; }
|
||||
.queue-filters > .field:first-child, .queue-filters .field-grow { flex-basis: 100%; }
|
||||
.queue-filters > .field:not(:first-child) { flex: 1; }
|
||||
.queue-filters > .field.queue-search { flex: 1 1 100%; }
|
||||
.queue-pagination { padding: 16px 20px; }
|
||||
.verification-notice { align-items: start; flex-direction: column; gap: 15px; padding: 18px; margin-top: 20px; }
|
||||
.worker-list { max-height: 320px; }
|
||||
.worker-stats { gap: 12px; }
|
||||
.worker-stats dd { font-size: 1.15rem; }
|
||||
.log-view { height: 22rem; max-height: 22rem; }
|
||||
}
|
||||
@media (max-width: 470px) {
|
||||
.topbar-inner { padding-left: 16px; padding-right: 16px; gap: 12px; }
|
||||
.main-nav { gap: 0; justify-content: space-between; }
|
||||
.nav-link { padding: 0 10px; font-size: .81rem; }
|
||||
.nav-link.is-active::after { left: 10px; right: 10px; }
|
||||
.connection-status { padding: 5px 7px; font-size: .65rem; gap: 6px; max-width: 160px; white-space: normal; }
|
||||
.brand-mark { width: 33px; height: 33px; }
|
||||
.brand-text { font-size: 1rem; }
|
||||
.brand-text > span { font-size: .67rem; }
|
||||
.app-main { padding: 23px 16px 30px; }
|
||||
.notice-wrap { padding: 0 16px; }
|
||||
.page-heading { flex-direction: column; align-items: stretch; gap: 17px; }
|
||||
.page-heading > .button { align-self: start; }
|
||||
.page-actions { justify-content: start; }
|
||||
.page-title { font-size: 1.85rem; }
|
||||
.eyebrow { font-size: .61rem; }
|
||||
.panel-header, .panel-body { padding: 18px; }
|
||||
.download-sidebar { grid-template-columns: minmax(0, 1fr); gap: 8px; }
|
||||
.form-grid { column-gap: 14px; row-gap: 18px; }
|
||||
.form-grid > .field:nth-child(-n+2) { grid-column: 1 / -1; }
|
||||
.field-input { font-size: 16px; }
|
||||
.field-label { font-size: .8rem; }
|
||||
.mode-switch { gap: 8px; }
|
||||
.mode-choice > span { padding: 12px; }
|
||||
.mode-choice strong { font-size: .81rem; }
|
||||
.mode-choice small { font-size: .67rem; }
|
||||
.form-actions .button { width: 100%; }
|
||||
.queue-filters, .job-row { padding-left: 18px; padding-right: 18px; }
|
||||
.queue-pagination { align-items: start; flex-direction: column; }
|
||||
.queue-pagination > div, .queue-pagination nav { width: 100%; justify-content: space-between; }
|
||||
.worker-row-heading { gap: 6px; }
|
||||
.worker-stats { gap: 7px; }
|
||||
.worker-stats > div { padding: 10px; }
|
||||
.worker-stats dd { font-size: 1rem; }
|
||||
.worker-create { padding: 18px; }
|
||||
.worker-actions .button { flex: 1 1 40%; }
|
||||
.app-footer { padding-left: 16px; padding-right: 16px; font-size: .68rem; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*, *::before, *::after { transition-duration: 0s !important; scroll-behavior: auto !important; }
|
||||
}
|
||||
|
||||
/* Container boundaries (Bootstrap container inside layout.ejs) */
|
||||
.container {
|
||||
max-width: 1100px;
|
||||
/* Dashboard and current worker claims */
|
||||
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 15px; }
|
||||
.section-heading h2 { font-size: 1rem; font-weight: 650; letter-spacing: -.015em; }
|
||||
.section-heading h3 { font-size: .9rem; font-weight: 600; }
|
||||
.section-heading .field-hint { margin-top: 3px; }
|
||||
.text-link { font-size: .8rem; font-weight: 600; text-decoration: none; flex-shrink: 0; }
|
||||
.text-link:hover { text-decoration: underline; }
|
||||
.activity-section { margin-bottom: 28px; min-width: 0; }
|
||||
.activity-cards { display: grid; grid-auto-flow: column; grid-auto-columns: calc((100% - 28px) / 3); gap: 14px; overflow-x: auto; padding: 0 0 7px; margin: 0; list-style: none; scroll-snap-type: x proximity; scrollbar-color: #435461 transparent; scrollbar-width: thin; }
|
||||
.activity-cards:empty { display: none; }
|
||||
.worker-card { background: var(--surface); border: 1px solid var(--border); border-top: 2px solid #42675f; border-radius: 10px; min-width: 0; padding: 17px 18px; scroll-snap-align: start; }
|
||||
.worker-card-heading { display: flex; align-items: start; justify-content: space-between; gap: 9px; margin-bottom: 15px; }
|
||||
.worker-card-name { min-width: 0; overflow-wrap: anywhere; color: var(--muted); font-size: .78rem; font-weight: 600; }
|
||||
.worker-card-state { font-size: .65rem; padding: 1px 6px; }
|
||||
.worker-card-jobs, .unassigned-jobs { list-style: none; padding: 0; margin: 0; }
|
||||
.worker-card-jobs > .active-job + .active-job { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border-soft); }
|
||||
.active-job-name { display: block; font-weight: 600; font-size: .95rem; line-height: 1.45; overflow-wrap: anywhere; }
|
||||
.active-job-source { display: block; margin-top: 6px; font-size: .72rem; color: var(--muted); text-decoration: none; overflow-wrap: anywhere; }
|
||||
.active-job-source[href]:hover { color: var(--accent); text-decoration: underline; }
|
||||
.active-job-metrics { display: flex; flex-direction: column; gap: 5px; margin-top: 17px; font-size: .7rem; font-variant-numeric: tabular-nums; }
|
||||
.active-job-size { color: var(--accent); font-weight: 600; }
|
||||
.active-job-time { color: var(--faint); }
|
||||
.worker-card-empty { color: var(--faint); font-size: .82rem; min-height: 86px; padding-top: 6px; }
|
||||
.activity-warning { margin-bottom: 14px; font-size: .8rem; }
|
||||
.activity-empty { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; border: 1px dashed #3c4b57; border-radius: 9px; padding: 20px; color: var(--muted); font-size: .82rem; }
|
||||
.activity-empty strong { font-weight: 550; color: var(--text); }
|
||||
.activity-empty .button { margin-left: auto; }
|
||||
.unassigned-activity { margin-top: 17px; padding: 18px 20px; border: 1px solid #65502d; border-radius: 10px; background: #211f1a; }
|
||||
.unassigned-jobs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
|
||||
.unassigned-jobs .active-job + .active-job { border-left: 1px solid #484131; padding-left: 20px; }
|
||||
.dashboard-overview { margin-bottom: 10px; }
|
||||
.dashboard-feedback { margin: 0 0 24px; }
|
||||
.dashboard-history { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; }
|
||||
.recent-list { list-style: none; padding: 0; margin: 0; }
|
||||
.recent-job { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 17px 24px; border-bottom: 1px solid var(--border-soft); }
|
||||
.recent-job:last-child { border-bottom: 0; }
|
||||
.recent-primary { display: grid; gap: 5px; min-width: 0; }
|
||||
.recent-name { font-size: .83rem; font-weight: 550; overflow-wrap: anywhere; }
|
||||
.recent-primary time { font-size: .72rem; }
|
||||
.recent-empty { padding: 36px 20px; }
|
||||
.history-footnote { padding: 14px 24px; border-top: 1px solid var(--border-soft); margin: 0; }
|
||||
.queue-action-help { margin-top: 15px; }
|
||||
#queue-view > .panel-header { flex-wrap: wrap; }
|
||||
#queue-view > .panel-header > div:first-child { flex: 1 1 340px; }
|
||||
#queue-view > .panel-header > .button-group { flex: 0 1 auto; }
|
||||
.form-grid > .season-field { grid-column: 1 / -1; }
|
||||
.season-field .field-input { max-width: 145px; }
|
||||
.token-cache-status { padding: 14px 16px; background: var(--surface-input); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 17px; }
|
||||
.worker-create > summary { cursor: pointer; font-size: .82rem; color: var(--muted); }
|
||||
.worker-quick-add-hint { margin: 0; padding: 17px 24px; border-top: 1px solid var(--border-soft); }
|
||||
.worker-create[open] > summary { margin-bottom: 20px; }
|
||||
.worker-create form > .button { margin-top: 15px; }
|
||||
@media (max-width: 1100px) {
|
||||
.activity-cards { grid-auto-columns: calc((100% - 14px) / 2); }
|
||||
.unassigned-jobs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
.topbar-inner { gap: 18px; }
|
||||
}
|
||||
|
||||
/* ===============================
|
||||
HEADER / NAVIGATION
|
||||
=============================== */
|
||||
|
||||
header h1 {
|
||||
font-size: 2.4rem;
|
||||
font-weight: 700;
|
||||
margin: 0;
|
||||
color: #8A190B; /* deep red accent */
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.6);
|
||||
@media (max-width: 740px) {
|
||||
.dashboard-history { grid-template-columns: minmax(0, 1fr); gap: 20px; }
|
||||
.recent-job { padding: 16px 20px; }
|
||||
.section-heading { align-items: start; }
|
||||
.unassigned-jobs { grid-template-columns: minmax(0, 1fr); }
|
||||
.unassigned-jobs .active-job + .active-job { border-left: 0; border-top: 1px solid #484131; padding-left: 0; padding-top: 16px; }
|
||||
}
|
||||
|
||||
.btn-outline-light {
|
||||
color: #E0E0E0;
|
||||
border-color: #5A5A5A;
|
||||
}
|
||||
.btn-outline-light:hover {
|
||||
background-color: #5A5A5A;
|
||||
color: #c7c7c7;
|
||||
}
|
||||
|
||||
/* ===============================
|
||||
CARDS / PANELS
|
||||
=============================== */
|
||||
|
||||
.card-dark,
|
||||
.card {
|
||||
background-color: #3A3A3A !important; /* mid-grey panels */
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
border: 1px solid #444;
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
/* list group items in status.ejs */
|
||||
.list-group-item {
|
||||
background-color: #3A3A3A;
|
||||
border-color: #4A4A4A;
|
||||
color: #E0E0E0;
|
||||
}
|
||||
.list-group-item:hover {
|
||||
background-color: #4A4A4A;
|
||||
}
|
||||
|
||||
/* ===============================
|
||||
FORM ELEMENTS
|
||||
=============================== */
|
||||
|
||||
.form-text {
|
||||
color: #BEBEBE !important; /* same as form label */
|
||||
}
|
||||
|
||||
.form-label {
|
||||
color: #BEBEBE;
|
||||
}
|
||||
|
||||
.form-control,
|
||||
.form-select {
|
||||
background-color: #4A4A4A;
|
||||
color: #E0E0E0;
|
||||
border: 1px solid #5A5A5A;
|
||||
}
|
||||
|
||||
.form-control:focus,
|
||||
.form-select:focus {
|
||||
border-color: #2980B9; /* same blue accent as reference */
|
||||
box-shadow: 0 0 0 0.25rem rgba(41, 128, 185, 0.25);
|
||||
}
|
||||
|
||||
/* Toggle switch label */
|
||||
.form-check-label {
|
||||
color: #BEBEBE !important;
|
||||
}
|
||||
|
||||
::placeholder {
|
||||
color: #BEBEBE !important; /* Same as label color */
|
||||
}
|
||||
|
||||
|
||||
/* ===============================
|
||||
BUTTONS
|
||||
=============================== */
|
||||
button,
|
||||
.btn {
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
/* ===== Floating Pill Toggle ===== */
|
||||
|
||||
.pill-toggle {
|
||||
position: relative;
|
||||
display: flex;
|
||||
width: 240px;
|
||||
background: #333;
|
||||
padding: 5px;
|
||||
border-radius: 30px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.pill-option {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 10px 0;
|
||||
z-index: 2;
|
||||
font-weight: 600;
|
||||
color: #aaa;
|
||||
transition: color 0.25s ease;
|
||||
}
|
||||
|
||||
.pill-option.active {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.pill-indicator {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
left: 5px;
|
||||
width: calc(50% - 5px);
|
||||
height: calc(100% - 10px);
|
||||
background: #8a190b; /* your accent red */
|
||||
border-radius: 25px;
|
||||
transition: transform 0.25s ease, background 0.25s ease;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* Hover feedback */
|
||||
.pill-option:hover {
|
||||
color: #ddd;
|
||||
}
|
||||
|
||||
|
||||
/* ===============================
|
||||
ALERTS
|
||||
=============================== */
|
||||
|
||||
.alert-danger {
|
||||
background-color: #4A1C1C;
|
||||
border-color: #8A190B;
|
||||
color: #E0E0E0;
|
||||
}
|
||||
|
||||
/* ===============================
|
||||
SCROLLBAR (dark theme)
|
||||
=============================== */
|
||||
|
||||
::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
::-webkit-scrollbar-thumb {
|
||||
background-color: #5A5A5A;
|
||||
border-radius: 4px;
|
||||
}
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background-color: #7D7D7D;
|
||||
}
|
||||
|
||||
/* ===============================
|
||||
LINKS
|
||||
=============================== */
|
||||
|
||||
a {
|
||||
color: #B04232;
|
||||
}
|
||||
a:hover {
|
||||
color: #E05D4A;
|
||||
}
|
||||
|
||||
/* ===============================
|
||||
FOOTER
|
||||
=============================== */
|
||||
|
||||
footer {
|
||||
color: #BEBEBE !important;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#logs {
|
||||
height: 60vh;
|
||||
background: #0b1220;
|
||||
color: #e6eef8;
|
||||
padding: 10px;
|
||||
font-family: monospace;
|
||||
font-size: 0.85rem;
|
||||
overflow-y: auto;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #444;
|
||||
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ===============================
|
||||
RESPONSIVE
|
||||
=============================== */
|
||||
|
||||
@media (max-width: 768px) {
|
||||
header h1 {
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
@media (max-width: 470px) {
|
||||
.main-nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); min-width: 0; width: 100%; }
|
||||
.nav-link { min-width: 0; justify-content: center; align-content: center; flex-wrap: wrap; padding: 0 6px; gap: 2px 4px; font-size: .73rem; white-space: normal; text-align: center; line-height: 1.3; }
|
||||
.nav-link.is-active::after { left: 6px; right: 6px; }
|
||||
.nav-count { font-size: .63rem; min-width: 18px; padding: 1px 4px; }
|
||||
.activity-cards { grid-auto-columns: 100%; }
|
||||
.activity-section { margin-bottom: 23px; }
|
||||
.section-heading { gap: 10px; }
|
||||
.section-heading .text-link { font-size: .72rem; }
|
||||
.section-heading h2 { font-size: .94rem; }
|
||||
.unassigned-activity .section-heading { flex-direction: column; }
|
||||
.activity-empty { align-items: start; flex-direction: column; }
|
||||
.activity-empty .button { margin-left: 0; margin-top: 6px; }
|
||||
.worker-card-empty { min-height: 40px; }
|
||||
#queue-view > .panel-header > div:first-child { flex-basis: auto; }
|
||||
.recent-job { padding: 15px 18px; gap: 10px; }
|
||||
}
|
||||
@@ -0,0 +1,432 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
const MAX_VISIBLE_LOG_BYTES = 64 * 1024;
|
||||
const POLL_INTERVAL = 10_000;
|
||||
const LOG_PREFIX = '[Earlier log output omitted]\n';
|
||||
|
||||
function validWorkerName(name) {
|
||||
return typeof name === 'string' && /^[A-Za-z0-9][\w-]{0,63}$/.test(name) && name.toLowerCase() !== 'all';
|
||||
}
|
||||
|
||||
function boundedLog(text) {
|
||||
const encoder = new TextEncoder();
|
||||
const encoded = encoder.encode(text);
|
||||
if (encoded.length <= MAX_VISIBLE_LOG_BYTES) return text;
|
||||
let start = encoded.length - (MAX_VISIBLE_LOG_BYTES - encoder.encode(LOG_PREFIX).length);
|
||||
while (start < encoded.length && (encoded[start] & 0xc0) === 0x80) start++;
|
||||
return LOG_PREFIX + new TextDecoder().decode(encoded.subarray(start));
|
||||
}
|
||||
|
||||
function statusClass(status) {
|
||||
if (['online', 'running'].includes(status)) return 'status-online';
|
||||
if (['stopped', 'errored', 'offline'].includes(status)) return 'status-stopped';
|
||||
return 'status-pending';
|
||||
}
|
||||
|
||||
function startWorkerPage({ document, window, fetch, WebSocket, setTimeout, clearTimeout, AbortController }) {
|
||||
const get = id => document.getElementById(id);
|
||||
const list = get('process-list');
|
||||
if (!list) return null;
|
||||
|
||||
const elements = {
|
||||
output: get('control-output'), listState: get('worker-refresh-state'),
|
||||
empty: get('workers-empty'), count: get('worker-counts'),
|
||||
controls: get('control-centre'), placeholder: get('worker-placeholder'),
|
||||
createForm: get('create-worker-form'), nameInput: get('worker-name'),
|
||||
logs: get('logs'), follow: get('follow-logs'), connection: get('log-connection-state'),
|
||||
reconnect: get('reconnect-logs'), refresh: get('refresh-list'),
|
||||
quickAdd: get('btn-quick-add'),
|
||||
};
|
||||
const rows = new Map();
|
||||
const records = new Map();
|
||||
let selectedKey = null;
|
||||
let commandInFlight = false;
|
||||
let listRequest = null;
|
||||
let pollTimer = null;
|
||||
let socket = null;
|
||||
let socketGeneration = 0;
|
||||
let connectionTimer = null;
|
||||
let connecting = false;
|
||||
let disposed = false;
|
||||
|
||||
const keyFor = worker => `${worker.pm_id}:${worker.name}`;
|
||||
const selected = () => selectedKey ? records.get(selectedKey) : null;
|
||||
const string = value => value == null ? '—' : String(value);
|
||||
|
||||
function text(id, value) { get(id).textContent = string(value); }
|
||||
|
||||
function showResult(message, state = '') {
|
||||
elements.output.textContent = message;
|
||||
elements.output.hidden = !message;
|
||||
elements.output.classList.toggle('is-error', state === 'error');
|
||||
elements.output.classList.toggle('is-success', state === 'success');
|
||||
}
|
||||
|
||||
function updateButtons() {
|
||||
const worker = selected();
|
||||
const online = worker && ['online', 'running', 'launching'].includes(worker.status);
|
||||
get('btn-create').disabled = commandInFlight;
|
||||
elements.quickAdd.disabled = commandInFlight;
|
||||
elements.nameInput.disabled = commandInFlight;
|
||||
get('clear-selection').disabled = commandInFlight;
|
||||
elements.refresh.disabled = commandInFlight || !!listRequest;
|
||||
for (const cmd of ['start', 'stop', 'restart', 'delete']) {
|
||||
get(`btn-${cmd}`).disabled = commandInFlight || !worker
|
||||
|| (cmd === 'start' && online) || (cmd === 'stop' && worker.status === 'stopped');
|
||||
}
|
||||
for (const [key, row] of rows) {
|
||||
row.disabled = commandInFlight || !validWorkerName(records.get(key)?.name);
|
||||
row.classList.toggle('is-selected', key === selectedKey);
|
||||
row.setAttribute('aria-pressed', String(key === selectedKey));
|
||||
}
|
||||
elements.reconnect.disabled = !worker || connecting;
|
||||
}
|
||||
|
||||
function populateControls() {
|
||||
const worker = selected();
|
||||
elements.controls.hidden = !worker;
|
||||
elements.placeholder.hidden = !!worker;
|
||||
if (worker) {
|
||||
text('cc-name', worker.name);
|
||||
text('cc-sub', `PM2 ${worker.pm_id} · ${worker.status}`);
|
||||
for (const [id, field] of Object.entries({
|
||||
'detail-pmid': 'pm_id', 'detail-pid': 'pid', 'detail-status': 'status',
|
||||
'detail-cpu': 'cpu', 'detail-mem': 'memoryMB', 'detail-uptime': 'uptime', 'detail-exec': 'execPath',
|
||||
})) text(id, worker[field]);
|
||||
}
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
function appendLog(message) {
|
||||
const value = String(message ?? '');
|
||||
const line = `[${new Date().toLocaleTimeString()}] ${value}${value.endsWith('\n') ? '' : '\n'}`;
|
||||
elements.logs.textContent = boundedLog(elements.logs.textContent + line);
|
||||
if (elements.follow.checked) elements.logs.scrollTop = elements.logs.scrollHeight;
|
||||
}
|
||||
|
||||
function closeSocket() {
|
||||
socketGeneration++;
|
||||
clearTimeout(connectionTimer);
|
||||
connectionTimer = null;
|
||||
connecting = false;
|
||||
const previous = socket;
|
||||
socket = null;
|
||||
if (!previous) return;
|
||||
try {
|
||||
if (previous.readyState === WebSocket.OPEN) previous.send(JSON.stringify({ type: 'stop-logs' }));
|
||||
previous.close();
|
||||
} catch { /* The old connection is already closed. */ }
|
||||
}
|
||||
|
||||
function openLogs(clear = false) {
|
||||
closeSocket();
|
||||
const worker = selected();
|
||||
if (!worker || disposed) return;
|
||||
const generation = socketGeneration;
|
||||
const workerKey = selectedKey;
|
||||
if (clear) elements.logs.textContent = `Connecting to ${worker.name}…\n`;
|
||||
connecting = true;
|
||||
elements.connection.textContent = 'Connecting…';
|
||||
updateButtons();
|
||||
let current;
|
||||
try {
|
||||
current = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}`);
|
||||
} catch {
|
||||
connecting = false;
|
||||
elements.connection.textContent = 'Log connection unavailable';
|
||||
updateButtons();
|
||||
return;
|
||||
}
|
||||
socket = current;
|
||||
const active = () => !disposed && socket === current && socketGeneration === generation && selectedKey === workerKey;
|
||||
connectionTimer = setTimeout(() => {
|
||||
if (!active() || current.readyState === WebSocket.OPEN) return;
|
||||
closeSocket();
|
||||
elements.connection.textContent = 'Connection timed out — reconnect to try again';
|
||||
updateButtons();
|
||||
}, 10_000);
|
||||
current.addEventListener('open', () => {
|
||||
if (!active()) return;
|
||||
clearTimeout(connectionTimer);
|
||||
connecting = false;
|
||||
try {
|
||||
current.send(JSON.stringify({ type: 'logs', name: worker.name }));
|
||||
elements.connection.textContent = `Connected to ${worker.name}`;
|
||||
} catch {
|
||||
elements.connection.textContent = 'Log request could not be sent — reconnect to try again';
|
||||
}
|
||||
updateButtons();
|
||||
});
|
||||
current.addEventListener('message', event => {
|
||||
if (!active()) return;
|
||||
let payload;
|
||||
try { payload = JSON.parse(event.data); } catch { return; }
|
||||
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return;
|
||||
if (['stdout', 'stderr'].includes(payload.type)) appendLog(payload.data || '');
|
||||
else if (payload.type === 'info') appendLog(`[info] ${payload.message || ''}`);
|
||||
else if (payload.type === 'error') {
|
||||
elements.connection.textContent = 'Log stream unavailable — reconnect to try again';
|
||||
appendLog(`[error] ${payload.error || 'The log stream failed.'}`);
|
||||
} else if (payload.type === 'close') {
|
||||
elements.connection.textContent = 'Log stream ended — reconnect to continue';
|
||||
appendLog('[Log stream ended]');
|
||||
}
|
||||
});
|
||||
const disconnected = () => {
|
||||
if (!active()) return;
|
||||
clearTimeout(connectionTimer);
|
||||
connecting = false;
|
||||
elements.connection.textContent = 'Disconnected — reconnect to continue';
|
||||
updateButtons();
|
||||
};
|
||||
current.addEventListener('close', disconnected);
|
||||
current.addEventListener('error', disconnected);
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
selectedKey = null;
|
||||
closeSocket();
|
||||
elements.connection.textContent = 'No worker selected';
|
||||
elements.logs.textContent = 'Select a worker to view its logs.';
|
||||
populateControls();
|
||||
}
|
||||
|
||||
function selectWorker(key) {
|
||||
if (commandInFlight || !records.has(key) || !validWorkerName(records.get(key).name)) return;
|
||||
if (selectedKey === key) return;
|
||||
selectedKey = key;
|
||||
populateControls();
|
||||
openLogs(true);
|
||||
}
|
||||
|
||||
function makeElement(tag, className, value) {
|
||||
const node = document.createElement(tag);
|
||||
if (className) node.className = className;
|
||||
if (value !== undefined) node.textContent = string(value);
|
||||
return node;
|
||||
}
|
||||
|
||||
function createRow(worker) {
|
||||
const item = makeElement('li', 'worker-list-item');
|
||||
const row = makeElement('button', 'worker-row');
|
||||
row.type = 'button';
|
||||
const heading = makeElement('span', 'worker-row-heading');
|
||||
heading.append(makeElement('strong', 'worker-name'));
|
||||
const badge = makeElement('span', 'badge');
|
||||
badge.dataset.workerStatus = '';
|
||||
heading.append(badge);
|
||||
const meta = makeElement('span', 'worker-row-meta');
|
||||
meta.dataset.workerMetrics = '';
|
||||
row.append(heading, meta);
|
||||
item.append(row);
|
||||
row.dataset.key = keyFor(worker);
|
||||
row.addEventListener('click', () => selectWorker(row.dataset.key));
|
||||
list.append(item);
|
||||
return row;
|
||||
}
|
||||
|
||||
function renderWorkers(workers) {
|
||||
const present = new Set();
|
||||
for (const worker of workers) {
|
||||
const key = keyFor(worker);
|
||||
present.add(key);
|
||||
records.set(key, worker);
|
||||
let row = rows.get(key);
|
||||
if (!row) { row = createRow(worker); rows.set(key, row); }
|
||||
row.dataset.name = string(worker.name);
|
||||
row.querySelector('.worker-name').textContent = string(worker.name);
|
||||
const badge = row.querySelector('[data-worker-status]');
|
||||
badge.textContent = string(worker.status);
|
||||
badge.className = `badge ${statusClass(worker.status)}`;
|
||||
row.querySelector('[data-worker-metrics]').textContent = `CPU ${string(worker.cpu)} · ${string(worker.memoryMB)} · ${string(worker.uptime)}`;
|
||||
}
|
||||
for (const [key, row] of rows) {
|
||||
if (!present.has(key)) {
|
||||
row.parentElement.remove();
|
||||
rows.delete(key);
|
||||
records.delete(key);
|
||||
}
|
||||
}
|
||||
elements.empty.hidden = workers.length > 0;
|
||||
const online = workers.filter(worker => ['online', 'running'].includes(worker.status)).length;
|
||||
elements.count.textContent = `${online} online · ${workers.length} total`;
|
||||
if (selectedKey && !records.has(selectedKey)) {
|
||||
clearSelection();
|
||||
if (!commandInFlight) showResult('The selected worker is no longer available. Choose another worker.');
|
||||
}
|
||||
populateControls();
|
||||
}
|
||||
|
||||
async function requestJson(url, options = {}, timeout = 12_000) {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), timeout);
|
||||
try {
|
||||
const response = await fetch(url, { ...options, cache: 'no-store', signal: controller.signal });
|
||||
const result = await response.json();
|
||||
return { response, result };
|
||||
} finally { clearTimeout(timer); }
|
||||
}
|
||||
|
||||
function schedulePoll() {
|
||||
clearTimeout(pollTimer);
|
||||
if (!disposed && !document.hidden) {
|
||||
pollTimer = setTimeout(async () => {
|
||||
if (!commandInFlight) await refreshList();
|
||||
schedulePoll();
|
||||
}, POLL_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
function refreshList() {
|
||||
if (disposed) return Promise.resolve(false);
|
||||
if (listRequest) return listRequest;
|
||||
listRequest = (async () => {
|
||||
try {
|
||||
const { response, result } = await requestJson('/pm2/list-json');
|
||||
if (!response.ok || !result?.ok || !Array.isArray(result.processes)) throw new Error('List unavailable');
|
||||
if (disposed) return false;
|
||||
renderWorkers(result.processes);
|
||||
elements.listState.textContent = `Updated ${new Date().toLocaleTimeString()}`;
|
||||
return true;
|
||||
} catch {
|
||||
if (!disposed) elements.listState.textContent = 'Could not refresh workers. Showing the last available list.';
|
||||
return false;
|
||||
} finally {
|
||||
listRequest = null;
|
||||
if (!disposed) updateButtons();
|
||||
}
|
||||
})();
|
||||
updateButtons();
|
||||
return listRequest;
|
||||
}
|
||||
|
||||
async function execCommand(command, name) {
|
||||
const automatic = command === 'quick-add';
|
||||
const creating = automatic || command === 'create';
|
||||
if (disposed || commandInFlight || (!automatic && !validWorkerName(name))) return false;
|
||||
commandInFlight = true;
|
||||
updateButtons();
|
||||
showResult(automatic ? 'Creating the next numbered worker…' : `${creating ? 'Creating' : 'Updating'} ${name}…`);
|
||||
try {
|
||||
// Let any earlier read finish before mutating so stale list responses
|
||||
// cannot replace the result of this command.
|
||||
if (listRequest) await listRequest;
|
||||
if (disposed) return false;
|
||||
const { response, result } = await requestJson(automatic ? '/pm2/quick-add' : '/pm2/command', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(automatic ? {} : { cmd: command, name }),
|
||||
}, automatic ? 45_000 : 15_000);
|
||||
if (disposed) return false;
|
||||
if (!response.ok || !result?.ok) {
|
||||
showResult(String(result?.error || result?.message || 'The worker command could not be completed.').slice(0, 500), 'error');
|
||||
return false;
|
||||
}
|
||||
if (automatic) {
|
||||
if (!validWorkerName(result.name) || !/^proxer-worker-\d+$/.test(result.name)) {
|
||||
showResult('The worker command completed, but its name could not be confirmed. Refresh the worker list before trying again.', 'error');
|
||||
await refreshList();
|
||||
return false;
|
||||
}
|
||||
name = result.name;
|
||||
}
|
||||
showResult(command === 'delete' ? `${name} was deleted.`
|
||||
: creating ? `${name} was created and started.` : `${name}: ${command} completed.`, 'success');
|
||||
const refreshed = await refreshList();
|
||||
if (!refreshed) showResult('The command completed, but the worker list could not be refreshed. Refresh it before your next action.', 'error');
|
||||
if (creating && refreshed) {
|
||||
const created = [...records.entries()].find(([, worker]) => worker.name === name);
|
||||
if (created) {
|
||||
selectedKey = created[0];
|
||||
populateControls();
|
||||
openLogs(true);
|
||||
}
|
||||
if (!automatic) elements.nameInput.value = '';
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
if (!disposed) showResult('Could not confirm the worker command. Refresh the worker list before trying again.', 'error');
|
||||
return false;
|
||||
} finally {
|
||||
commandInFlight = false;
|
||||
if (!disposed) updateButtons();
|
||||
}
|
||||
}
|
||||
|
||||
for (const row of list.querySelectorAll('.worker-row')) {
|
||||
const data = row.dataset;
|
||||
const worker = { name: data.name, pm_id: data.pmid, pid: data.pid, status: data.status,
|
||||
cpu: data.cpu, memoryMB: data.memory, uptime: data.uptime, execPath: data.exec };
|
||||
const key = keyFor(worker);
|
||||
records.set(key, worker);
|
||||
rows.set(key, row);
|
||||
row.addEventListener('click', () => selectWorker(key));
|
||||
}
|
||||
elements.createForm.addEventListener('submit', async event => {
|
||||
event.preventDefault();
|
||||
if (commandInFlight) return;
|
||||
const name = elements.nameInput.value.trim();
|
||||
elements.nameInput.value = name;
|
||||
const inUse = [...records.values()].some(worker => worker.name === name);
|
||||
elements.nameInput.setCustomValidity(!validWorkerName(name)
|
||||
? 'Use 1–64 letters, numbers, underscores or hyphens, starting with a letter or number. “all” is reserved.'
|
||||
: inUse ? 'A worker with that name already exists.' : '');
|
||||
if (!elements.createForm.reportValidity()) return;
|
||||
await execCommand('create', name);
|
||||
});
|
||||
elements.nameInput.addEventListener('input', () => elements.nameInput.setCustomValidity(''));
|
||||
elements.quickAdd.addEventListener('click', () => execCommand('quick-add'));
|
||||
|
||||
const confirmations = {
|
||||
stop: name => `Stop ${name}? An active download may be interrupted.`,
|
||||
restart: name => `Restart ${name}? An active download may be interrupted.`,
|
||||
delete: name => `Delete ${name} from the worker list? This stops the worker and may interrupt an active download. Downloaded files are kept.`,
|
||||
};
|
||||
for (const command of ['start', 'stop', 'restart', 'delete']) {
|
||||
get(`btn-${command}`).addEventListener('click', () => {
|
||||
const worker = selected();
|
||||
if (!worker || commandInFlight) return;
|
||||
if (confirmations[command] && !window.confirm(confirmations[command](worker.name))) return;
|
||||
execCommand(command, worker.name);
|
||||
});
|
||||
}
|
||||
get('clear-selection').addEventListener('click', () => { if (!commandInFlight) clearSelection(); });
|
||||
elements.refresh.addEventListener('click', () => { refreshList(); });
|
||||
elements.reconnect.addEventListener('click', () => openLogs(false));
|
||||
get('clear-logs').addEventListener('click', () => { elements.logs.textContent = ''; });
|
||||
elements.follow.addEventListener('change', () => {
|
||||
if (elements.follow.checked) elements.logs.scrollTop = elements.logs.scrollHeight;
|
||||
});
|
||||
elements.logs.addEventListener('scroll', () => {
|
||||
if (elements.logs.scrollHeight - elements.logs.scrollTop - elements.logs.clientHeight > 40) elements.follow.checked = false;
|
||||
});
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
clearTimeout(pollTimer);
|
||||
if (!document.hidden) {
|
||||
if (!commandInFlight) refreshList();
|
||||
schedulePoll();
|
||||
}
|
||||
});
|
||||
function dispose() {
|
||||
disposed = true;
|
||||
clearTimeout(pollTimer);
|
||||
closeSocket();
|
||||
}
|
||||
window.addEventListener('pagehide', dispose);
|
||||
window.addEventListener('pageshow', event => {
|
||||
if (event.persisted) window.location.reload();
|
||||
});
|
||||
populateControls();
|
||||
schedulePoll();
|
||||
return { refreshList, execCommand, selectWorker, clearSelection, appendLog, dispose };
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = { startWorkerPage, validWorkerName, boundedLog, statusClass, MAX_VISIBLE_LOG_BYTES };
|
||||
}
|
||||
if (typeof document !== 'undefined' && document.getElementById('process-list')) {
|
||||
startWorkerPage({ document, window, fetch: window.fetch.bind(window), WebSocket: window.WebSocket,
|
||||
setTimeout: window.setTimeout.bind(window), clearTimeout: window.clearTimeout.bind(window),
|
||||
AbortController: window.AbortController });
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user