Files
Proxer-Downloader/views/status.ejs
T
2025-12-06 19:34:25 +01:00

278 lines
9.2 KiB
Plaintext

<%- include("partials/header") %>
<div class="row">
<!-- ======================= -->
<!-- QUEUED -->
<!-- ======================= -->
<div class="col-md-3 text-center">
<div class="d-flex justify-content-center align-items-center mb-2">
<h3 class="mb-0">Queued</h3>
</div>
<ul class="list-group" id="queuedList">
<% 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>
<% }) %>
<% if (queued.length === 0) { %>
<li class="list-group-item">No queued jobs</li>
<% } %>
</ul>
</div>
<!-- ======================= -->
<!-- PROCESSING -->
<!-- ======================= -->
<div class="col-md-3 text-center">
<div class="d-flex justify-content-center align-items-center mb-2">
<h3 class="mb-0" style="color:#58a6ff">Processing</h3>
</div>
<ul class="list-group" id="processingList">
<% processing.forEach(job => { %>
<li class="list-group-item">
<strong style="color:#58a6ff"><%= job.filename %></strong>
<span class="spinner-border spinner-border-sm ms-2" style="color:#58a6ff"></span><br>
<small><%= job.url %></small><br>
<small>Started: <%= new Date(job.created_at).toLocaleString() %></small>
<% if (job.fileSize) { %>
<br><small>Downloaded: <%= job.fileSize %></small>
<% } %>
<% if (job.output_log) { %>
<details class="mt-2">
<summary class="text-light">Live Log</summary>
<pre style="background:#001122; color:#9cf; padding:10px; border-radius:5px; white-space:pre-wrap;">
<%= job.output_log %>
</pre>
</details>
<% } %>
</li>
<% }) %>
<% if (processing.length === 0) { %>
<li class="list-group-item">Nothing processing</li>
<% } %>
</ul>
</div>
<!-- ======================= -->
<!-- DONE -->
<!-- ======================= -->
<div class="col-md-3 text-center">
<div class="d-flex justify-content-center align-items-center mb-2">
<h3 class="text-success mb-0">Done</h3>
<form id="clear-done-form" action="/clear-done" method="POST" class="ms-2">
<button class="btn btn-success btn-sm shadow-sm rounded-pill">
🗑️
</button>
</form>
</div>
<ul class="list-group" id="doneList">
<% 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 class="mt-2">
<summary class="text-light">Show Log</summary>
<pre style="background:#222; color:#e0e0e0; padding:10px; border-radius:5px; white-space:pre-wrap;">
<%= job.output_log %>
</pre>
</details>
<% } %>
</li>
<% }) %>
<% if (finished.length === 0) { %>
<li class="list-group-item">No completed jobs</li>
<% } %>
</ul>
</div>
<!-- ======================= -->
<!-- FAILED -->
<!-- ======================= -->
<div class="col-md-3 text-center">
<div class="d-flex justify-content-center align-items-center mb-2">
<h3 class="text-danger mb-0">Failed</h3>
<form id="clear-failed-form" action="/clear-failed" method="POST" class="ms-2">
<button class="btn btn-danger btn-sm shadow-sm rounded-pill">
🗑️
</button>
</form>
</div>
<ul class="list-group" id="failedList">
<% 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 class="mt-2">
<summary class="text-danger">Show Error Log</summary>
<pre style="background:#330000; color:#ffb3b3; padding:10px; border-radius:5px; white-space:pre-wrap;">
<%= job.output_log %>
</pre>
</details>
<% } %>
</li>
<% }) %>
<% if (failed.length === 0) { %>
<li class="list-group-item">No failed jobs</li>
<% } %>
</ul>
</div>
</div>
<!-- ======================= -->
<!-- PM2 LOGS -->
<!-- ======================= -->
<div class="row mt-4">
<div class="col-12">
<pre id="pm2Logs" style="background:#383838; padding:10px; border-radius:5px; height:300px; overflow-y:auto; white-space:pre-wrap; color: #330000;"></pre>
</div>
</div>
<script>
async function fetchLogs() {
try {
const res = await fetch('../../../.pm2/logs/proxerdl-worker1-out.log');
const text = await res.text();
document.getElementById('pm2Logs').textContent = text;
// auto-scroll to bottom
const logDiv = document.getElementById('pm2Logs');
logDiv.scrollTop = logDiv.scrollHeight;
} catch (err) {
console.error('Error fetching logs:', err);
}
}
// fetch logs every 2 seconds
setInterval(fetchLogs, 2000);
// initial fetch
fetchLogs();
</script>
<!-- ======================= -->
<!-- AUTO-REFRESH SCRIPT -->
<!-- ======================= -->
<script>
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];
}
async function refreshStatus() {
try {
// -----------------------------------------
// 1. CAPTURE CURRENTLY OPEN DETAILS TAGS
// -----------------------------------------
const openDetails = new Set();
document.querySelectorAll("details").forEach((d, index) => {
if (d.open) openDetails.add(index);
});
// fetch new data
const res = await fetch("/status-data");
const data = await res.json();
// =======================
// Templates
// =======================
const renderQueued = 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>`;
const renderProcessing = job => `
<li class="list-group-item">
<strong style="color:#58a6ff">${job.filename}</strong>
<span class="spinner-border spinner-border-sm ms-2" style="color:#58a6ff"></span><br>
<small>${job.url}</small><br>
<small>Started: ${new Date(job.created_at).toLocaleString()}</small><br>
<small>Downloaded: ${formatBytes(job.fileSize)}</small>
${job.output_log ? `
<details class="mt-2">
<summary class="text-light">Live Log</summary>
<pre style="background:#001122; color:#9cf; padding:10px; border-radius:5px; white-space:pre-wrap;">
${job.output_log}
</pre>
</details>` : ""}
</li>`;
const renderDone = job => `
<li class="list-group-item">
<strong class="text-success">${job.filename}</strong><br>
<small>${new Date(job.finished_at).toLocaleString()}</small><br>
<small>Size: ${formatBytes(job.fileSize)}</small>
${job.output_log ? `
<details class="mt-2">
<summary class="text-light">Show Log</summary>
<pre style="background:#222; color:#e0e0e0; padding:10px; border-radius:5px; white-space:pre-wrap;">
${job.output_log}
</pre>
</details>` : ""}
</li>`;
const renderFailed = job => `
<li class="list-group-item">
<strong class="text-danger">${job.filename}</strong><br>
<small>${new Date(job.failed_at).toLocaleString()}</small><br>
${job.output_log ? `
<details class="mt-2">
<summary class="text-danger">Show Error Log</summary>
<pre style="background:#330000; color:#ffb3b3; padding:10px; border-radius:5px; white-space:pre-wrap;">
${job.output_log}
</pre>
</details>` : ""}
</li>`;
// Replace lists
queuedList.innerHTML = data.queued.length ?
data.queued.map(renderQueued).join("") :
`<li class="list-group-item">No queued jobs</li>`;
processingList.innerHTML = data.processing.length ?
data.processing.map(renderProcessing).join("") :
`<li class="list-group-item">Nothing processing</li>`;
doneList.innerHTML = data.done.length ?
data.done.map(renderDone).join("") :
`<li class="list-group-item">No completed jobs</li>`;
failedList.innerHTML = data.failed.length ?
data.failed.map(renderFailed).join("") :
`<li class="list-group-item">No failed jobs</li>`;
// -----------------------------------------
// 2. RESTORE PREVIOUSLY OPEN DETAILS TAGS
// -----------------------------------------
document.querySelectorAll("details").forEach((d, index) => {
if (openDetails.has(index)) d.open = true;
});
} catch (err) {
console.error("Status refresh error:", err);
}
}
setInterval(refreshStatus, 3000);
</script>
<%- include("partials/footer") %>