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
+36 -27
+36 -27
View File
@@ -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");
@@ -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,36 +94,38 @@ 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")
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();
@@ -128,35 +135,37 @@ exports.status = async (req, res) => {
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
// ===========================