Files
Proxer-Downloader/views/status.ejs
T
2026-10-23 18:19:44 +02:00

145 lines
10 KiB
Plaintext
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<%- 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";
};
%>
<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>
<% 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>
<% } %>
<%- include('partials/active-downloads') %>
<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>
<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>
<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>
<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>
<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") %>