From d97600122edc0662e22c5ef4f24be901f6b7e283 Mon Sep 17 00:00:00 2001 From: DeSqBlocki Date: Sat, 6 Dec 2025 16:07:42 +0100 Subject: [PATCH] added padding leading zero --- controllers/queueController.js | 69 +++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/controllers/queueController.js b/controllers/queueController.js index b4cfc05..dec08ce 100644 --- a/controllers/queueController.js +++ b/controllers/queueController.js @@ -18,12 +18,13 @@ exports.enqueue = async (req, res) => { // ========================================= if (body.mode === "video") { if (!body.url) throw new Error("url required"); - var filename + var filename; if (!body.filename) { - let split_slash = body.url.split('/') - let split_hash = `${split_slash[4]} E${split_slash[5]} ${split_slash[6]}`.split('#') - filename = split_hash[0] - console.log(filename) + let split_slash = body.url.split("/"); + let split_hash = + `${split_slash[4]} E${split_slash[5]} ${split_slash[6]}`.split("#"); + filename = split_hash[0]; + console.log(filename); } else { filename = body.filename; } @@ -32,7 +33,7 @@ exports.enqueue = async (req, res) => { url: body.url, token, filename, - created_at: new Date() + created_at: new Date(), }); return res.redirect("/status"); @@ -52,7 +53,7 @@ exports.enqueue = async (req, res) => { const name = body.name?.trim() || null; const from = parseInt(body.episode_from); - const to = parseInt(body.episode_to); + const to = parseInt(body.episode_to); if (isNaN(from) || from <= 0) throw new Error("episode_from must be a valid number"); @@ -63,13 +64,17 @@ exports.enqueue = async (req, res) => { // Insert one queue item per episode const ops = []; + // Determine padding width based on the highest episode number + const pad = String(to).length; + for (let ep = from; ep <= to; ep++) { + const epStr = String(ep).padStart(pad, "0"); + const url = `https://proxer.me/watch/${id}/${ep}/${lang}`; - const filename = - name - ? `${name}_E${ep}.mp4` - : `${id}_${ep}_${lang}.mp4`; + const filename = name + ? `${name}_E${epStr}.mp4` + : `${id}_${epStr}_${lang}.mp4`; ops.push({ insertOne: { @@ -77,9 +82,9 @@ exports.enqueue = async (req, res) => { url, token, filename, - created_at: new Date() - } - } + created_at: new Date(), + }, + }, }); } @@ -89,74 +94,78 @@ exports.enqueue = async (req, res) => { } throw new Error("Invalid mode"); - } catch (err) { res.render("error", { title: "Enqueue Failed", message: err.message, - details: err.stack + details: err.stack, }); } }; - exports.status = async (req, res) => { const db = await getDb(); - const queued = await db.collection("queue") - .find({ $or: [ { processing: { $exists: false } }, { processing: false } ] }) + const queued = await db + .collection("queue") + .find({ $or: [{ processing: { $exists: false } }, { processing: false }] }) .sort({ created_at: 1 }) .toArray(); - const processing = await db.collection("queue") + const processing = await db + .collection("queue") .find({ processing: true }) .sort({ created_at: 1 }) .toArray(); - const done = await db.collection("done") + const done = await db + .collection("done") .find({}) .sort({ finished_at: -1 }) .toArray(); - const failed = await db.collection("failed") + const failed = await db + .collection("failed") .find({}) .sort({ failed_at: -1 }) .toArray(); - + res.render("status", { title: "Queue Status", queued, processing, finished: done, - failed + failed, }); }; - exports.statusData = async (req, res) => { const db = await getDb(); - const queued = await db.collection("queue") + const queued = await db + .collection("queue") .find({ processing: { $ne: true } }) .sort({ created_at: 1 }) .toArray(); - const processing = await db.collection("queue") + const processing = await db + .collection("queue") .find({ processing: true }) .sort({ created_at: 1 }) .toArray(); - const done = await db.collection("done") + const done = await db + .collection("done") .find({}) .sort({ finished_at: -1 }) .toArray(); - const failed = await db.collection("failed") + const failed = await db + .collection("failed") .find({}) .sort({ failed_at: -1 }) .toArray(); - // =========================== // FILE SIZE FOR DONE // ===========================