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,33 @@
|
||||
<%- include('partials/header', { title: 'Dashboard', activePage: 'dashboard' }) %>
|
||||
<%
|
||||
const overview = {
|
||||
queued: ['Waiting', 'Ready for a worker'], processing: ['Active', 'Claimed downloads'],
|
||||
done: ['Completed', 'Successful downloads'], failed: ['Failed attempts', 'Review attempt history']
|
||||
};
|
||||
const recentRows = typeof recent === 'object' && recent ? recent : { done: [], failed: [] };
|
||||
%>
|
||||
<div class="page-heading">
|
||||
<div><p class="eyebrow">DOWNLOAD OVERVIEW</p><h1 class="page-title">Dashboard</h1><p class="page-description">Your workers, current downloads and latest results in one place.</p></div>
|
||||
<div class="button-group"><button type="button" class="button button-secondary" id="dashboard-refresh">Refresh</button><a class="button button-primary" href="/download">New download <span aria-hidden="true">→</span></a></div>
|
||||
</div>
|
||||
<%- include('partials/active-downloads') %>
|
||||
<nav class="queue-overview dashboard-overview" aria-label="Open queue or history">
|
||||
<% Object.entries(overview).forEach(([state, info]) => { %>
|
||||
<a class="queue-stat" href="/status?state=<%= state %>"><span class="queue-stat-label"><%= info[0] %></span><strong class="queue-stat-count" data-dashboard-count="<%= state %>"><%= counts[state].toLocaleString('en') %></strong><span class="queue-stat-note"><%= info[1] %> <span aria-hidden="true">↗</span></span></a>
|
||||
<% }) %>
|
||||
</nav>
|
||||
<p class="dashboard-feedback field-hint" id="dashboard-feedback" role="status" aria-live="polite">Updates every 10 seconds while this page is visible.</p>
|
||||
<div class="dashboard-history">
|
||||
<% ['done', 'failed'].forEach(state => { %>
|
||||
<section class="panel" aria-labelledby="recent-<%= state %>-title">
|
||||
<div class="panel-header"><div><h2 id="recent-<%= state %>-title"><%= state === 'done' ? 'Recently completed' : 'Recent failed attempts' %></h2><p class="field-hint">Latest five records</p></div><a class="text-link" href="/status?state=<%= state %>">View history <span aria-hidden="true">↗</span></a></div>
|
||||
<ul class="recent-list" id="recent-<%= state %>"><% recentRows[state].forEach(job => { const stamp = job[state === 'done' ? 'finished_at' : 'failed_at'] || job.created_at; %>
|
||||
<li class="recent-job" data-recent-id="<%= job._id %>"><div class="recent-primary"><strong class="recent-name"><%= job.filename %></strong><time class="muted"<% if (stamp) { %> datetime="<%= stamp %>"<% } %>><%= stamp ? new Date(stamp).toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' }) : 'Time not recorded' %></time></div><span class="badge <%= state === 'done' ? 'badge-success' : 'badge-danger' %>"><%= state === 'done' ? 'Completed' : job.error_category || 'Failed' %></span></li>
|
||||
<% }) %></ul>
|
||||
<div class="empty-state recent-empty" id="recent-<%= state %>-empty"<%- recentRows[state].length ? ' hidden' : '' %>><strong><%= state === 'done' ? 'No completed downloads yet' : 'No failed attempts recorded' %></strong><p><%= state === 'done' ? 'Completed episodes will appear here.' : 'Any failed attempts will appear here for review.' %></p></div>
|
||||
<% if (state === 'failed') { %><p class="history-footnote field-hint">An earlier failed attempt may belong to an episode that later completed.</p><% } %>
|
||||
</section>
|
||||
<% }) %>
|
||||
</div>
|
||||
<script src="/dashboard.js" defer></script>
|
||||
<%- include('partials/footer') %>
|
||||
+5
-13
@@ -1,13 +1,5 @@
|
||||
<%- include("partials/header") %>
|
||||
|
||||
<div class="alert alert-danger mt-4">
|
||||
<h4>Error</h4>
|
||||
|
||||
<p>
|
||||
<%= message %>
|
||||
</p>
|
||||
|
||||
<a href="/" class="btn btn-danger mt-3">Return to Home</a>
|
||||
</div>
|
||||
|
||||
<%- include("partials/footer") %>
|
||||
<%- include('partials/header') %>
|
||||
<section class="panel error-panel" aria-labelledby="error-title">
|
||||
<div class="panel-body"><p class="eyebrow">REQUEST NEEDS ATTENTION</p><h1 class="page-title" id="error-title"><%= typeof title === 'string' && title ? title : 'Unable to complete this request' %></h1><p class="page-description"><%= typeof message === 'string' ? message : 'Please try again.' %></p><div class="button-group"><a href="/download" class="button button-primary">New download</a><a href="/status" class="button button-secondary">View queue</a></div></div>
|
||||
</section>
|
||||
<%- include('partials/footer') %>
|
||||
+72
-143
@@ -1,153 +1,82 @@
|
||||
<%- include("partials/header") %>
|
||||
<%
|
||||
const formValues = typeof values === 'object' && values ? values : {};
|
||||
const selectedMode = formValues.mode === 'video' ? 'video' : 'series';
|
||||
const isSeries = selectedMode === 'series';
|
||||
const episodeLimit = typeof maxSeriesEpisodes === 'number' ? maxSeriesEpisodes : 500;
|
||||
const destination = typeof outputDir === 'string' ? outputDir : 'Configured media folder';
|
||||
const submissionError = typeof formError === 'string' ? formError : '';
|
||||
const savedToken = typeof tokenStatus === 'object' && tokenStatus ? tokenStatus : { available: false, state: 'unknown' };
|
||||
const languages = [['engsub', 'English subtitles'], ['engdub', 'English dub'], ['gersub', 'German subtitles'], ['gerdub', 'German dub']];
|
||||
%>
|
||||
<%- include('partials/header', { activePage: 'download' }) %>
|
||||
|
||||
<div class="card card-dark p-4">
|
||||
<!-- MODE TOGGLE -->
|
||||
<div class="d-flex justify-content-center mb-4">
|
||||
<div class="pill-toggle">
|
||||
<div class="pill-option active" id="pillSeries">Series</div>
|
||||
<div class="pill-option" id="pillVideo">Video</div>
|
||||
<div class="pill-indicator" id="pillIndicator"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form method="POST" action="/queue" id="jobForm">
|
||||
<input type="hidden" name="mode" id="modeInput" value="series" />
|
||||
|
||||
<!-- ===================== -->
|
||||
<!-- 1. ID / URL -->
|
||||
<!-- ===================== -->
|
||||
|
||||
<!-- SERIES: ID -->
|
||||
<div id="seriesFields">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">ID</label>
|
||||
<input
|
||||
class="form-control"
|
||||
name="id"
|
||||
type="number"
|
||||
placeholder="ID"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- VIDEO: URL -->
|
||||
<div id="videoFields" style="display: none">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">URL</label>
|
||||
<input
|
||||
class="form-control"
|
||||
name="url"
|
||||
placeholder="https://proxer.me/watch/..."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===================== -->
|
||||
<!-- 2. TITEL (shared) -->
|
||||
<!-- ===================== -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Title / filename</label>
|
||||
<input
|
||||
class="form-control"
|
||||
name="name"
|
||||
placeholder="Title S01E01"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- ===================== -->
|
||||
<!-- 3. LANGUAGE (shared) -->
|
||||
<!-- ===================== -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Language</label>
|
||||
<select class="form-select" name="language">
|
||||
<option value="engsub">EngSub</option>
|
||||
<option value="engdub">EngDub</option>
|
||||
<option value="gersub">GerSub</option>
|
||||
<option value="gerdub">GerDub</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- ===================== -->
|
||||
<!-- 4. EPISODES (series only) -->
|
||||
<!-- ===================== -->
|
||||
<div id="seriesEpisodes">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Episodes</label>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<input
|
||||
class="form-control"
|
||||
name="episode_from"
|
||||
type="number"
|
||||
min="1"
|
||||
placeholder="From"
|
||||
/>
|
||||
</div>
|
||||
<div class="col">
|
||||
<input
|
||||
class="form-control"
|
||||
name="episode_to"
|
||||
type="number"
|
||||
min="1"
|
||||
placeholder="To"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===================== -->
|
||||
<!-- 5. TOKEN (shared) -->
|
||||
<!-- ===================== -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Token</label>
|
||||
<input
|
||||
class="form-control"
|
||||
name="token"
|
||||
type="password"
|
||||
autocomplete="off"
|
||||
required
|
||||
placeholder="Token"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- ACTIONS -->
|
||||
<div class="d-flex justify-content-between">
|
||||
<button class="btn btn-danger">Queue Download</button>
|
||||
<a class="btn btn-outline-light" href="/status">View Queue</a>
|
||||
</div>
|
||||
</form>
|
||||
<div class="page-heading">
|
||||
<div><p class="eyebrow">YOUR DOWNLOAD LIBRARY</p><h1 class="page-title">New download</h1><p class="page-description">Queue a series or a single episode. Your workers take it from here.</p></div>
|
||||
<a class="button button-secondary" href="/status">View queue <span aria-hidden="true">↗</span></a>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const indicator = document.getElementById("pillIndicator");
|
||||
const btnSeries = document.getElementById("pillSeries");
|
||||
const btnVideo = document.getElementById("pillVideo");
|
||||
<div class="download-layout">
|
||||
<section class="panel">
|
||||
<div class="panel-header"><h2>Download details</h2><span class="muted small">Fields marked * are required</span></div>
|
||||
<form method="POST" action="/queue" id="jobForm" class="panel-body download-form" data-max-episodes="<%= episodeLimit %>">
|
||||
<% if (submissionError) { %>
|
||||
<div id="form-error" class="inline-notice notice-warning" role="alert" tabindex="-1"><strong>Download not added</strong><p><%= submissionError %></p><p class="small">Your download details are kept below. Token values are never shown again; leave the field blank to try the saved token or paste a replacement.</p></div>
|
||||
<% } %>
|
||||
|
||||
const modeInput = document.getElementById("modeInput");
|
||||
const seriesFields = document.getElementById("seriesFields");
|
||||
const seriesEpisodes = document.getElementById("seriesEpisodes");
|
||||
const videoFields = document.getElementById("videoFields");
|
||||
<fieldset class="mode-switch" id="download-mode" hidden>
|
||||
<legend class="visually-hidden">Download mode</legend>
|
||||
<label class="mode-choice"><input type="radio" name="mode" value="series" aria-controls="series-fields"<%- isSeries ? ' checked' : '' %>><span><strong>Series</strong><small>A range of episodes</small></span></label>
|
||||
<label class="mode-choice"><input type="radio" name="mode" value="video" aria-controls="video-fields"<%- !isSeries ? ' checked' : '' %>><span><strong>Single episode</strong><small>One Proxer watch URL</small></span></label>
|
||||
</fieldset>
|
||||
<noscript><div class="inline-notice">Current mode: <strong><%= isSeries ? 'Series' : 'Single episode' %></strong>. Switch to <a href="/download?mode=series">Series</a> or <a href="/download?mode=video">Single episode</a> before filling out this form.</div></noscript>
|
||||
|
||||
function updateMode(mode) {
|
||||
const isSeries = mode === "series";
|
||||
<fieldset id="series-fields" class="form-section"<%- isSeries ? '' : ' hidden disabled' %>>
|
||||
<legend class="section-label">01 <span>Choose your episodes</span></legend>
|
||||
<div class="form-grid">
|
||||
<div class="field"><label class="field-label" for="series-id">Series ID <span aria-hidden="true">*</span></label><input class="field-input" id="series-id" name="id" type="number" inputmode="numeric" min="1" max="9007199254740991" step="1" value="<%= formValues.id || '' %>" placeholder="e.g. 12345" required aria-describedby="series-id-hint"><p class="field-hint" id="series-id-hint">The numeric ID in the Proxer series or watch URL.</p></div>
|
||||
<div class="field"><label class="field-label" for="language">Language <span aria-hidden="true">*</span></label><select class="field-input" id="language" name="language" required><% languages.forEach(([value, label]) => { %><option value="<%= value %>"<%- (formValues.language || 'engsub') === value ? ' selected' : '' %>><%= label %></option><% }) %></select></div>
|
||||
<div class="field season-field"><label class="field-label" for="series-season">Season <span aria-hidden="true">*</span></label><input class="field-input" id="series-season" name="season" type="number" inputmode="numeric" min="0" max="9007199254740991" step="1" value="<%= formValues.season ?? '1' %>" required aria-describedby="season-hint"><p class="field-hint" id="season-hint">Used in the filename only. Use 0 for specials. Episode numbers still follow the Proxer source.</p></div>
|
||||
<div class="field"><label class="field-label" for="episode-from">First episode <span aria-hidden="true">*</span></label><input class="field-input" id="episode-from" name="episode_from" type="number" inputmode="numeric" min="1" max="9007199254740991" step="1" value="<%= formValues.episode_from || '' %>" placeholder="1" required></div>
|
||||
<div class="field"><label class="field-label" for="episode-to">Last episode <span aria-hidden="true">*</span></label><input class="field-input" id="episode-to" name="episode_to" type="number" inputmode="numeric" min="1" max="9007199254740991" step="1" value="<%= formValues.episode_to || '' %>" placeholder="12" required aria-describedby="episode-limit"><p class="field-hint" id="episode-limit">Both ends included. Up to <%= episodeLimit.toLocaleString('en') %> episodes per submission.</p></div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
indicator.style.transform = isSeries
|
||||
? "translateX(0)"
|
||||
: "translateX(100%)";
|
||||
<fieldset id="video-fields" class="form-section"<%- isSeries ? ' hidden disabled' : '' %>>
|
||||
<legend class="section-label">01 <span>Choose your episode</span></legend>
|
||||
<div class="field"><label class="field-label" for="episode-url">Proxer episode URL <span aria-hidden="true">*</span></label><input class="field-input" id="episode-url" name="url" type="url" inputmode="url" value="<%= formValues.url || '' %>" maxlength="2048" placeholder="https://proxer.me/watch/12345/1/engsub" spellcheck="false" required aria-describedby="episode-url-hint"><p class="field-hint" id="episode-url-hint">Use the HTTPS watch URL. The episode and language are taken from this link.</p></div>
|
||||
</fieldset>
|
||||
|
||||
btnSeries.classList.toggle("active", isSeries);
|
||||
btnVideo.classList.toggle("active", !isSeries);
|
||||
<section class="form-section" aria-labelledby="filename-heading">
|
||||
<h3 class="section-label" id="filename-heading">02 <span>Name your files</span></h3>
|
||||
<div class="field"><label class="field-label" for="download-name"><span id="name-label"><%= isSeries ? 'Series title' : 'Filename' %></span> <span class="optional">Optional</span></label><input class="field-input" id="download-name" name="name" value="<%= formValues.name || '' %>" maxlength="255" placeholder="<%= isSeries ? 'e.g. My Series' : 'e.g. My SeriesS001E001_engsub' %>" aria-describedby="name-hint"><p class="field-hint" id="name-hint"><%= isSeries ? '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.' %></p></div>
|
||||
</section>
|
||||
|
||||
modeInput.value = mode;
|
||||
<section class="form-section" aria-labelledby="access-heading">
|
||||
<h3 class="section-label" id="access-heading">03 <span>Provide access</span></h3>
|
||||
<div class="token-cache-status" id="token-cache-status" data-state="<%= savedToken.state %>">
|
||||
<span class="badge <%= savedToken.available ? 'badge-success' : savedToken.state === 'invalid' ? 'badge-warning' : 'badge-neutral' %>"><%= savedToken.available ? 'Token saved' : savedToken.state === 'invalid' ? 'Replacement needed' : savedToken.state === 'missing' ? 'No token saved' : 'Saved token checked on submission' %></span>
|
||||
<p class="field-hint"><%= savedToken.available ? 'Leave the field blank to reuse it. Download access is checked again every time you add to the queue.' : savedToken.state === 'invalid' ? 'The saved token was rejected. Paste a fresh token to continue.' : savedToken.state === 'missing' ? 'Paste a token once. After a successful access check, it is saved for future submissions.' : savedToken.state === 'unavailable' ? 'Saved-token status is unavailable. Submission will retry the check before adding any jobs.' : 'Leave blank to try the saved token, or paste a replacement.' %></p>
|
||||
<% if (savedToken.lastValidatedAt && Number.isFinite(new Date(savedToken.lastValidatedAt).getTime())) { %><p class="field-hint">Last access check: <time datetime="<%= savedToken.lastValidatedAt %>" id="token-checked-at"><%= new Date(savedToken.lastValidatedAt).toLocaleString('en-GB', { dateStyle: 'medium', timeStyle: 'short' }) %></time></p><% } %>
|
||||
</div>
|
||||
<div class="field"><label class="field-label" for="download-token">Session token <span class="optional">Leave blank to reuse saved token</span></label><div class="input-with-action"><input class="field-input" id="download-token" name="token" type="password" autocomplete="off" autocapitalize="none" spellcheck="false" maxlength="8192" placeholder="Paste a new token value" aria-describedby="token-hint"><button type="button" class="input-action" id="toggle-token" aria-pressed="false" aria-controls="download-token" hidden>Show</button></div><p class="field-hint" id="token-hint">Paste the cookie value only. A working token is stored in MongoDB and is never sent back to the browser. The first episode's source is checked before any jobs are added.</p></div>
|
||||
</section>
|
||||
|
||||
seriesFields.style.display = isSeries ? "" : "none";
|
||||
seriesEpisodes.style.display = isSeries ? "" : "none";
|
||||
videoFields.style.display = isSeries ? "none" : "";
|
||||
}
|
||||
<div class="form-actions"><button class="button button-primary" type="submit" id="queue-download">Add to queue <span aria-hidden="true">→</span></button><span class="muted small">Downloads start when a worker is available.</span></div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
btnSeries.onclick = () => updateMode("series");
|
||||
btnVideo.onclick = () => updateMode("video");
|
||||
</script>
|
||||
|
||||
<%- include("partials/footer") %>
|
||||
<aside class="download-sidebar" aria-label="Download preview">
|
||||
<section class="panel preview-panel">
|
||||
<div class="panel-header"><h2>At a glance</h2><span class="badge badge-neutral" id="preview-mode"><%= isSeries ? 'Series' : 'Single episode' %></span></div>
|
||||
<div class="panel-body">
|
||||
<p class="preview-count"><strong id="preview-count">—</strong><span id="preview-count-label">episodes to queue</span></p>
|
||||
<div class="preview-section"><h3>Filename preview</h3><p class="preview-filename" id="filename-preview">Fill in the episode details to see your filenames.</p><p class="field-hint" id="preview-last" hidden></p></div>
|
||||
<div class="preview-section"><h3>Save location</h3><p class="destination-path"><%= destination %></p><p class="field-hint">Files are saved as MP4.</p></div>
|
||||
<p class="preview-validation" id="preview-validation" aria-live="polite"></p>
|
||||
</div>
|
||||
</section>
|
||||
<section class="help-card"><span class="help-icon" aria-hidden="true">i</span><div><h2>If verification is needed</h2><p>Downloads pause and keep the affected episode in the queue. Complete verification on Proxer, then use <strong>Resume after verification</strong> to retry.</p></div></section>
|
||||
</aside>
|
||||
</div>
|
||||
<script src="/download.js" defer></script>
|
||||
<%- include('partials/footer') %>
|
||||
@@ -0,0 +1,38 @@
|
||||
<%
|
||||
const live = typeof activity === 'object' && activity ? activity : { workers: [], unassigned: [], available: false };
|
||||
const paused = typeof global === 'object' && global?.captcha_blocked === true;
|
||||
const currentWorkers = Array.isArray(live.workers) ? live.workers : [];
|
||||
const unknownJobs = Array.isArray(live.unassigned) ? live.unassigned : [];
|
||||
const liveSource = value => typeof value === 'string' && /^https:\/\/proxer\.me\/watch\/[1-9]\d*\/[1-9]\d*\/(engsub|engdub|gersub|gerdub)$/.test(value) ? value : '';
|
||||
const liveBytes = value => {
|
||||
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) return 'Size unavailable';
|
||||
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
|
||||
const n = value ? Math.min(Math.floor(Math.log(value) / Math.log(1024)), 4) : 0;
|
||||
return (value / 1024 ** n).toFixed(n ? 1 : 0) + ' ' + units[n] + ' on disk';
|
||||
};
|
||||
const workerState = worker => worker.jobs.length ? 'Active' : worker.status !== 'online'
|
||||
? (worker.status === 'errored' ? 'Error' : worker.status === 'stopped' ? 'Stopped' : 'Not ready')
|
||||
: worker.activityUnknown ? 'Activity unknown' : paused ? 'Paused' : 'Idle';
|
||||
%>
|
||||
<section class="activity-section" id="current-downloads" aria-labelledby="activity-title">
|
||||
<div class="section-heading"><div><h2 id="activity-title">Current downloads</h2><p class="field-hint" id="activity-freshness">Current claims by worker · refreshes with this page</p></div><a class="text-link" href="/pm2" id="activity-manage">Manage workers <span aria-hidden="true">↗</span></a></div>
|
||||
<p class="inline-notice notice-warning activity-warning" id="activity-warning"<%- live.available && !live.truncated && !live.workersTruncated ? ' hidden' : '' %>><%= !live.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.' %></p>
|
||||
<ul class="activity-cards" id="activity-workers" aria-label="Current download per worker. Scroll horizontally to view more workers." tabindex="0">
|
||||
<% currentWorkers.forEach(worker => { const state = workerState(worker); %>
|
||||
<li class="worker-card" data-worker-key="<%= worker.key %>">
|
||||
<div class="worker-card-heading"><strong class="worker-card-name"><%= worker.name %></strong><span class="worker-card-state badge <%= state === 'Active' ? 'badge-info' : ['Paused', 'Activity unknown'].includes(state) ? 'badge-warning' : state === 'Idle' ? 'badge-success' : 'badge-neutral' %>"><%= state %></span></div>
|
||||
<ul class="worker-card-jobs">
|
||||
<% worker.jobs.forEach(job => { %><%- include('active-job', { job, liveSource, liveBytes }) %><% }) %>
|
||||
</ul>
|
||||
<p class="worker-card-empty"<%- worker.jobs.length ? ' hidden' : '' %>><%= 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.' %></p>
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
<p class="field-hint activity-scroll-hint" id="activity-scroll-hint" hidden>Scroll sideways to view all <%= currentWorkers.length %> workers.</p>
|
||||
<div class="activity-empty" id="activity-empty"<%- currentWorkers.length ? ' hidden' : '' %>><strong><%= live.available ? 'No managed workers yet' : 'Worker inventory unavailable' %></strong><span><%= live.available ? 'Quick-add a worker to start taking queued episodes.' : 'Check the worker supervisor, then refresh.' %></span><a class="button button-secondary button-small" href="/pm2">Open workers</a></div>
|
||||
<section class="unassigned-activity" id="activity-unassigned" aria-labelledby="unassigned-title"<%- unknownJobs.length ? '' : ' hidden' %>>
|
||||
<div class="section-heading"><div><h3 id="unassigned-title">Active claims without a confirmed worker</h3><p class="field-hint">Older jobs and unavailable or restarted workers can appear here. These claims stay protected.</p></div><a class="text-link" href="/status?state=processing">View active queue</a></div>
|
||||
<ul class="unassigned-jobs" id="activity-unassigned-jobs"><% unknownJobs.forEach(job => { %><%- include('active-job', { job, liveSource, liveBytes, unassigned: true }) %><% }) %></ul>
|
||||
</section>
|
||||
</section>
|
||||
<script src="/activity.js" defer></script>
|
||||
@@ -0,0 +1,7 @@
|
||||
<% const source = liveSource(job.url); const parts = source.split('/'); const unconfirmed = typeof unassigned === 'boolean' && unassigned; %>
|
||||
<li class="active-job" data-active-job-id="<%= job._id %>">
|
||||
<strong class="active-job-name"><%= job.filename %></strong>
|
||||
<a class="active-job-source"<% if (source) { %> href="<%= source %>" target="_blank" rel="noopener noreferrer"<% } %>><%= source ? 'Series ' + parts[4] + ' · Episode ' + parts[5] + ' · ' + parts[6] : 'Source unavailable' %></a>
|
||||
<div class="active-job-metrics"><span class="active-job-size"><%= liveBytes(job.fileSize) %></span><span class="active-job-time" data-started-at="<%= job.started_at || '' %>"><%= job.started_at ? 'Started ' + new Date(job.started_at).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' }) : 'Start time unavailable' %></span></div>
|
||||
<p class="active-job-attribution field-hint"<%- unconfirmed ? '' : ' hidden' %>><%= unconfirmed && job.worker ? 'Saved worker: ' + job.worker.name + ' · live assignment unconfirmed' : unconfirmed ? 'Worker was not recorded for this claim.' : '' %></p>
|
||||
</li>
|
||||
@@ -1,5 +1,4 @@
|
||||
<footer class="mt-5 small">Built by DeSqBlocki</footer>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</main>
|
||||
<footer class="app-footer"><span>Proxer Downloader</span><span>Built by DeSqBlocki</span></footer>
|
||||
</body>
|
||||
</html>
|
||||
+38
-47
@@ -1,56 +1,47 @@
|
||||
<%
|
||||
const currentPage = typeof activePage === 'string' ? activePage : '';
|
||||
const pageTitle = typeof title === 'string' && title ? title : 'Proxer Downloader';
|
||||
const globalStatus = typeof global === 'object' && global ? global : {};
|
||||
const summaryKnown = typeof counts === 'object' && counts !== null;
|
||||
const downloadsPaused = globalStatus.captcha_blocked === true;
|
||||
const pendingCount = summaryKnown ? (Number(counts.queued) || 0) + (Number(counts.processing) || 0) : null;
|
||||
%>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Proxer-Downloader</title>
|
||||
<link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<meta name="color-scheme" content="dark">
|
||||
<title><%= pageTitle %><%= pageTitle === 'Proxer Downloader' ? '' : ' · Proxer Downloader' %></title>
|
||||
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script src="/app.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- CAPTCHA ALERT (initially hidden, will be toggled by JS) -->
|
||||
<div id="captcha-alert" class="alert alert-danger text-center m-0" style="display: <%= (typeof global !== 'undefined' && global.captcha_blocked) ? 'block' : 'none' %>;">
|
||||
<span id="captcha-message"><%= (typeof global !== 'undefined' && 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.' %></span>
|
||||
<form id="clear-captcha-form" action="/clear-captcha" method="POST" class="d-inline ms-2">
|
||||
<button class="btn btn-danger btn-sm">Resume after verification</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="container-fluid py-4" style="max-width: 2000px;">
|
||||
<!-- HEADER -->
|
||||
<header class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1>Proxer-Downloader</h1>
|
||||
<nav class="d-flex gap-2">
|
||||
<a class="btn btn-outline-light" href="/">Home</a>
|
||||
<a class="btn btn-outline-light" href="/status">Status</a>
|
||||
<a class="btn btn-outline-light" href="/pm2">PM2</a>
|
||||
<a class="skip-link" href="#main-content">Skip to content</a>
|
||||
<header class="topbar">
|
||||
<div class="topbar-inner">
|
||||
<a class="brand" href="/" aria-label="Proxer Downloader home">
|
||||
<span class="brand-mark" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none"><path d="M12 4v11m-4-4 4 4 4-4M5 17v3h14v-3" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></span>
|
||||
<span class="brand-text">Proxer<span>Downloader</span></span>
|
||||
</a>
|
||||
<nav class="main-nav" aria-label="Main navigation">
|
||||
<a href="/" class="nav-link<%= currentPage === 'dashboard' ? ' is-active' : '' %>"<%- currentPage === 'dashboard' ? ' aria-current="page"' : '' %>>Dashboard</a>
|
||||
<a href="/download" class="nav-link<%= currentPage === 'download' ? ' is-active' : '' %>"<%- currentPage === 'download' ? ' aria-current="page"' : '' %>>New download</a>
|
||||
<a href="/status" class="nav-link<%= currentPage === 'queue' ? ' is-active' : '' %>"<%- currentPage === 'queue' ? ' aria-current="page"' : '' %>>Queue <span id="nav-queue-count" class="nav-count"<%- pendingCount === null ? ' hidden' : '' %>><%= pendingCount === null ? '' : pendingCount.toLocaleString('en') %></span></a>
|
||||
<a href="/pm2" class="nav-link<%= currentPage === 'workers' ? ' is-active' : '' %>"<%- currentPage === 'workers' ? ' aria-current="page"' : '' %>>Workers</a>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<script>
|
||||
async function updateCaptchaAlert() {
|
||||
try {
|
||||
const res = await fetch('/status-data', { cache: 'no-store' });
|
||||
const data = await res.json();
|
||||
const alertEl = document.getElementById('captcha-alert');
|
||||
const messageEl = document.getElementById('captcha-message');
|
||||
|
||||
if (data.global && data.global.captcha_blocked) {
|
||||
messageEl.textContent = data.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.';
|
||||
alertEl.style.display = 'block';
|
||||
} else {
|
||||
alertEl.style.display = 'none';
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error fetching status-data:', err);
|
||||
}
|
||||
}
|
||||
|
||||
// Poll every 5 seconds
|
||||
setInterval(updateCaptchaAlert, 5000);
|
||||
</script>
|
||||
<span id="global-status" class="connection-status<%= downloadsPaused ? ' is-paused' : summaryKnown ? ' is-ready' : '' %>" role="status" aria-live="polite"><span class="status-dot" aria-hidden="true"></span><span id="global-status-text"><%= downloadsPaused ? 'Downloads paused' : summaryKnown ? 'Queue ready' : 'Checking queue…' %></span></span>
|
||||
</div>
|
||||
</header>
|
||||
<div class="notice-wrap">
|
||||
<section id="captcha-alert" class="verification-notice" aria-label="Downloads need your attention"<%- downloadsPaused ? '' : ' hidden' %>>
|
||||
<div class="notice-copy"><strong>Verification needed</strong><span id="captcha-message"><%= globalStatus.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.' %></span></div>
|
||||
<form id="clear-captcha-form" action="/clear-captcha" method="POST">
|
||||
<button type="submit" class="button button-warning button-small">Resume after verification</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
<main id="main-content" class="app-main" data-page="<%= currentPage %>" tabindex="-1">
|
||||
+125
-387
@@ -1,402 +1,140 @@
|
||||
<%- include('partials/header') %>
|
||||
<%- include('partials/header', { title: 'Workers', activePage: 'workers' }) %>
|
||||
<%
|
||||
const workerProcesses = Array.isArray(processes) ? processes : [];
|
||||
const onlineCount = workerProcesses.filter(p => ['online', 'running'].includes(p.status)).length;
|
||||
const workerStatusClass = status => ['online', 'running'].includes(status) ? 'status-online'
|
||||
: ['stopped', 'errored', 'offline'].includes(status) ? 'status-stopped' : 'status-pending';
|
||||
%>
|
||||
|
||||
<style>
|
||||
/* Dark theme PM2 CSS (integrates with your style.css) */
|
||||
.pm2-row { cursor: pointer; border: 1px solid #4A4A4A; }
|
||||
.pm2-row.active, .pm2-row.selected-outline {
|
||||
background-color: #555 !important;
|
||||
border-color: #8A190B !important;
|
||||
box-shadow: 0 0 0 2px rgba(138,25,11,0.4);
|
||||
}
|
||||
<section class="page-heading" aria-labelledby="workers-title">
|
||||
<div>
|
||||
<p class="eyebrow">Download operations</p>
|
||||
<h1 id="workers-title" class="page-title">Workers</h1>
|
||||
<p class="page-description">Manage your download workers and follow their output.</p>
|
||||
</div>
|
||||
<div class="page-actions">
|
||||
<span id="worker-counts" class="worker-counts"><%= onlineCount %> online · <%= workerProcesses.length %> total</span>
|
||||
<button id="refresh-list" class="button button-secondary" type="button" disabled>Refresh workers</button>
|
||||
<button id="btn-quick-add" class="button button-primary" type="button" disabled>Quick add worker</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
#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;
|
||||
<noscript><p class="notice">Enable JavaScript to manage workers and view live logs.</p></noscript>
|
||||
<p id="control-output" class="action-message" role="status" aria-live="polite" hidden></p>
|
||||
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
.kv-label { width: 110px; display: inline-block; color: #C0C0C0; }
|
||||
.kv-value { font-weight: bold; color: #ffffff; }
|
||||
.subtle { color: #BEBEBE; font-size: 0.85rem; }
|
||||
|
||||
.badge-small { font-size: .75rem; padding: .25rem .5rem; border-radius: .4rem; }
|
||||
</style>
|
||||
|
||||
<div class="container py-3" style="max-width:1300px;">
|
||||
|
||||
<div class="row g-3">
|
||||
|
||||
<!-- LEFT COLUMN — PROCESS LIST & CONTROL CENTRE -->
|
||||
<div class="col-md-5 d-flex">
|
||||
<div class="card-dark w-100 d-flex flex-column">
|
||||
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<div>
|
||||
<h4 class="mb-0">Downloader Workers</h4>
|
||||
<div class="subtle">Select a worker to manage it and view its logs.</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2 align-items-center">
|
||||
<button id="refresh-list" class="btn btn-sm btn-outline-light" aria-label="Refresh worker list">⟳</button>
|
||||
|
||||
<!-- NEW: ONE-CLICK CREATE -->
|
||||
<button id="btn-create" class="btn btn-sm btn-success" aria-label="Create downloader worker">
|
||||
<strong>+</strong>
|
||||
<div class="workers-layout">
|
||||
<section class="panel" aria-labelledby="worker-list-title">
|
||||
<div class="panel-header">
|
||||
<div>
|
||||
<h2 id="worker-list-title">Your workers</h2>
|
||||
<p id="worker-refresh-state" class="muted" role="status" aria-live="polite">Updates every 10 seconds</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<ul id="process-list" class="worker-list" aria-label="Download workers">
|
||||
<% workerProcesses.forEach(p => { %>
|
||||
<li class="worker-list-item">
|
||||
<button type="button" class="worker-row" aria-pressed="false" disabled
|
||||
data-key="<%= String(p.pm_id) + ':' + p.name %>"
|
||||
data-name="<%= p.name %>" data-pmid="<%= p.pm_id %>"
|
||||
data-pid="<%= p.pid %>" data-status="<%= p.status %>"
|
||||
data-cpu="<%= p.cpu %>" data-memory="<%= p.memoryMB %>"
|
||||
data-uptime="<%= p.uptime %>" data-exec="<%= p.execPath %>">
|
||||
<span class="worker-row-heading">
|
||||
<strong class="worker-name"><%= p.name %></strong>
|
||||
<span class="badge <%= workerStatusClass(p.status) %>" data-worker-status><%= p.status %></span>
|
||||
</span>
|
||||
<span class="worker-row-meta" data-worker-metrics>CPU <%= p.cpu %> · <%= p.memoryMB %> · <%= p.uptime %></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PROCESS LIST -->
|
||||
<div id="process-list" class="list-group" style="max-height:40vh; overflow-y:auto;">
|
||||
<% if (processes && processes.length) { %>
|
||||
<% processes.forEach(p => {
|
||||
let status = (p.status || '').toLowerCase();
|
||||
let badge = 'bg-secondary';
|
||||
if (status === 'online' || status === 'running') badge = 'bg-success';
|
||||
else if (status.includes('stop') || status.includes('exit')) badge = 'bg-danger';
|
||||
else if (status.includes('launch') || status.includes('start')) badge = 'bg-warning text-dark';
|
||||
%>
|
||||
<a href="#"
|
||||
class="list-group-item pm2-row d-flex justify-content-between"
|
||||
data-name="<%= p.name %>"
|
||||
data-pid="<%= p.pid %>"
|
||||
data-pmid="<%= p.pm_id %>"
|
||||
data-status="<%= p.status %>"
|
||||
>
|
||||
<div>
|
||||
<strong><%= p.name %></strong>
|
||||
<span class="badge badge-small <%= badge %>"><%= p.status %></span>
|
||||
<div class="subtle"><%= p.execPath %></div>
|
||||
</div>
|
||||
|
||||
<div class="text-end">
|
||||
<div>pid: <span><%= p.pid %></span></div>
|
||||
<div class="subtle"><%= p.uptime %></div>
|
||||
</div>
|
||||
</a>
|
||||
<% }) %>
|
||||
<% } else { %>
|
||||
<div class="alert alert-warning">No downloader workers found.</div>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
<pre id="control-output" class="mt-3 p-2" role="status" aria-live="polite" style="background:#0b0b0b; max-height:110px; overflow:auto; border-radius:6px; white-space:pre-wrap;">Worker action results will appear here.</pre>
|
||||
|
||||
<!-- CONTROL CENTRE -->
|
||||
<div id="control-centre" class="mt-3 p-3" style="display:none; background:#3A3A3A; border-radius:8px; border:1px solid #555;">
|
||||
<h5 id="cc-name">Process Name</h5>
|
||||
<div id="cc-sub" class="subtle mb-2">pm_id / pid / status</div>
|
||||
|
||||
<!-- Quick actions -->
|
||||
<div class="d-flex flex-wrap gap-2 mb-3">
|
||||
<button id="btn-start" class="btn btn-success btn-sm">Start</button>
|
||||
<button id="btn-stop" class="btn btn-danger btn-sm">Stop</button>
|
||||
<button id="btn-restart" class="btn btn-warning btn-sm">Restart</button>
|
||||
<button id="btn-delete" class="btn btn-outline-light btn-sm">Delete</button>
|
||||
</div>
|
||||
|
||||
<!-- Details -->
|
||||
<div class="small">
|
||||
<div><span class="kv-label">PM2 name</span> <span class="kv-value" id="detail-name">—</span></div>
|
||||
<div><span class="kv-label">PM2 id</span> <span class="kv-value" id="detail-pmid">—</span></div>
|
||||
<div><span class="kv-label">PID</span> <span class="kv-value" id="detail-pid">—</span></div>
|
||||
<div><span class="kv-label">Status</span> <span class="kv-value" id="detail-status">—</span></div>
|
||||
<div><span class="kv-label">Uptime</span> <span class="kv-value" id="detail-uptime">—</span></div>
|
||||
<div><span class="kv-label">CPU</span> <span class="kv-value" id="detail-cpu">—</span></div>
|
||||
<div><span class="kv-label">Memory</span> <span class="kv-value" id="detail-mem">—</span></div>
|
||||
<div><span class="kv-label">Exec Path</span> <span class="kv-value" id="detail-exec">—</span></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
<div id="workers-empty" class="empty-state" <%= workerProcesses.length ? 'hidden' : '' %>>
|
||||
<h3>No workers yet</h3>
|
||||
<p>Use Quick add worker to start processing the queue.</p>
|
||||
</div>
|
||||
|
||||
<p class="field-hint worker-quick-add-hint">Quick add starts a worker immediately, named proxer-worker-1, proxer-worker-2 and so on. The next number is chosen automatically.</p>
|
||||
<details class="worker-create">
|
||||
<summary>Choose a custom name</summary>
|
||||
<form id="create-worker-form" novalidate>
|
||||
<div class="field">
|
||||
<label class="field-label" for="worker-name">Worker name</label>
|
||||
<input class="field-input" id="worker-name" name="workerName" type="text"
|
||||
required maxlength="64" pattern="[A-Za-z0-9][A-Za-z0-9_\-]{0,63}"
|
||||
autocomplete="off" spellcheck="false" placeholder="my-worker"
|
||||
aria-describedby="worker-name-hint">
|
||||
<p id="worker-name-hint" class="field-hint">Start with a letter or number. Use letters, numbers, underscores or hyphens.</p>
|
||||
</div>
|
||||
<button id="btn-create" class="button button-secondary" type="submit" disabled>Create named worker</button>
|
||||
<p class="field-hint">A new worker starts immediately.</p>
|
||||
</form>
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- RIGHT COLUMN — LOGS -->
|
||||
<div class="col-md-7 d-flex">
|
||||
<div class="card-dark w-100 d-flex flex-column">
|
||||
<div class="worker-workspace">
|
||||
<section id="worker-placeholder" class="panel worker-selection-empty">
|
||||
<div class="empty-state">
|
||||
<h2>Select a worker</h2>
|
||||
<p>Choose a worker to see its health, manage it and open its logs.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<h4>Logs</h4>
|
||||
<div class="d-flex gap-2">
|
||||
<button id="clear-logs" class="btn btn-outline-light btn-sm">Clear</button>
|
||||
<section id="control-centre" class="panel worker-controls" aria-labelledby="cc-name" hidden>
|
||||
<div class="panel-header">
|
||||
<div>
|
||||
<p class="eyebrow">Selected worker</p>
|
||||
<h2 id="cc-name"></h2>
|
||||
<p id="cc-sub" class="muted"></p>
|
||||
</div>
|
||||
<button id="clear-selection" class="button button-ghost" type="button">Deselect</button>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<dl class="worker-stats">
|
||||
<div><dt>CPU</dt><dd id="detail-cpu">—</dd></div>
|
||||
<div><dt>Memory</dt><dd id="detail-mem">—</dd></div>
|
||||
<div><dt>Uptime</dt><dd id="detail-uptime">—</dd></div>
|
||||
</dl>
|
||||
<div class="worker-actions" aria-label="Selected worker actions">
|
||||
<button id="btn-start" class="button button-primary" type="button" disabled>Start</button>
|
||||
<button id="btn-stop" class="button button-secondary" type="button" disabled>Stop</button>
|
||||
<button id="btn-restart" class="button button-secondary" type="button" disabled>Restart</button>
|
||||
<button id="btn-delete" class="button button-danger" type="button" disabled>Delete worker</button>
|
||||
</div>
|
||||
<details class="worker-details">
|
||||
<summary>Process details</summary>
|
||||
<dl>
|
||||
<div><dt>PM2 ID</dt><dd id="detail-pmid">—</dd></div>
|
||||
<div><dt>Process ID</dt><dd id="detail-pid">—</dd></div>
|
||||
<div><dt>Status</dt><dd id="detail-status">—</dd></div>
|
||||
<div><dt>Executable</dt><dd id="detail-exec">—</dd></div>
|
||||
</dl>
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel log-panel" aria-labelledby="logs-title">
|
||||
<div class="panel-header">
|
||||
<div>
|
||||
<h2 id="logs-title">Worker logs</h2>
|
||||
<p id="log-connection-state" class="muted" role="status" aria-live="polite">No worker selected</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="log-toolbar">
|
||||
<label class="checkbox-label" for="follow-logs"><input id="follow-logs" type="checkbox" checked> Follow output</label>
|
||||
<div class="worker-actions">
|
||||
<button id="reconnect-logs" class="button button-secondary button-small" type="button" disabled>Reconnect logs</button>
|
||||
<button id="clear-logs" class="button button-ghost button-small" type="button">Clear view</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="logs">[no logs yet]</div>
|
||||
|
||||
<pre id="logs" class="log-view" tabindex="0" aria-label="Worker log output" aria-live="off">Select a worker to view its logs.</pre>
|
||||
<p class="field-hint">The latest output stays here while you browse. Clearing this view does not delete stored logs.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const ws = new WebSocket((location.protocol === 'https:' ? 'wss://' : 'ws://') + location.host);
|
||||
const logsEl = document.getElementById('logs');
|
||||
const actionOutput = document.getElementById('control-output');
|
||||
const MAX_VISIBLE_LOG = 64 * 1024;
|
||||
let selectedEl = null;
|
||||
let selectedData = null;
|
||||
let selectionGeneration = 0;
|
||||
let logWorkerName = null;
|
||||
let commandInFlight = false;
|
||||
|
||||
function appendLog(message) {
|
||||
const following = logsEl.scrollHeight - logsEl.scrollTop - logsEl.clientHeight < 40;
|
||||
const combined = logsEl.textContent + `[${new Date().toLocaleTimeString()}] ${String(message)}\n`;
|
||||
logsEl.textContent = combined.length > MAX_VISIBLE_LOG
|
||||
? '[earlier log output omitted]\n' + combined.slice(-MAX_VISIBLE_LOG)
|
||||
: combined;
|
||||
if (following) logsEl.scrollTop = logsEl.scrollHeight;
|
||||
}
|
||||
|
||||
function sendLogRequest(payload, showUnavailable = true) {
|
||||
if (ws.readyState !== WebSocket.OPEN) {
|
||||
if (showUnavailable) appendLog('[log connection is not ready]');
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ws.send(JSON.stringify(payload));
|
||||
return true;
|
||||
} catch {
|
||||
if (showUnavailable) appendLog('[log request could not be sent]');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function startSelectedLogs() {
|
||||
if (!selectedData || logWorkerName === selectedData.name) return;
|
||||
if (sendLogRequest({ type: 'logs', name: selectedData.name })) logWorkerName = selectedData.name;
|
||||
}
|
||||
|
||||
ws.addEventListener('open', () => {
|
||||
appendLog('[log connection ready]');
|
||||
startSelectedLogs();
|
||||
});
|
||||
ws.addEventListener('close', () => {
|
||||
logWorkerName = null;
|
||||
appendLog('[log connection closed; reload this page to reconnect]');
|
||||
});
|
||||
ws.addEventListener('error', () => appendLog('[log connection unavailable]'));
|
||||
ws.addEventListener('message', event => {
|
||||
let payload;
|
||||
try { payload = JSON.parse(event.data); } catch { return; }
|
||||
if (!payload || typeof payload !== 'object') return;
|
||||
if (payload.type === 'stdout' || payload.type === 'stderr') appendLog(payload.data || '');
|
||||
else if (payload.type === 'info') appendLog('[info] ' + (payload.message || ''));
|
||||
else if (payload.type === 'error') {
|
||||
logWorkerName = null;
|
||||
appendLog('[error] ' + (payload.error || 'The log stream failed.'));
|
||||
} else if (payload.type === 'close') {
|
||||
logWorkerName = null;
|
||||
appendLog('[log stream closed]');
|
||||
}
|
||||
});
|
||||
|
||||
function clearSelection() {
|
||||
selectionGeneration++;
|
||||
document.querySelectorAll('.pm2-row').forEach(row => row.classList.remove('active', 'selected-outline'));
|
||||
selectedEl = null;
|
||||
selectedData = null;
|
||||
logWorkerName = null;
|
||||
document.getElementById('control-centre').style.display = 'none';
|
||||
sendLogRequest({ type: 'stop-logs' }, false);
|
||||
}
|
||||
|
||||
function controlData(process) {
|
||||
return { ...process, pmid: process.pm_id ?? process.pmid ?? '—' };
|
||||
}
|
||||
|
||||
function populateControlCentre(data) {
|
||||
const values = {
|
||||
'cc-name': data.name,
|
||||
'cc-sub': `pm_id: ${data.pmid} • pid: ${data.pid} • status: ${data.status}`,
|
||||
'detail-name': data.name,
|
||||
'detail-pmid': data.pmid,
|
||||
'detail-pid': data.pid,
|
||||
'detail-status': data.status,
|
||||
'detail-uptime': data.uptime,
|
||||
'detail-cpu': data.cpu,
|
||||
'detail-mem': data.memoryMB,
|
||||
'detail-exec': data.execPath,
|
||||
};
|
||||
for (const [id, value] of Object.entries(values)) document.getElementById(id).textContent = value ?? '—';
|
||||
}
|
||||
|
||||
async function readProcesses() {
|
||||
const response = await fetch('/pm2/list-json', { cache: 'no-store' });
|
||||
const result = await response.json();
|
||||
if (!response.ok || !result.ok || !Array.isArray(result.processes)) throw new Error('The worker list is unavailable.');
|
||||
return result.processes;
|
||||
}
|
||||
|
||||
function bindRowEvents() {
|
||||
document.querySelectorAll('.pm2-row').forEach(row => {
|
||||
row.addEventListener('click', async event => {
|
||||
event.preventDefault();
|
||||
if (selectedEl === row) {
|
||||
clearSelection();
|
||||
return;
|
||||
}
|
||||
clearSelection();
|
||||
const requestGeneration = selectionGeneration;
|
||||
row.classList.add('active', 'selected-outline');
|
||||
selectedEl = row;
|
||||
selectedData = controlData({
|
||||
name: row.dataset.name,
|
||||
pmid: row.dataset.pmid,
|
||||
pid: row.dataset.pid,
|
||||
status: row.dataset.status,
|
||||
});
|
||||
populateControlCentre(selectedData);
|
||||
document.getElementById('control-centre').style.display = 'block';
|
||||
const name = selectedData.name;
|
||||
try {
|
||||
const full = (await readProcesses()).find(process => process.name === name);
|
||||
if (requestGeneration !== selectionGeneration || selectedData?.name !== name) return;
|
||||
if (!full) {
|
||||
clearSelection();
|
||||
actionOutput.textContent = 'The selected worker is no longer available.';
|
||||
return;
|
||||
}
|
||||
selectedData = controlData(full);
|
||||
populateControlCentre(selectedData);
|
||||
} catch {
|
||||
if (requestGeneration !== selectionGeneration || selectedData?.name !== name) return;
|
||||
actionOutput.textContent = 'Could not refresh the selected worker details.';
|
||||
}
|
||||
if (requestGeneration === selectionGeneration && selectedData?.name === name) startSelectedLogs();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function element(tag, className, text) {
|
||||
const node = document.createElement(tag);
|
||||
if (className) node.className = className;
|
||||
if (text !== undefined) node.textContent = String(text ?? '—');
|
||||
return node;
|
||||
}
|
||||
|
||||
function processRow(process) {
|
||||
const row = element('a', 'list-group-item pm2-row d-flex justify-content-between');
|
||||
row.href = '#';
|
||||
row.dataset.name = String(process.name);
|
||||
row.dataset.pid = String(process.pid);
|
||||
row.dataset.pmid = String(process.pm_id);
|
||||
row.dataset.status = String(process.status);
|
||||
const status = String(process.status || '').toLowerCase();
|
||||
let badge = 'bg-secondary';
|
||||
if (status === 'online' || status === 'running') badge = 'bg-success';
|
||||
else if (status.includes('stop') || status.includes('exit')) badge = 'bg-danger';
|
||||
else if (status.includes('start') || status.includes('launch')) badge = 'bg-warning text-dark';
|
||||
const description = element('div');
|
||||
description.append(element('strong', '', process.name), ' ', element('span', 'badge badge-small ' + badge, process.status), element('div', 'subtle', process.execPath));
|
||||
const detail = element('div', 'text-end');
|
||||
detail.append(element('div', '', 'pid: ' + process.pid), element('div', 'subtle', process.uptime));
|
||||
row.append(description, detail);
|
||||
return row;
|
||||
}
|
||||
|
||||
async function refreshList() {
|
||||
try {
|
||||
const processes = await readProcesses();
|
||||
const list = document.getElementById('process-list');
|
||||
const selectedName = selectedData?.name;
|
||||
list.replaceChildren();
|
||||
for (const process of processes) {
|
||||
const row = processRow(process);
|
||||
list.appendChild(row);
|
||||
if (process.name === selectedName) {
|
||||
selectedEl = row;
|
||||
selectedData = controlData(process);
|
||||
row.classList.add('active', 'selected-outline');
|
||||
populateControlCentre(selectedData);
|
||||
}
|
||||
}
|
||||
if (!processes.length) list.appendChild(element('div', 'alert alert-warning', 'No downloader workers found.'));
|
||||
if (selectedName && !processes.some(process => process.name === selectedName)) clearSelection();
|
||||
bindRowEvents();
|
||||
return true;
|
||||
} catch {
|
||||
actionOutput.textContent = 'Could not refresh the worker list. Please try again.';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function execCommand(payload) {
|
||||
if (commandInFlight) return false;
|
||||
commandInFlight = true;
|
||||
actionOutput.textContent = 'Running worker command…';
|
||||
try {
|
||||
const response = await fetch('/pm2/command', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
const result = await response.json();
|
||||
actionOutput.textContent = result.message || result.error || 'The worker command could not be completed.';
|
||||
if (response.ok && result.ok) {
|
||||
await refreshList();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch {
|
||||
actionOutput.textContent = 'Could not contact the worker supervisor. Please try again.';
|
||||
return false;
|
||||
} finally {
|
||||
commandInFlight = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function findNextWorkerName() {
|
||||
const names = new Set((await readProcesses()).map(process => process.name));
|
||||
let next = 1;
|
||||
while (names.has('proxerdl-worker' + next)) next++;
|
||||
return 'proxerdl-worker' + next;
|
||||
}
|
||||
|
||||
document.getElementById('btn-create').addEventListener('click', async event => {
|
||||
const button = event.currentTarget;
|
||||
if (button.disabled || commandInFlight) return;
|
||||
button.disabled = true;
|
||||
actionOutput.textContent = 'Preparing a downloader worker…';
|
||||
try {
|
||||
const name = await findNextWorkerName();
|
||||
if (await execCommand({ cmd: 'create', name })) {
|
||||
const row = [...document.querySelectorAll('.pm2-row')].find(item => item.dataset.name === name);
|
||||
if (row) row.click();
|
||||
}
|
||||
} catch {
|
||||
actionOutput.textContent = 'Could not prepare the worker. Refresh the list and try again.';
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
for (const command of ['start', 'stop', 'restart', 'delete']) {
|
||||
document.getElementById('btn-' + command).addEventListener('click', () => {
|
||||
if (!selectedData) {
|
||||
actionOutput.textContent = 'Select a downloader worker first.';
|
||||
return;
|
||||
}
|
||||
execCommand({ cmd: command, name: selectedData.name });
|
||||
});
|
||||
}
|
||||
document.getElementById('refresh-list').addEventListener('click', refreshList);
|
||||
document.getElementById('clear-logs').addEventListener('click', () => { logsEl.textContent = ''; });
|
||||
window.addEventListener('beforeunload', () => sendLogRequest({ type: 'stop-logs' }, false));
|
||||
bindRowEvents();
|
||||
</script>
|
||||
|
||||
<script src="/workers.js" defer></script>
|
||||
<%- include('partials/footer') %>
|
||||
+132
-303
@@ -1,315 +1,144 @@
|
||||
<%- include("partials/header") %>
|
||||
<%- include("partials/header", { title: "Queue", activePage: "queue" }) %>
|
||||
<%
|
||||
const states = {
|
||||
queued: { label: "Queued", note: "Waiting to start", badge: "badge-neutral", date: "created_at", dateLabel: "Queued" },
|
||||
processing: { label: "Active", note: "Claimed by workers", badge: "badge-info", date: "started_at", dateLabel: "Started" },
|
||||
done: { label: "Completed", note: "Successful downloads", badge: "badge-success", date: "finished_at", dateLabel: "Finished" },
|
||||
failed: { label: "Failed attempts", note: "Review the attempt log", badge: "badge-danger", date: "failed_at", dateLabel: "Failed" }
|
||||
};
|
||||
const selected = states[filters.state];
|
||||
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 clearAction = clearActions[filters.state];
|
||||
const pageLink = (state, page, q = filters.q) => "/status?" + new URLSearchParams({ state, q, page: String(page), pageSize: String(pagination.pageSize) }).toString();
|
||||
const safeSource = value => typeof value === "string" && /^https:\/\/proxer\.me\/watch\/[1-9]\d*\/[1-9]\d*\/(engsub|engdub|gersub|gerdub)$/.test(value) ? value : "";
|
||||
const languages = { engsub: "English sub", engdub: "English dub", gersub: "German sub", gerdub: "German dub" };
|
||||
const sourceLabel = value => {
|
||||
const parts = safeSource(value).split("/");
|
||||
return parts.length === 7 ? "Series " + parts[4] + " · Episode " + parts[5] + " · " + languages[parts[6]] : "Source unavailable";
|
||||
};
|
||||
const bytes = 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];
|
||||
};
|
||||
const displayDate = value => {
|
||||
const date = new Date(value);
|
||||
return value && Number.isFinite(date.getTime()) ? date.toLocaleString("en-GB", { dateStyle: "medium", timeStyle: "short" }) : "Not recorded";
|
||||
};
|
||||
%>
|
||||
|
||||
<style>
|
||||
.status-card {
|
||||
background: #3A3A3A;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #444;
|
||||
padding: 15px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.35);
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.status-title {
|
||||
margin: 0;
|
||||
font-size: 1.6rem;
|
||||
}
|
||||
|
||||
.log-box {
|
||||
background:#001122;
|
||||
color:#9cf;
|
||||
padding:10px;
|
||||
border-radius:5px;
|
||||
white-space:pre-wrap;
|
||||
overflow-wrap:break-word;
|
||||
}
|
||||
|
||||
.log-box-light {
|
||||
background:#222;
|
||||
color:#e0e0e0;
|
||||
padding:10px;
|
||||
border-radius:5px;
|
||||
white-space:pre-wrap;
|
||||
overflow-wrap:break-word;
|
||||
}
|
||||
|
||||
.log-box-error {
|
||||
background:#330000;
|
||||
color:#ffb3b3;
|
||||
padding:10px;
|
||||
border-radius:5px;
|
||||
white-space:pre-wrap;
|
||||
overflow-wrap:break-word;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display:flex;
|
||||
justify-content:center;
|
||||
align-items:center;
|
||||
margin-bottom:10px;
|
||||
gap:6px;
|
||||
}
|
||||
|
||||
.list-group-item {
|
||||
background:#3A3A3A;
|
||||
border-color:#4A4A4A;
|
||||
}
|
||||
|
||||
details summary {
|
||||
cursor:pointer;
|
||||
margin-top:6px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="row g-3">
|
||||
|
||||
<!-- ======================= -->
|
||||
<!-- QUEUED -->
|
||||
<!-- ======================= -->
|
||||
<div class="col-md-3">
|
||||
<div class="status-card text-center">
|
||||
|
||||
<div class="section-header">
|
||||
<h3 class="status-title">Queued</h3>
|
||||
<form action="/clear-queued" method="POST">
|
||||
<button class="btn btn-outline-secondary btn-sm rounded-pill">🗑️</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<ul class="list-group" id="queuedList">
|
||||
<% if (queued.length === 0) { %>
|
||||
<li class="list-group-item ">No queued jobs</li>
|
||||
<% } %>
|
||||
|
||||
<% queued.forEach(job => { %>
|
||||
<li class="list-group-item">
|
||||
<strong><%= job.filename %></strong><br>
|
||||
<small><%= job.url %></small><br>
|
||||
<small><%= new Date(job.created_at).toLocaleString() %></small>
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ======================= -->
|
||||
<!-- PROCESSING -->
|
||||
<!-- ======================= -->
|
||||
<div class="col-md-3">
|
||||
<div class="status-card text-center">
|
||||
|
||||
<div class="section-header">
|
||||
<h3 class="status-title" style="color:#58a6ff;">Processing</h3>
|
||||
</div>
|
||||
|
||||
<ul class="list-group" id="processingList">
|
||||
<% if (processing.length === 0) { %>
|
||||
<li class="list-group-item ">Nothing processing</li>
|
||||
<% } %>
|
||||
|
||||
<% processing.forEach(job => { %>
|
||||
<li class="list-group-item">
|
||||
<strong style="color:#58a6ff"><%= job.filename %></strong>
|
||||
<span class="spinner-border spinner-border-sm ms-1" style="color:#58a6ff"></span><br>
|
||||
<small><%= job.url %></small><br>
|
||||
<small><%= job.started_at ? 'Started' : 'Queued' %>: <%= new Date(job.started_at || job.created_at).toLocaleString() %></small><br>
|
||||
|
||||
<% if (job.fileSize) { %>
|
||||
<small>Downloaded: <%= job.fileSize %></small>
|
||||
<% } %>
|
||||
|
||||
<% if (job.output_log) { %>
|
||||
<details data-id="processing-<%= job._id %>">
|
||||
<summary class="text-light">Live Log</summary>
|
||||
<pre class="log-box"><%= job.output_log %></pre>
|
||||
</details>
|
||||
<% } %>
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ======================= -->
|
||||
<!-- DONE -->
|
||||
<!-- ======================= -->
|
||||
<div class="col-md-3">
|
||||
<div class="status-card text-center">
|
||||
|
||||
<div class="section-header">
|
||||
<h3 class="status-title text-success">Done</h3>
|
||||
<form action="/clear-done" method="POST">
|
||||
<button class="btn btn-outline-success btn-sm rounded-pill">🗑️</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<ul class="list-group" id="doneList">
|
||||
<% if (finished.length === 0) { %>
|
||||
<li class="list-group-item ">No completed jobs</li>
|
||||
<% } %>
|
||||
|
||||
<% finished.forEach(job => { %>
|
||||
<li class="list-group-item">
|
||||
|
||||
<strong class="text-success"><%= job.filename %></strong><br>
|
||||
<small><%= new Date(job.finished_at).toLocaleString() %></small><br>
|
||||
|
||||
<% if (job.fileSize) { %>
|
||||
<small>Size: <%= job.fileSize %></small><br>
|
||||
<% } %>
|
||||
|
||||
<% if (job.output_log) { %>
|
||||
<details data-id="done-<%= job._id %>">
|
||||
<summary class="text-light">Show Log</summary>
|
||||
<pre class="log-box-light"><%= job.output_log %></pre>
|
||||
</details>
|
||||
<% } %>
|
||||
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ======================= -->
|
||||
<!-- FAILED -->
|
||||
<!-- ======================= -->
|
||||
<div class="col-md-3">
|
||||
<div class="status-card text-center">
|
||||
|
||||
<div class="section-header">
|
||||
<h3 class="status-title text-danger">Failed</h3>
|
||||
<form action="/clear-failed" method="POST">
|
||||
<button class="btn btn-outline-danger btn-sm rounded-pill">🗑️</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<ul class="list-group" id="failedList">
|
||||
<% if (failed.length === 0) { %>
|
||||
<li class="list-group-item ">No failed jobs</li>
|
||||
<% } %>
|
||||
|
||||
<% failed.forEach(job => { %>
|
||||
<li class="list-group-item">
|
||||
|
||||
<strong class="text-danger"><%= job.filename %></strong><br>
|
||||
<small><%= new Date(job.failed_at).toLocaleString() %></small><br>
|
||||
|
||||
<% if (job.output_log) { %>
|
||||
<details data-id="failed-<%= job._id %>">
|
||||
<summary class="text-danger">Show Error Log</summary>
|
||||
<pre class="log-box-error"><%= job.output_log %></pre>
|
||||
</details>
|
||||
<% } %>
|
||||
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<p class="eyebrow">Download activity</p>
|
||||
<h1 class="page-title">Your queue, at a glance.</h1>
|
||||
<p class="page-description">Follow active downloads and find the episode you need.</p>
|
||||
</div>
|
||||
<a class="button button-primary" href="/download">New download</a>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
/* ============================================================
|
||||
AUTO REFRESH STATUS
|
||||
============================================================ */
|
||||
<% if (typeof added !== "undefined" && added > 0) { %>
|
||||
<div class="notice notice-success" role="status"><strong><%= added %> <%= added === 1 ? "episode" : "episodes" %> added to the queue.</strong> Downloads will start when a worker is available and the queue is ready.</div>
|
||||
<% } %>
|
||||
|
||||
function formatBytes(bytes) {
|
||||
if (!bytes) return "Unknown";
|
||||
const units = ["B","KB","MB","GB","TB"];
|
||||
let i = 0;
|
||||
while (bytes >= 1024 && i < units.length - 1) {
|
||||
bytes /= 1024;
|
||||
i++;
|
||||
}
|
||||
return bytes.toFixed(1) + " " + units[i];
|
||||
}
|
||||
<%- include('partials/active-downloads') %>
|
||||
|
||||
async function refreshStatus() {
|
||||
try {
|
||||
// Track open details by data-id
|
||||
const openMap = new Set(
|
||||
[...document.querySelectorAll("details")].filter(d => d.open).map(d => d.dataset.id)
|
||||
);
|
||||
<nav class="queue-overview" aria-label="Filter downloads by state">
|
||||
<% Object.entries(states).forEach(([state, info]) => { %>
|
||||
<a class="queue-stat<%= state === filters.state ? ' is-selected' : '' %>" href="<%= pageLink(state, 1) %>" data-state-link="<%= state %>"<%- state === filters.state ? ' aria-current="page"' : '' %>>
|
||||
<span class="queue-stat-label"><%= info.label %></span>
|
||||
<strong class="queue-stat-count" data-state-count="<%= state %>"><%= counts[state] %></strong>
|
||||
<span class="queue-stat-note"><%= info.note %></span>
|
||||
</a>
|
||||
<% }) %>
|
||||
</nav>
|
||||
|
||||
const res = await fetch("/status-data");
|
||||
const data = await res.json();
|
||||
<section class="panel" aria-labelledby="queue-title" id="queue-view" data-state="<%= filters.state %>" data-page="<%= pagination.page %>" data-page-size="<%= pagination.pageSize %>" data-query="<%= filters.q %>">
|
||||
<div class="panel-header">
|
||||
<div>
|
||||
<h2 id="queue-title"><%= selected.label %></h2>
|
||||
<p id="queue-state-note" class="muted"><%= filters.state === "failed" ? "An attempt can appear here even when its retained episode later completes. Check the queue and completed downloads before resubmitting." : filters.state === "processing" ? "File size shows the current file on disk. A claimed item may be resolving its source or transferring." : filters.state === "done" ? "Completed downloads stay in history until you clear their records." : "Waiting episodes are taken by available workers when verification is clear." %></p>
|
||||
</div>
|
||||
<div class="button-group">
|
||||
<form action="/clear-state" method="POST" id="queue-clear-state-form" data-confirm="<%= clearAction?.confirmation || '' %>"<%- clearAction ? '' : ' hidden' %>>
|
||||
<input type="hidden" name="state" id="queue-clear-state" value="<%= filters.state %>">
|
||||
<button class="button button-danger button-small" type="submit" id="queue-clear-state-button"<%- clearAction && counts[filters.state] > 0 ? '' : ' disabled' %>><%= clearAction?.label || 'Clear records' %></button>
|
||||
</form>
|
||||
<span class="badge badge-neutral" id="queue-active-protected"<%- clearAction ? ' hidden' : '' %>>Active downloads protected</span>
|
||||
<button class="button button-secondary button-small" type="button" id="queue-refresh">Refresh</button>
|
||||
<button class="button button-secondary button-small" type="button" id="queue-auto-refresh" aria-pressed="true">Auto refresh: on</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
/* Renderer helpers */
|
||||
const q = job => `
|
||||
<li class="list-group-item">
|
||||
<strong>${escapeHtml(job.filename)}</strong><br>
|
||||
<small>${escapeHtml(job.url)}</small><br>
|
||||
<small>${new Date(job.created_at).toLocaleString()}</small>
|
||||
</li>`;
|
||||
<div class="panel-body">
|
||||
<form method="GET" action="/status" id="queue-filter-form" class="queue-filters">
|
||||
<input type="hidden" name="state" id="queue-state" value="<%= filters.state %>">
|
||||
<div class="field queue-search">
|
||||
<label class="field-label" for="queue-query">Find a filename</label>
|
||||
<input class="field-input" type="search" id="queue-query" name="q" maxlength="100" value="<%= filters.q %>" placeholder="Search episode titles…" autocomplete="off">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="field-label" for="queue-page-size">Per page</label>
|
||||
<select class="field-input" name="pageSize" id="queue-page-size">
|
||||
<% [10, 25, 50].forEach(size => { %>
|
||||
<option value="<%= size %>"<%- size === pagination.pageSize ? ' selected' : '' %>><%= size %></option>
|
||||
<% }) %>
|
||||
</select>
|
||||
</div>
|
||||
<button class="button button-secondary" type="submit">Filter</button>
|
||||
<a class="button button-secondary" id="queue-clear-filter" href="<%= pageLink(filters.state, 1, '') %>"<%- filters.q ? '' : ' hidden' %>>Clear search</a>
|
||||
</form>
|
||||
<p class="field-hint" id="queue-feedback" role="status" aria-live="polite">Updates every 10 seconds while this page is visible.</p>
|
||||
</div>
|
||||
|
||||
const p = job => `
|
||||
<li class="list-group-item">
|
||||
<strong style="color:#58a6ff">${escapeHtml(job.filename)}</strong>
|
||||
<span class="spinner-border spinner-border-sm ms-1" style="color:#58a6ff"></span><br>
|
||||
<small>${escapeHtml(job.url)}</small><br>
|
||||
<small>${job.started_at ? 'Started' : 'Queued'}: ${new Date(job.started_at || job.created_at).toLocaleString()}</small><br>
|
||||
<small>Downloaded: ${formatBytes(job.fileSize || 0)}</small>
|
||||
${job.output_log ? `
|
||||
<details data-id="processing-${escapeHtml(job._id)}">
|
||||
<summary class="text-light">Live Log</summary>
|
||||
<pre class="log-box">${escapeHtml(job.output_log)}</pre>
|
||||
</details>` : ""}
|
||||
</li>`;
|
||||
<div class="queue-columns" aria-hidden="true">
|
||||
<span>Download</span><span>State</span><span>When</span><span>File on disk</span>
|
||||
</div>
|
||||
<ul class="job-list" id="queue-jobs" aria-label="<%= selected.label %>">
|
||||
<% items.forEach(job => { const stamp = job[selected.date] || job.created_at; const source = safeSource(job.url); %>
|
||||
<li class="job-row" data-job-id="<%= job._id %>" data-job-state="<%= filters.state %>">
|
||||
<div class="job-primary">
|
||||
<strong class="job-filename"><%= job.filename %></strong>
|
||||
<a class="job-source"<% if (source) { %> href="<%= source %>" target="_blank" rel="noopener noreferrer"<% } %>><%= sourceLabel(job.url) %></a>
|
||||
</div>
|
||||
<div class="job-state">
|
||||
<span class="badge <%= selected.badge %>"><%= selected.label %></span>
|
||||
<span class="job-error-category muted"><%= job.error_category || "" %></span>
|
||||
</div>
|
||||
<div class="job-time">
|
||||
<span class="job-time-label muted"><%= filters.state === "processing" && !job.started_at ? "Queued" : selected.dateLabel %></span>
|
||||
<time<% if (stamp) { %> datetime="<%= stamp %>"<% } %>><%= displayDate(stamp) %></time>
|
||||
</div>
|
||||
<div class="job-size">
|
||||
<span class="job-size-value"><%= bytes(job.fileSize) %></span>
|
||||
<small class="muted"><%= typeof job.fileSize === "number" ? "on disk" : "not available" %></small>
|
||||
</div>
|
||||
<details class="job-log"<%- job.output_log ? "" : " hidden" %>>
|
||||
<summary><%= filters.state === "failed" ? "View attempt log" : "View log" %></summary>
|
||||
<pre class="log-output" tabindex="0"><%= job.output_log || "" %></pre>
|
||||
</details>
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
<div class="empty-state" id="queue-empty"<%- items.length ? " hidden" : "" %>>
|
||||
<strong id="queue-empty-title"><%= filters.q ? "No matching filenames" : "No " + selected.label.toLowerCase() %></strong>
|
||||
<p id="queue-empty-message"><%= filters.q ? "Try a shorter search or choose another state." : filters.state === "queued" ? "Add a series or a single episode to get started." : filters.state === "processing" ? "No episodes are currently claimed by a worker." : filters.state === "done" ? "Successful downloads will appear here." : "No failed attempts are recorded." %></p>
|
||||
</div>
|
||||
|
||||
const d = job => `
|
||||
<li class="list-group-item">
|
||||
<strong class="text-success">${escapeHtml(job.filename)}</strong><br>
|
||||
<small>${new Date(job.finished_at).toLocaleString()}</small><br>
|
||||
<small>Size: ${formatBytes(job.fileSize || 0)}</small>
|
||||
${job.output_log ? `
|
||||
<details data-id="done-${escapeHtml(job._id)}">
|
||||
<summary class="text-light">Show Log</summary>
|
||||
<pre class="log-box-light">${escapeHtml(job.output_log)}</pre>
|
||||
</details>` : ""}
|
||||
</li>`;
|
||||
|
||||
const f = job => `
|
||||
<li class="list-group-item">
|
||||
<strong class="text-danger">${escapeHtml(job.filename)}</strong><br>
|
||||
<small>${new Date(job.failed_at).toLocaleString()}</small><br>
|
||||
${job.output_log ? `
|
||||
<details data-id="failed-${escapeHtml(job._id)}">
|
||||
<summary class="text-danger">Show Error Log</summary>
|
||||
<pre class="log-box-error">${escapeHtml(job.output_log)}</pre>
|
||||
</details>` : ""}
|
||||
</li>`;
|
||||
|
||||
/* Replace lists */
|
||||
queuedList.innerHTML = data.queued.length ? data.queued.map(q).join("") : `<li class="list-group-item ">No queued jobs</li>`;
|
||||
processingList.innerHTML = data.processing.length ? data.processing.map(p).join("") : `<li class="list-group-item ">Nothing processing</li>`;
|
||||
doneList.innerHTML = data.done.length ? data.done.map(d).join("") : `<li class="list-group-item ">No completed jobs</li>`;
|
||||
failedList.innerHTML = data.failed.length ? data.failed.map(f).join("") : `<li class="list-group-item ">No failed jobs</li>`;
|
||||
|
||||
// Restore open <details>
|
||||
document.querySelectorAll("details").forEach(d => {
|
||||
if (openMap.has(d.dataset.id)) {
|
||||
d.open = true;
|
||||
}
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
console.error("Status refresh error:", err);
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
return String(text ?? "").replace(/[&<>"']/g, c =>
|
||||
({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c])
|
||||
);
|
||||
}
|
||||
|
||||
setInterval(refreshStatus, 3000);
|
||||
|
||||
|
||||
</script>
|
||||
<nav class="queue-pagination" aria-label="Queue pages">
|
||||
<p id="queue-range" class="muted"><%= pagination.total ? ((pagination.page - 1) * pagination.pageSize + 1) + "–" + Math.min(pagination.page * pagination.pageSize, pagination.total) + " of " + pagination.total : "0 results" %><%= filters.q && pagination.total ? " matches" : "" %></p>
|
||||
<div class="button-group">
|
||||
<a class="button button-secondary button-small" href="<%= pageLink(filters.state, Math.max(1, pagination.page - 1)) %>" data-page-link="previous" aria-disabled="<%= pagination.page <= 1 %>"<%- pagination.page <= 1 ? ' tabindex="-1"' : '' %>>Previous</a>
|
||||
<span id="queue-page-label">Page <%= pagination.page %> of <%= pagination.totalPages %></span>
|
||||
<a class="button button-secondary button-small" href="<%= pageLink(filters.state, Math.min(pagination.totalPages, pagination.page + 1)) %>" data-page-link="next" aria-disabled="<%= pagination.page >= pagination.totalPages %>"<%- pagination.page >= pagination.totalPages ? ' tabindex="-1"' : '' %>>Next</a>
|
||||
</div>
|
||||
</nav>
|
||||
</section>
|
||||
|
||||
<p class="field-hint queue-action-help">The clear action applies to all records in the selected state, including records outside this search or page. Clearing history keeps downloaded files on disk.</p>
|
||||
<script src="/status.js" defer></script>
|
||||
<%- include("partials/footer") %>
|
||||
Reference in new issue
Block a user