Change RO number to jobid.
This commit is contained in:
@@ -5,8 +5,8 @@ export default function ValidateJobBasedRequest(
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const ro_number: string = (req.body.ro_number || "").trim();
|
||||
if (ro_number === "") {
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
if (jobid === "") {
|
||||
res.status(400).json({ error: "No RO Number has been specified." });
|
||||
return;
|
||||
} else {
|
||||
|
||||
@@ -8,27 +8,27 @@ import { PathToRoFolder } from "../util/pathGenerators";
|
||||
import { FolderPaths } from "../util/serverInit";
|
||||
|
||||
export async function JobsListMedia(req: Request, res: Response) {
|
||||
const ro_number: string = (req.body.ro_number || "").trim();
|
||||
await fs.ensureDir(PathToRoFolder(ro_number));
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
await fs.ensureDir(PathToRoFolder(jobid));
|
||||
let ret: MediaFile[];
|
||||
if (req.files) {
|
||||
//We just uploaded files, we're going to send only those back.
|
||||
ret = await Promise.all(
|
||||
(req.files as Express.Multer.File[]).map(async (file) => {
|
||||
const relativeThumbPath: string = await GenerateThumbnail(
|
||||
path.join(FolderPaths.Jobs, ro_number, file.filename)
|
||||
path.join(FolderPaths.Jobs, jobid, file.filename)
|
||||
);
|
||||
return {
|
||||
src: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
ro_number,
|
||||
jobid,
|
||||
file.filename,
|
||||
]),
|
||||
thumbnail: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
ro_number,
|
||||
jobid,
|
||||
relativeThumbPath,
|
||||
]),
|
||||
thumbnailHeight: 250,
|
||||
@@ -38,7 +38,7 @@ export async function JobsListMedia(req: Request, res: Response) {
|
||||
);
|
||||
} else {
|
||||
const filesList: fs.Dirent[] = (
|
||||
await fs.readdir(PathToRoFolder(ro_number), {
|
||||
await fs.readdir(PathToRoFolder(jobid), {
|
||||
withFileTypes: true,
|
||||
})
|
||||
).filter((f) => f.isFile() && !/(^|\/)\.[^\/\.]/g.test(f.name));
|
||||
@@ -46,19 +46,19 @@ export async function JobsListMedia(req: Request, res: Response) {
|
||||
ret = await Promise.all(
|
||||
filesList.map(async (file) => {
|
||||
const relativeThumbPath: string = await GenerateThumbnail(
|
||||
path.join(FolderPaths.Jobs, ro_number, file.name)
|
||||
path.join(FolderPaths.Jobs, jobid, file.name)
|
||||
);
|
||||
return {
|
||||
src: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
ro_number,
|
||||
jobid,
|
||||
file.name,
|
||||
]),
|
||||
thumbnail: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
ro_number,
|
||||
jobid,
|
||||
relativeThumbPath,
|
||||
]),
|
||||
thumbnailHeight: 250,
|
||||
|
||||
@@ -9,7 +9,7 @@ import { JobsListMedia } from "./jobsListMedia";
|
||||
import { PathToRoFolder } from "../util/pathGenerators";
|
||||
|
||||
export async function JobsMoveMedia(req: Request, res: Response) {
|
||||
const ro_number: string = (req.body.ro_number || "").trim();
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
const from_ro: string = (req.body.from_ro || "").trim();
|
||||
const files: string[] = req.body.files; //Just file names.
|
||||
|
||||
@@ -24,7 +24,7 @@ export async function JobsMoveMedia(req: Request, res: Response) {
|
||||
return;
|
||||
}
|
||||
//Make sure the destination RO directory exists.
|
||||
await fs.ensureDir(PathToRoFolder(ro_number));
|
||||
await fs.ensureDir(PathToRoFolder(jobid));
|
||||
|
||||
const movingQueue: Promise<void>[] = [];
|
||||
|
||||
@@ -32,14 +32,14 @@ export async function JobsMoveMedia(req: Request, res: Response) {
|
||||
movingQueue.push(
|
||||
fs.move(
|
||||
path.join(FolderPaths.Jobs, from_ro, file),
|
||||
path.join(FolderPaths.Jobs, ro_number, file)
|
||||
path.join(FolderPaths.Jobs, jobid, file)
|
||||
)
|
||||
);
|
||||
|
||||
movingQueue.push(
|
||||
fs.move(
|
||||
path.join(FolderPaths.Jobs, from_ro, FolderPaths.ThumbsSubDir, file),
|
||||
path.join(FolderPaths.Jobs, ro_number, FolderPaths.ThumbsSubDir, file)
|
||||
path.join(FolderPaths.Jobs, jobid, FolderPaths.ThumbsSubDir, file)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -11,8 +11,8 @@ import fs from "fs-extra";
|
||||
export const JobMediaUploadMulter = multer({
|
||||
storage: multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
const ro_number: string = (req.body.ro_number || "").trim();
|
||||
const DestinationFolder: string = PathToRoFolder(ro_number);
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
const DestinationFolder: string = PathToRoFolder(jobid);
|
||||
fs.ensureDirSync(DestinationFolder);
|
||||
cb(null, DestinationFolder);
|
||||
},
|
||||
@@ -24,7 +24,7 @@ export const JobMediaUploadMulter = multer({
|
||||
});
|
||||
|
||||
export async function jobsUploadMedia(req: Request, res: Response) {
|
||||
const ro_number: string = (req.body.ro_number || "").trim();
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
|
||||
try {
|
||||
if (!req.files) {
|
||||
@@ -39,8 +39,10 @@ export async function jobsUploadMedia(req: Request, res: Response) {
|
||||
(req.files as Express.Multer.File[]).forEach((file) => {
|
||||
thumbnailGenerationQueue.push(GenerateThumbnail(file.path));
|
||||
});
|
||||
await Promise.all(thumbnailGenerationQueue);
|
||||
|
||||
logger.debug("Pre await", thumbnailGenerationQueue.toString());
|
||||
await Promise.all(thumbnailGenerationQueue);
|
||||
logger.debug("Post Await", thumbnailGenerationQueue.toString());
|
||||
JobsListMedia(req, res);
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user