added live update and file size to status
This commit is contained in:
1 parent
e5a0e942aa
commit
411ae23068
4 files changed
+186
-50
No files matched your search
@@ -1,4 +1,6 @@
|
|||||||
const { getDb } = require("../lib/mongo");
|
const { getDb } = require("../lib/mongo");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
exports.enqueue = async (req, res) => {
|
exports.enqueue = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@@ -130,3 +132,56 @@ exports.status = async (req, res) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
exports.statusData = async (req, res) => {
|
||||||
|
const db = await getDb();
|
||||||
|
|
||||||
|
const queued = await db.collection("queue")
|
||||||
|
.find({ processing: { $ne: true } })
|
||||||
|
.sort({ created_at: 1 })
|
||||||
|
.toArray();
|
||||||
|
|
||||||
|
const processing = await db.collection("queue")
|
||||||
|
.find({ processing: true })
|
||||||
|
.sort({ created_at: 1 })
|
||||||
|
.toArray();
|
||||||
|
|
||||||
|
const done = await db.collection("done")
|
||||||
|
.find({})
|
||||||
|
.sort({ finished_at: -1 })
|
||||||
|
.toArray();
|
||||||
|
|
||||||
|
const failed = await db.collection("failed")
|
||||||
|
.find({})
|
||||||
|
.sort({ failed_at: -1 })
|
||||||
|
.toArray();
|
||||||
|
|
||||||
|
|
||||||
|
// ===========================
|
||||||
|
// FILE SIZE FOR DONE
|
||||||
|
// ===========================
|
||||||
|
for (let job of done) {
|
||||||
|
try {
|
||||||
|
const filePath = path.join(process.env.OUTPUT_DIR, `${job.filename}.mp4`);
|
||||||
|
const stats = fs.statSync(filePath);
|
||||||
|
job.fileSize = stats.size;
|
||||||
|
} catch {
|
||||||
|
job.fileSize = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================
|
||||||
|
// FILE SIZE FOR PROCESSING
|
||||||
|
// ===========================
|
||||||
|
for (let job of processing) {
|
||||||
|
try {
|
||||||
|
const filePath = path.join(process.env.OUTPUT_DIR, `${job.filename}.mp4`);
|
||||||
|
const stats = fs.statSync(filePath);
|
||||||
|
job.fileSize = stats.size;
|
||||||
|
} catch {
|
||||||
|
job.fileSize = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({ queued, processing, done, failed });
|
||||||
|
};
|
||||||
+1
-1
@@ -7,7 +7,7 @@ router.get("/", (req, res) =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
router.post("/queue", queue.enqueue); // <-- FIXED
|
router.post("/queue", queue.enqueue); // <-- FIXED
|
||||||
|
router.get("/status-data", queue.statusData);
|
||||||
router.get("/status", queue.status);
|
router.get("/status", queue.status);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
<div class="d-flex justify-content-center mb-3">
|
<div class="d-flex justify-content-center mb-3">
|
||||||
<div class="form-check form-switch">
|
<div class="form-check form-switch">
|
||||||
<input class="form-check-input" type="checkbox" id="modeToggle">
|
<input class="form-check-input" type="checkbox" id="modeToggle">
|
||||||
<label class="form-check-label text-muted" for="modeToggle" id="modeLabel">Series</label>
|
<label class="form-check-label " for="modeToggle" id="modeLabel">Series</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+129
-48
@@ -1,26 +1,21 @@
|
|||||||
<%- include("partials/header") %>
|
<%- include("partials/header") %>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<!-- QUEUED -->
|
<!-- QUEUED -->
|
||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<h3>Queued</h3>
|
<h3>Queued</h3>
|
||||||
<ul class="list-group">
|
<ul class="list-group" id="queuedList">
|
||||||
|
|
||||||
<% queued.forEach(job => { %>
|
<% queued.forEach(job => { %>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong><%= job.filename %></strong><br>
|
<strong><%= job.filename %></strong><br />
|
||||||
<small><%= job.url %></small><br>
|
<small><%= job.url %></small><br />
|
||||||
<small><%= new Date(job.created_at).toLocaleString() %></small>
|
<small><%= new Date(job.created_at).toLocaleString() %></small>
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% }) %> <% if (queued.length === 0) { %>
|
||||||
|
<li class="list-group-item">No queued jobs</li>
|
||||||
<% if (queued.length === 0) { %>
|
|
||||||
<li class="list-group-item text-muted">No queued jobs</li>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -29,32 +24,39 @@
|
|||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<h3 style="color: #58a6ff">Processing</h3>
|
<h3 style="color: #58a6ff">Processing</h3>
|
||||||
<ul class="list-group">
|
<ul class="list-group" id="processingList">
|
||||||
|
|
||||||
<% processing.forEach(job => { %>
|
<% processing.forEach(job => { %>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong style="color: #58a6ff"><%= job.filename %></strong>
|
<strong style="color: #58a6ff"><%= job.filename %></strong>
|
||||||
<span class="spinner-border spinner-border-sm ms-2" style="color:#58a6ff"></span>
|
<span
|
||||||
<br>
|
class="spinner-border spinner-border-sm ms-2"
|
||||||
<small><%= job.url %></small><br>
|
style="color: #58a6ff"
|
||||||
|
></span>
|
||||||
|
<br />
|
||||||
|
<small><%= job.url %></small><br />
|
||||||
<small>Started: <%= new Date(job.created_at).toLocaleString() %></small>
|
<small>Started: <%= new Date(job.created_at).toLocaleString() %></small>
|
||||||
|
|
||||||
<% if (job.output_log) { %>
|
<% if (job.output_log) { %>
|
||||||
<details class="mt-2">
|
<details class="mt-2">
|
||||||
<summary class="text-light">Live Log</summary>
|
<summary class="text-light">Live Log</summary>
|
||||||
<pre style="background:#001122; color:#9cf; padding:10px; border-radius:5px; white-space:pre-wrap;">
|
<pre
|
||||||
|
style="
|
||||||
|
background: #001122;
|
||||||
|
color: #9cf;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
"
|
||||||
|
>
|
||||||
<%= job.output_log %>
|
<%= job.output_log %>
|
||||||
</pre>
|
</pre
|
||||||
|
>
|
||||||
</details>
|
</details>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% }) %> <% if (processing.length === 0) { %>
|
||||||
|
<li class="list-group-item">Nothing processing</li>
|
||||||
<% if (processing.length === 0) { %>
|
|
||||||
<li class="list-group-item text-muted">Nothing processing</li>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -63,29 +65,33 @@
|
|||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<h3 class="text-success">Done</h3>
|
<h3 class="text-success">Done</h3>
|
||||||
<ul class="list-group">
|
<ul class="list-group" id="doneList">
|
||||||
|
|
||||||
<% finished.forEach(job => { %>
|
<% finished.forEach(job => { %>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong class="text-success"><%= job.filename %></strong><br>
|
<strong class="text-success"><%= job.filename %></strong><br />
|
||||||
<small><%= new Date(job.finished_at).toLocaleString() %></small><br>
|
<small><%= new Date(job.finished_at).toLocaleString() %></small><br />
|
||||||
|
|
||||||
<% if (job.output_log) { %>
|
<% if (job.output_log) { %>
|
||||||
<details class="mt-2">
|
<details class="mt-2">
|
||||||
<summary class="text-light">Show Log</summary>
|
<summary class="text-light">Show Log</summary>
|
||||||
<pre style="background:#222; color:#e0e0e0; padding:10px; border-radius:5px; white-space:pre-wrap;">
|
<pre
|
||||||
|
style="
|
||||||
|
background: #222;
|
||||||
|
color: #e0e0e0;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
"
|
||||||
|
>
|
||||||
<%= job.output_log %>
|
<%= job.output_log %>
|
||||||
</pre>
|
</pre
|
||||||
|
>
|
||||||
</details>
|
</details>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% }) %> <% if (finished.length === 0) { %>
|
||||||
|
<li class="list-group-item">No completed jobs</li>
|
||||||
<% if (finished.length === 0) { %>
|
|
||||||
<li class="list-group-item text-muted">No completed jobs</li>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -94,32 +100,107 @@
|
|||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<h3 class="text-danger">Failed</h3>
|
<h3 class="text-danger">Failed</h3>
|
||||||
<ul class="list-group">
|
<ul class="list-group" id="failedList">
|
||||||
|
|
||||||
<% failed.forEach(job => { %>
|
<% failed.forEach(job => { %>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong class="text-danger"><%= job.filename %></strong><br>
|
<strong class="text-danger"><%= job.filename %></strong><br />
|
||||||
<small><%= new Date(job.failed_at).toLocaleString() %></small><br>
|
<small><%= new Date(job.failed_at).toLocaleString() %></small><br />
|
||||||
|
|
||||||
<% if (job.output_log) { %>
|
<% if (job.output_log) { %>
|
||||||
<details class="mt-2">
|
<details class="mt-2">
|
||||||
<summary class="text-danger">Show Error Log</summary>
|
<summary class="text-danger">Show Error Log</summary>
|
||||||
<pre style="background:#330000; color:#ffb3b3; padding:10px; border-radius:5px; white-space:pre-wrap;">
|
<pre
|
||||||
|
style="
|
||||||
|
background: #330000;
|
||||||
|
color: #ffb3b3;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
"
|
||||||
|
>
|
||||||
<%= job.output_log %>
|
<%= job.output_log %>
|
||||||
</pre>
|
</pre
|
||||||
|
>
|
||||||
</details>
|
</details>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% }) %> <% if (failed.length === 0) { %>
|
||||||
|
<li class="list-group-item">No failed jobs</li>
|
||||||
<% if (failed.length === 0) { %>
|
|
||||||
<li class="list-group-item text-muted">No failed jobs</li>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- ======================= -->
|
||||||
|
<!-- AUTO-REFRESH SCRIPT -->
|
||||||
|
<!-- ======================= -->
|
||||||
|
<script>
|
||||||
|
async function refreshStatus() {
|
||||||
|
try {
|
||||||
|
const res = await fetch("/status-data");
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
// Helper for templates
|
||||||
|
function renderQueued(job) {
|
||||||
|
return `
|
||||||
|
<li class="list-group-item">
|
||||||
|
<strong>${job.filename}</strong><br>
|
||||||
|
<small>${job.url}</small><br>
|
||||||
|
<small>${new Date(job.created_at).toLocaleString()}</small>
|
||||||
|
</li>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderProcessing(job) {
|
||||||
|
return `
|
||||||
|
<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>
|
||||||
|
</li>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderDone(job) {
|
||||||
|
return `
|
||||||
|
<li class="list-group-item">
|
||||||
|
<strong class="text-success">${job.filename}</strong><br>
|
||||||
|
<small>${new Date(job.finished_at).toLocaleString()}</small>
|
||||||
|
</li>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderFailed(job) {
|
||||||
|
return `
|
||||||
|
<li class="list-group-item">
|
||||||
|
<strong class="text-danger">${job.filename}</strong><br>
|
||||||
|
<small>${new Date(job.failed_at).toLocaleString()}</small>
|
||||||
|
</li>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update UI lists
|
||||||
|
document.getElementById("queuedList").innerHTML = data.queued.length
|
||||||
|
? data.queued.map(renderQueued).join("")
|
||||||
|
: `<li class="list-group-item ">No queued jobs</li>`;
|
||||||
|
|
||||||
|
document.getElementById("processingList").innerHTML = data.processing
|
||||||
|
.length
|
||||||
|
? data.processing.map(renderProcessing).join("")
|
||||||
|
: `<li class="list-group-item ">Nothing processing</li>`;
|
||||||
|
|
||||||
|
document.getElementById("doneList").innerHTML = data.done.length
|
||||||
|
? data.done.map(renderDone).join("")
|
||||||
|
: `<li class="list-group-item ">No completed jobs</li>`;
|
||||||
|
|
||||||
|
document.getElementById("failedList").innerHTML = data.failed.length
|
||||||
|
? data.failed.map(renderFailed).join("")
|
||||||
|
: `<li class="list-group-item ">No failed jobs</li>`;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Status refresh error:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-refresh every 3 seconds
|
||||||
|
setInterval(refreshStatus, 3000);
|
||||||
|
</script>
|
||||||
|
|
||||||
<%- include("partials/footer") %>
|
<%- include("partials/footer") %>
|
||||||
Reference in new issue
Block a user