diff --git a/queue_worker.js b/queue_worker.js index 8922c25..a668fac 100644 --- a/queue_worker.js +++ b/queue_worker.js @@ -1,6 +1,6 @@ // proxer-queue-worker.js const { exec } = require("child_process"); -const { spawn } = require('child_process'); +const { spawn } = require("child_process"); const { MongoClient } = require("mongodb"); const path = require("path"); require("dotenv").config(); @@ -34,21 +34,23 @@ async function runJob(job) { const cmd = [ process.env.VENV_PYTHON, path.join(__dirname, "scripts/proxer-dl-video.py"), - "-u", job.url, - "-f", job.filename, - "-t", job.token, - "-o", process.env.OUTPUT_DIR + "-u", + job.url, + "-f", + job.filename, + "-t", + job.token, + "-o", + process.env.OUTPUT_DIR, ]; const proc = spawn(cmd[0], cmd.slice(1)); let output = ""; - proc.stdout.on("data", d => output += d.toString()); - proc.stderr.on("data", d => output += d.toString()); + proc.stdout.on("data", (d) => (output += d.toString())); + proc.stderr.on("data", (d) => (output += d.toString())); - const exitCode = await new Promise(resolve => - proc.on("close", resolve) - ); + const exitCode = await new Promise((resolve) => proc.on("close", resolve)); // ========== CAPTCHA / ERROR DETECTION ========== const suspicious = @@ -58,14 +60,21 @@ async function runJob(job) { output.toLowerCase().includes("blocked") || output.toLowerCase().includes("token") || output.toLowerCase().includes("forbidden"); + if (suspicious) { console.log("⛔ CAPTCHA or fatal error detected, notifying system"); - console.log(output) + console.log(output); await failedCol.insertOne({ filename: job.filename, failed_at: new Date(), - output_log: output + output_log: output, }); + + // Unset the processing flag so the job isn't stuck + await queueCol.updateOne( + { _id: job._id }, + { $unset: { processing: "" } } + ); return true; // signals worker to halt globally } @@ -73,19 +82,17 @@ async function runJob(job) { await doneCol.insertOne({ filename: job.filename, finished_at: new Date(), - output_log: output + output_log: output, }); await queueCol.deleteOne({ _id: job._id }); return false; - } catch (err) { console.error("Worker crash:", err); return true; } } - // ======================== // MAIN LOOP // ======================== diff --git a/routes/index.js b/routes/index.js index fc7f32d..8047a2f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -30,10 +30,19 @@ router.get("/status-data", queue.statusData); // ======================= router.post("/clear-captcha", async (req, res) => { const db = await getDb(); - await db.collection("settings").updateOne( - { _id: "global" }, - { $set: { captcha_blocked: false } } - ); + await db + .collection("settings") + .updateOne({ _id: "global" }, { $set: { captcha_blocked: false } }); + // Redirect to status, controller fetches everything + res.redirect("/status"); +}); + +router.post("/clear-failed", async (req, res) => { + const db = await getDb(); + await db + .collection("failed") + .deleteMany({}) //delete all + // Redirect to status, controller fetches everything res.redirect("/status"); }); diff --git a/views/partials/header.ejs b/views/partials/header.ejs index de69878..1fafc58 100644 --- a/views/partials/header.ejs +++ b/views/partials/header.ejs @@ -26,6 +26,9 @@