added pm2 status page and updated others
This commit is contained in:
1 parent
39c2a3f1ef
commit
c07a08dfc0
9 files changed
+1017
-223
No files matched your search
+230
-181
@@ -1,156 +1,225 @@
|
||||
<%- include("partials/header") %>
|
||||
|
||||
<div class="row">
|
||||
<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 text-center">
|
||||
<div class="d-flex justify-content-center align-items-center mb-2">
|
||||
<h3 class="mb-0">Queued</h3>
|
||||
<form id="clear-queued-form" action="/clear-queued" method="POST" class="ms-2">
|
||||
<button class="btn btn-outline-secondary btn-sm shadow-sm rounded-pill">
|
||||
🗑️
|
||||
</button>
|
||||
</form>
|
||||
<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>
|
||||
<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>
|
||||
<form id="clear-processing-form" action="/clear-processing" method="POST" class="ms-2">
|
||||
<button class="btn btn-outline-primary btn-sm shadow-sm rounded-pill">
|
||||
🗑️
|
||||
</button>
|
||||
</form>
|
||||
</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>
|
||||
<% }) %>
|
||||
<div class="col-md-3">
|
||||
<div class="status-card text-center">
|
||||
|
||||
<div class="section-header">
|
||||
<h3 class="status-title" style="color:#58a6ff;">Processing</h3>
|
||||
<form action="/clear-processing" method="POST">
|
||||
<button class="btn btn-outline-primary btn-sm rounded-pill">🗑️</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<ul class="list-group" id="processingList">
|
||||
<% if (processing.length === 0) { %>
|
||||
<li class="list-group-item">Nothing processing</li>
|
||||
<li class="list-group-item ">Nothing processing</li>
|
||||
<% } %>
|
||||
</ul>
|
||||
|
||||
<% 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>Started: <%= new Date(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 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-outline-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>
|
||||
<% }) %>
|
||||
<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>
|
||||
<li class="list-group-item ">No completed jobs</li>
|
||||
<% } %>
|
||||
</ul>
|
||||
|
||||
<% 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 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-outline-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>
|
||||
<% }) %>
|
||||
<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>
|
||||
<li class="list-group-item ">No failed jobs</li>
|
||||
<% } %>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<% failed.forEach(job => { %>
|
||||
<li class="list-group-item">
|
||||
|
||||
<!-- ======================= -->
|
||||
<!-- 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>
|
||||
<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>
|
||||
</div>
|
||||
<!-- SCRIPT TO BE IMPLEMENTED! -->
|
||||
|
||||
<!-- ======================= -->
|
||||
<!-- AUTO-REFRESH SCRIPT -->
|
||||
<!-- ======================= -->
|
||||
<script>
|
||||
/* ============================================================
|
||||
AUTO REFRESH STATUS
|
||||
============================================================ */
|
||||
|
||||
function formatBytes(bytes) {
|
||||
if (!bytes) return "Unknown";
|
||||
const units = ["B","KB","MB","GB","TB"];
|
||||
@@ -164,97 +233,70 @@ function formatBytes(bytes) {
|
||||
|
||||
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);
|
||||
});
|
||||
// Track open details by data-id
|
||||
const openMap = new Set(
|
||||
[...document.querySelectorAll("details")].filter(d => d.open).map(d => d.dataset.id)
|
||||
);
|
||||
|
||||
// fetch new data
|
||||
const res = await fetch("/status-data");
|
||||
const data = await res.json();
|
||||
|
||||
// =======================
|
||||
// Templates
|
||||
// =======================
|
||||
|
||||
const renderQueued = job => `
|
||||
/* Renderer helpers */
|
||||
const q = 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 => `
|
||||
const p = 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>
|
||||
<span class="spinner-border spinner-border-sm ms-1" 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>
|
||||
|
||||
<small>Downloaded: ${formatBytes(job.fileSize || 0)}</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>` : ""}
|
||||
<details data-id="processing-${job._id}">
|
||||
<summary class="text-light">Live Log</summary>
|
||||
<pre class="log-box">${escapeHtml(job.output_log)}</pre>
|
||||
</details>` : ""}
|
||||
</li>`;
|
||||
|
||||
const renderDone = job => `
|
||||
const d = 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>
|
||||
|
||||
<small>Size: ${formatBytes(job.fileSize || 0)}</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>` : ""}
|
||||
<details data-id="done-${job._id}">
|
||||
<summary class="text-light">Show Log</summary>
|
||||
<pre class="log-box-light">${escapeHtml(job.output_log)}</pre>
|
||||
</details>` : ""}
|
||||
</li>`;
|
||||
|
||||
const renderFailed = job => `
|
||||
const f = 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>` : ""}
|
||||
<details data-id="failed-${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(renderQueued).join("") :
|
||||
`<li class="list-group-item">No queued jobs</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>`;
|
||||
|
||||
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;
|
||||
// Restore open <details>
|
||||
document.querySelectorAll("details").forEach(d => {
|
||||
if (openMap.has(d.dataset.id)) {
|
||||
d.open = true;
|
||||
}
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
@@ -262,8 +304,15 @@ ${job.output_log}
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
return text.replace(/[&<>"']/g, c =>
|
||||
({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c])
|
||||
);
|
||||
}
|
||||
|
||||
setInterval(refreshStatus, 3000);
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<%- include("partials/footer") %>
|
||||
Reference in new issue
Block a user