phase 2 rework
This commit is contained in:
1 parent
20054198f3
commit
b397ea9256
44 files changed
+5528
-1377
No files matched your search
+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