phase 2 rework
This commit is contained in:
1 parent
20054198f3
commit
b397ea9256
44 files changed
+5528
-1377
No files matched your search
+24
-7
@@ -29,6 +29,14 @@ function positiveInteger(value, label) {
|
||||
return number;
|
||||
}
|
||||
|
||||
function seasonNumber(value) {
|
||||
const text = typeof value === "number" ? String(value) : value;
|
||||
if (typeof text !== "string" || !/^(0|[1-9]\d*)$/.test(text) || !Number.isSafeInteger(Number(text))) {
|
||||
throw new ValidationError("Season must be a whole number of zero or greater within the supported range.");
|
||||
}
|
||||
return Number(text);
|
||||
}
|
||||
|
||||
function isWellFormedText(value) {
|
||||
// In Unicode mode a valid surrogate pair is one code point outside this range.
|
||||
// Lone surrogates would otherwise be replaced silently when converted to UTF-8.
|
||||
@@ -115,17 +123,16 @@ function optionalTitle(value) {
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
async function buildQueueJobs(body, config, now = () => new Date()) {
|
||||
async function planQueueJobs(body, config, now = () => new Date()) {
|
||||
if (!body || typeof body !== "object" || Array.isArray(body)) throw new ValidationError("Invalid download request.");
|
||||
if (body.mode !== "video" && body.mode !== "series") throw new ValidationError("Choose video or series mode.");
|
||||
const token = cookieToken(body.token, config.tokenPrefix);
|
||||
const created_at = now();
|
||||
const jobs = [];
|
||||
if (body.mode === "video") {
|
||||
const source = normalizeWatchUrl(body.url);
|
||||
const filename = normalizeFilename(optionalTitle(body.filename) || optionalTitle(body.name)
|
||||
|| `${source.id} E${source.episode} ${source.language}`);
|
||||
jobs.push({ url: source.url, token, filename, created_at });
|
||||
jobs.push({ url: source.url, filename, created_at });
|
||||
} else {
|
||||
const id = positiveInteger(body.id, "Series ID");
|
||||
const from = positiveInteger(body.episode_from, "First episode");
|
||||
@@ -137,11 +144,15 @@ async function buildQueueJobs(body, config, now = () => new Date()) {
|
||||
if (!LANGUAGES.has(body.language)) throw new ValidationError("Choose a supported language.");
|
||||
const name = optionalTitle(body.name) || String(id);
|
||||
const pad = String(to).length;
|
||||
// Older direct API clients omit season and keep their established names.
|
||||
// The web form always sends a season, including zero for specials.
|
||||
const season = body.season === undefined ? null : seasonNumber(body.season);
|
||||
for (let ep = from; ep <= to; ep += 1) {
|
||||
jobs.push({
|
||||
url: `https://proxer.me/watch/${id}/${ep}/${body.language}`,
|
||||
token,
|
||||
filename: normalizeFilename(`${name}E${String(ep).padStart(pad, "0")}_${body.language}`),
|
||||
filename: normalizeFilename(season === null
|
||||
? `${name}E${String(ep).padStart(pad, "0")}_${body.language}`
|
||||
: `${name}S${String(season).padStart(3, "0")}E${String(ep).padStart(3, "0")}_${body.language}`),
|
||||
created_at,
|
||||
});
|
||||
}
|
||||
@@ -151,6 +162,12 @@ async function buildQueueJobs(body, config, now = () => new Date()) {
|
||||
return jobs;
|
||||
}
|
||||
|
||||
async function buildQueueJobs(body, config, now = () => new Date()) {
|
||||
const jobs = await planQueueJobs(body, config, now);
|
||||
const token = cookieToken(body.token, config.tokenPrefix);
|
||||
return jobs.map(job => ({ ...job, token }));
|
||||
}
|
||||
|
||||
function sanitizeLog(value, sensitiveValues = []) {
|
||||
if (typeof value !== "string") return "";
|
||||
let result = value;
|
||||
@@ -191,6 +208,6 @@ function toPublicJob(job) {
|
||||
|
||||
module.exports = {
|
||||
ValidationError, LANGUAGES, MAX_LOG_BYTES, STATUS_READ_PROJECTION,
|
||||
positiveInteger, normalizeWatchUrl, normalizeFilename, validateOutputTarget,
|
||||
cookieToken, buildQueueJobs, sanitizeLog, toPublicJob,
|
||||
positiveInteger, seasonNumber, normalizeWatchUrl, normalizeFilename, validateOutputTarget,
|
||||
cookieToken, planQueueJobs, buildQueueJobs, sanitizeLog, toPublicJob,
|
||||
};
|
||||
Reference in new issue
Block a user