From 411ae23068157d45455d2cac6c67637db9be9aed Mon Sep 17 00:00:00 2001 From: DeSqBlocki Date: Sat, 6 Dec 2025 15:52:34 +0100 Subject: [PATCH] added live update and file size to status --- controllers/queueController.js | 57 +++++++- routes/index.js | 2 +- views/index.ejs | 2 +- views/status.ejs | 231 ++++++++++++++++++++++----------- 4 files changed, 214 insertions(+), 78 deletions(-) diff --git a/controllers/queueController.js b/controllers/queueController.js index 72ea8b4..b4cfc05 100644 --- a/controllers/queueController.js +++ b/controllers/queueController.js @@ -1,4 +1,6 @@ const { getDb } = require("../lib/mongo"); +const fs = require("fs"); +const path = require("path"); exports.enqueue = async (req, res) => { try { @@ -120,7 +122,7 @@ exports.status = async (req, res) => { .find({}) .sort({ failed_at: -1 }) .toArray(); - + res.render("status", { title: "Queue Status", queued, @@ -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 }); +}; diff --git a/routes/index.js b/routes/index.js index dc611bd..17cd353 100644 --- a/routes/index.js +++ b/routes/index.js @@ -7,7 +7,7 @@ router.get("/", (req, res) => ); router.post("/queue", queue.enqueue); // <-- FIXED - +router.get("/status-data", queue.statusData); router.get("/status", queue.status); module.exports = router; diff --git a/views/index.ejs b/views/index.ejs index 57a81f7..ddedcd5 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -4,7 +4,7 @@
- +
diff --git a/views/status.ejs b/views/status.ejs index a0e4612..5b05da2 100644 --- a/views/status.ejs +++ b/views/status.ejs @@ -1,26 +1,21 @@ <%- include("partials/header") %>
-

Queued

-
    - +
      <% queued.forEach(job => { %> -
    • - <%= job.filename %>
      - <%= job.url %>
      - <%= new Date(job.created_at).toLocaleString() %> -
    • - <% }) %> - - <% if (queued.length === 0) { %> -
    • No queued jobs
    • +
    • + <%= job.filename %>
      + <%= job.url %>
      + <%= new Date(job.created_at).toLocaleString() %> +
    • + <% }) %> <% if (queued.length === 0) { %> +
    • No queued jobs
    • <% } %> -
@@ -28,33 +23,40 @@
-

Processing

-
    - +

    Processing

    +
      <% processing.forEach(job => { %> -
    • - <%= job.filename %> - -
      - <%= job.url %>
      - Started: <%= new Date(job.created_at).toLocaleString() %> +
    • + <%= job.filename %> + +
      + <%= job.url %>
      + Started: <%= new Date(job.created_at).toLocaleString() %> - <% if (job.output_log) { %> -
      - Live Log -
      +        <% if (job.output_log) { %>
      +        
      + Live Log +
       <%= job.output_log %>
      -              
      -
      - <% } %> - -
    • - <% }) %> - - <% if (processing.length === 0) { %> -
    • Nothing processing
    • + + + <% } %> + + <% }) %> <% if (processing.length === 0) { %> +
    • Nothing processing
    • <% } %> -
@@ -63,29 +65,33 @@

Done

-
    - +
      <% finished.forEach(job => { %> -
    • - <%= job.filename %>
      - <%= new Date(job.finished_at).toLocaleString() %>
      +
    • + <%= job.filename %>
      + <%= new Date(job.finished_at).toLocaleString() %>
      - <% if (job.output_log) { %> -
      - Show Log -
      +        <% if (job.output_log) { %>
      +        
      + Show Log +
       <%= job.output_log %>
      -              
      -
      - <% } %> - -
    • - <% }) %> - - <% if (finished.length === 0) { %> -
    • No completed jobs
    • + + + <% } %> + + <% }) %> <% if (finished.length === 0) { %> +
    • No completed jobs
    • <% } %> -
@@ -94,32 +100,107 @@

Failed

-
    - +
      <% failed.forEach(job => { %> -
    • - <%= job.filename %>
      - <%= new Date(job.failed_at).toLocaleString() %>
      +
    • + <%= job.filename %>
      + <%= new Date(job.failed_at).toLocaleString() %>
      - <% if (job.output_log) { %> -
      - Show Error Log -
      +        <% if (job.output_log) { %>
      +        
      + Show Error Log +
       <%= job.output_log %>
      -              
      -
      - <% } %> - -
    • - <% }) %> - - <% if (failed.length === 0) { %> -
    • No failed jobs
    • + + + <% } %> + + <% }) %> <% if (failed.length === 0) { %> +
    • No failed jobs
    • <% } %> -
-
+ + + + + <%- include("partials/footer") %>