Added debug statements.

This commit is contained in:
Patrick Fic
2022-05-10 14:53:58 -07:00
parent 270be1d360
commit 16e2852994
3 changed files with 111 additions and 96 deletions

View File

@@ -7,48 +7,54 @@ import { FolderPaths } from "../util/serverInit";
import multer from "multer";
import { JobsListMedia } from "./jobsListMedia";
import { PathToRoFolder } from "../util/pathGenerators";
import { logger } from "../server";
export async function JobsMoveMedia(req: Request, res: Response) {
const jobid: string = (req.body.jobid || "").trim();
const from_jobid: string = (req.body.from_jobid || "").trim();
const files: string[] = req.body.files; //Just file names.
//Validate the request is valid and contains everything that it needs.
if (from_jobid === "") {
res.status(400).json({ error: "from_jobid must be specified. " });
return;
}
if (files.length === 0) {
res.status(400).json({ error: "files must be specified. " });
return;
}
//Make sure the destination RO directory exists.
await fs.ensureDir(PathToRoFolder(jobid));
const movingQueue: Promise<void>[] = [];
files.forEach((file) => {
movingQueue.push(
fs.move(
path.join(FolderPaths.Jobs, from_jobid, file),
path.join(FolderPaths.Jobs, jobid, file)
)
);
movingQueue.push(
fs.move(
path.join(FolderPaths.Jobs, from_jobid, FolderPaths.ThumbsSubDir, file),
path.join(FolderPaths.Jobs, jobid, FolderPaths.ThumbsSubDir, file)
)
);
});
//Use AllSettled as it allows for individual moves to fail.
//e.g. if the thumbnail does not exist.
await Promise.allSettled(movingQueue);
try {
//Validate the request is valid and contains everything that it needs.
if (from_jobid === "") {
res.status(400).json({ error: "from_jobid must be specified. " });
return;
}
if (files.length === 0) {
res.status(400).json({ error: "files must be specified. " });
return;
}
//Make sure the destination RO directory exists.
await fs.ensureDir(PathToRoFolder(jobid));
logger.debug("Moving job based media.", { jobid, from_jobid, files });
const movingQueue: Promise<void>[] = [];
files.forEach((file) => {
movingQueue.push(
fs.move(
path.join(FolderPaths.Jobs, from_jobid, file),
path.join(FolderPaths.Jobs, jobid, file)
)
);
movingQueue.push(
fs.move(
path.join(
FolderPaths.Jobs,
from_jobid,
FolderPaths.ThumbsSubDir,
file
),
path.join(FolderPaths.Jobs, jobid, FolderPaths.ThumbsSubDir, file)
)
);
});
//Use AllSettled as it allows for individual moves to fail.
//e.g. if the thumbnail does not exist.
await Promise.allSettled(movingQueue);
JobsListMedia(req, res);
} catch (err) {
res.status(500).send(err);