Added debug statements.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { logger } from "../server";
|
||||||
import GenerateThumbnail from "../util/generateThumbnail";
|
import GenerateThumbnail from "../util/generateThumbnail";
|
||||||
import MediaFile from "../util/interfaces/MediaFile";
|
import MediaFile from "../util/interfaces/MediaFile";
|
||||||
import GenerateUrl from "../util/MediaUrlGen";
|
import GenerateUrl from "../util/MediaUrlGen";
|
||||||
@@ -10,7 +11,9 @@ import { FolderPaths } from "../util/serverInit";
|
|||||||
export async function JobsListMedia(req: Request, res: Response) {
|
export async function JobsListMedia(req: Request, res: Response) {
|
||||||
const jobid: string = (req.body.jobid || "").trim();
|
const jobid: string = (req.body.jobid || "").trim();
|
||||||
await fs.ensureDir(PathToRoFolder(jobid));
|
await fs.ensureDir(PathToRoFolder(jobid));
|
||||||
|
logger.debug("Listing media for job.", PathToRoFolder(jobid));
|
||||||
let ret: MediaFile[];
|
let ret: MediaFile[];
|
||||||
|
try {
|
||||||
if (req.files) {
|
if (req.files) {
|
||||||
//We just uploaded files, we're going to send only those back.
|
//We just uploaded files, we're going to send only those back.
|
||||||
ret = await Promise.all(
|
ret = await Promise.all(
|
||||||
@@ -71,4 +74,7 @@ export async function JobsListMedia(req: Request, res: Response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.json(ret);
|
res.json(ret);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ import { FolderPaths } from "../util/serverInit";
|
|||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
import { JobsListMedia } from "./jobsListMedia";
|
import { JobsListMedia } from "./jobsListMedia";
|
||||||
import { PathToRoFolder } from "../util/pathGenerators";
|
import { PathToRoFolder } from "../util/pathGenerators";
|
||||||
|
import { logger } from "../server";
|
||||||
|
|
||||||
export async function JobsMoveMedia(req: Request, res: Response) {
|
export async function JobsMoveMedia(req: Request, res: Response) {
|
||||||
const jobid: string = (req.body.jobid || "").trim();
|
const jobid: string = (req.body.jobid || "").trim();
|
||||||
const from_jobid: string = (req.body.from_jobid || "").trim();
|
const from_jobid: string = (req.body.from_jobid || "").trim();
|
||||||
const files: string[] = req.body.files; //Just file names.
|
const files: string[] = req.body.files; //Just file names.
|
||||||
|
|
||||||
|
try {
|
||||||
//Validate the request is valid and contains everything that it needs.
|
//Validate the request is valid and contains everything that it needs.
|
||||||
|
|
||||||
if (from_jobid === "") {
|
if (from_jobid === "") {
|
||||||
@@ -25,7 +27,7 @@ export async function JobsMoveMedia(req: Request, res: Response) {
|
|||||||
}
|
}
|
||||||
//Make sure the destination RO directory exists.
|
//Make sure the destination RO directory exists.
|
||||||
await fs.ensureDir(PathToRoFolder(jobid));
|
await fs.ensureDir(PathToRoFolder(jobid));
|
||||||
|
logger.debug("Moving job based media.", { jobid, from_jobid, files });
|
||||||
const movingQueue: Promise<void>[] = [];
|
const movingQueue: Promise<void>[] = [];
|
||||||
|
|
||||||
files.forEach((file) => {
|
files.forEach((file) => {
|
||||||
@@ -38,7 +40,12 @@ export async function JobsMoveMedia(req: Request, res: Response) {
|
|||||||
|
|
||||||
movingQueue.push(
|
movingQueue.push(
|
||||||
fs.move(
|
fs.move(
|
||||||
path.join(FolderPaths.Jobs, from_jobid, FolderPaths.ThumbsSubDir, file),
|
path.join(
|
||||||
|
FolderPaths.Jobs,
|
||||||
|
from_jobid,
|
||||||
|
FolderPaths.ThumbsSubDir,
|
||||||
|
file
|
||||||
|
),
|
||||||
path.join(FolderPaths.Jobs, jobid, FolderPaths.ThumbsSubDir, file)
|
path.join(FolderPaths.Jobs, jobid, FolderPaths.ThumbsSubDir, file)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -48,7 +55,6 @@ export async function JobsMoveMedia(req: Request, res: Response) {
|
|||||||
//e.g. if the thumbnail does not exist.
|
//e.g. if the thumbnail does not exist.
|
||||||
await Promise.allSettled(movingQueue);
|
await Promise.allSettled(movingQueue);
|
||||||
|
|
||||||
try {
|
|
||||||
JobsListMedia(req, res);
|
JobsListMedia(req, res);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(500).send(err);
|
res.status(500).send(err);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const JobMediaUploadMulter = multer({
|
|||||||
cb(null, DestinationFolder);
|
cb(null, DestinationFolder);
|
||||||
},
|
},
|
||||||
filename: function (req, file, cb) {
|
filename: function (req, file, cb) {
|
||||||
logger.info("Uploading file: ", path.basename(file.originalname));
|
logger.debug("Uploading file: ", path.basename(file.originalname));
|
||||||
cb(null, generateUniqueFilename(file));
|
cb(null, generateUniqueFilename(file));
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -33,6 +33,10 @@ export async function jobsUploadMedia(req: Request, res: Response) {
|
|||||||
message: "No file uploaded",
|
message: "No file uploaded",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
logger.log(
|
||||||
|
"Creating thumbnails for newly uploaded media",
|
||||||
|
(req.files as Express.Multer.File[]).map((f) => f.filename)
|
||||||
|
);
|
||||||
const thumbnailGenerationQueue: Promise<string>[] = [];
|
const thumbnailGenerationQueue: Promise<string>[] = [];
|
||||||
|
|
||||||
//for each file.path, generate the thumbnail.
|
//for each file.path, generate the thumbnail.
|
||||||
@@ -40,9 +44,8 @@ export async function jobsUploadMedia(req: Request, res: Response) {
|
|||||||
thumbnailGenerationQueue.push(GenerateThumbnail(file.path));
|
thumbnailGenerationQueue.push(GenerateThumbnail(file.path));
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug("Pre await", thumbnailGenerationQueue.toString());
|
|
||||||
await Promise.all(thumbnailGenerationQueue);
|
await Promise.all(thumbnailGenerationQueue);
|
||||||
logger.debug("Post Await", thumbnailGenerationQueue.toString());
|
|
||||||
JobsListMedia(req, res);
|
JobsListMedia(req, res);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user