added padding leading zero

This commit is contained in:
DeSqBlocki committed 2025-12-06 16:07:42 +01:00
1 parent 411ae23068
commit d97600122e
1 file changed
+39 -30
+39 -30
View File
@@ -18,12 +18,13 @@ exports.enqueue = async (req, res) => {
// ========================================= // =========================================
if (body.mode === "video") { if (body.mode === "video") {
if (!body.url) throw new Error("url required"); if (!body.url) throw new Error("url required");
var filename var filename;
if (!body.filename) { if (!body.filename) {
let split_slash = body.url.split('/') let split_slash = body.url.split("/");
let split_hash = `${split_slash[4]} E${split_slash[5]} ${split_slash[6]}`.split('#') let split_hash =
filename = split_hash[0] `${split_slash[4]} E${split_slash[5]} ${split_slash[6]}`.split("#");
console.log(filename) filename = split_hash[0];
console.log(filename);
} else { } else {
filename = body.filename; filename = body.filename;
} }
@@ -32,7 +33,7 @@ exports.enqueue = async (req, res) => {
url: body.url, url: body.url,
token, token,
filename, filename,
created_at: new Date() created_at: new Date(),
}); });
return res.redirect("/status"); return res.redirect("/status");
@@ -52,7 +53,7 @@ exports.enqueue = async (req, res) => {
const name = body.name?.trim() || null; const name = body.name?.trim() || null;
const from = parseInt(body.episode_from); const from = parseInt(body.episode_from);
const to = parseInt(body.episode_to); const to = parseInt(body.episode_to);
if (isNaN(from) || from <= 0) if (isNaN(from) || from <= 0)
throw new Error("episode_from must be a valid number"); 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 // Insert one queue item per episode
const ops = []; const ops = [];
// Determine padding width based on the highest episode number
const pad = String(to).length;
for (let ep = from; ep <= to; ep++) { for (let ep = from; ep <= to; ep++) {
const epStr = String(ep).padStart(pad, "0");
const url = `https://proxer.me/watch/${id}/${ep}/${lang}`; const url = `https://proxer.me/watch/${id}/${ep}/${lang}`;
const filename = const filename = name
name ? `${name}_E${epStr}.mp4`
? `${name}_E${ep}.mp4` : `${id}_${epStr}_${lang}.mp4`;
: `${id}_${ep}_${lang}.mp4`;
ops.push({ ops.push({
insertOne: { insertOne: {
@@ -77,9 +82,9 @@ exports.enqueue = async (req, res) => {
url, url,
token, token,
filename, filename,
created_at: new Date() created_at: new Date(),
} },
} },
}); });
} }
@@ -89,74 +94,78 @@ exports.enqueue = async (req, res) => {
} }
throw new Error("Invalid mode"); throw new Error("Invalid mode");
} catch (err) { } catch (err) {
res.render("error", { res.render("error", {
title: "Enqueue Failed", title: "Enqueue Failed",
message: err.message, message: err.message,
details: err.stack details: err.stack,
}); });
} }
}; };
exports.status = async (req, res) => { exports.status = async (req, res) => {
const db = await getDb(); const db = await getDb();
const queued = await db.collection("queue") const queued = await db
.find({ $or: [ { processing: { $exists: false } }, { processing: false } ] }) .collection("queue")
.find({ $or: [{ processing: { $exists: false } }, { processing: false }] })
.sort({ created_at: 1 }) .sort({ created_at: 1 })
.toArray(); .toArray();
const processing = await db.collection("queue") const processing = await db
.collection("queue")
.find({ processing: true }) .find({ processing: true })
.sort({ created_at: 1 }) .sort({ created_at: 1 })
.toArray(); .toArray();
const done = await db.collection("done") const done = await db
.collection("done")
.find({}) .find({})
.sort({ finished_at: -1 }) .sort({ finished_at: -1 })
.toArray(); .toArray();
const failed = await db.collection("failed") const failed = await db
.collection("failed")
.find({}) .find({})
.sort({ failed_at: -1 }) .sort({ failed_at: -1 })
.toArray(); .toArray();
res.render("status", { res.render("status", {
title: "Queue Status", title: "Queue Status",
queued, queued,
processing, processing,
finished: done, finished: done,
failed failed,
}); });
}; };
exports.statusData = async (req, res) => { exports.statusData = async (req, res) => {
const db = await getDb(); const db = await getDb();
const queued = await db.collection("queue") const queued = await db
.collection("queue")
.find({ processing: { $ne: true } }) .find({ processing: { $ne: true } })
.sort({ created_at: 1 }) .sort({ created_at: 1 })
.toArray(); .toArray();
const processing = await db.collection("queue") const processing = await db
.collection("queue")
.find({ processing: true }) .find({ processing: true })
.sort({ created_at: 1 }) .sort({ created_at: 1 })
.toArray(); .toArray();
const done = await db.collection("done") const done = await db
.collection("done")
.find({}) .find({})
.sort({ finished_at: -1 }) .sort({ finished_at: -1 })
.toArray(); .toArray();
const failed = await db.collection("failed") const failed = await db
.collection("failed")
.find({}) .find({})
.sort({ failed_at: -1 }) .sort({ failed_at: -1 })
.toArray(); .toArray();
// =========================== // ===========================
// FILE SIZE FOR DONE // FILE SIZE FOR DONE
// =========================== // ===========================