Package Updates
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
|
||||
export default function ValidateJobBasedRequest(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
export default function ValidateJobBasedRequest(req: Request, res: Response, next: NextFunction) {
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
if (jobid === "") {
|
||||
res.status(400).json({ error: "No RO Number has been specified." });
|
||||
|
||||
@@ -5,11 +5,7 @@ import { logger } from "../server";
|
||||
import MediaFile from "../util/interfaces/MediaFile";
|
||||
import ListableChecker from "../util/listableChecker";
|
||||
import { PathToRoBillsFolder, PathToRoFolder } from "../util/pathGenerators";
|
||||
import {
|
||||
BillsRelativeFilePath,
|
||||
FolderPaths,
|
||||
JobRelativeFilePath,
|
||||
} from "../util/serverInit";
|
||||
import { BillsRelativeFilePath, FolderPaths, JobRelativeFilePath } from "../util/serverInit";
|
||||
|
||||
export async function JobsDeleteMedia(req: Request, res: Response) {
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
@@ -21,12 +17,12 @@ export async function JobsDeleteMedia(req: Request, res: Response) {
|
||||
// Setup lists for both file locations
|
||||
const jobFileList: fs.Dirent[] = (
|
||||
await fs.readdir(PathToRoFolder(jobid), {
|
||||
withFileTypes: true,
|
||||
withFileTypes: true
|
||||
})
|
||||
).filter((f) => f.isFile() && ListableChecker(f));
|
||||
const billFileList: fs.Dirent[] = (
|
||||
await fs.readdir(PathToRoBillsFolder(jobid), {
|
||||
withFileTypes: true,
|
||||
withFileTypes: true
|
||||
})
|
||||
).filter((f) => f.isFile() && ListableChecker(f));
|
||||
|
||||
@@ -37,12 +33,7 @@ export async function JobsDeleteMedia(req: Request, res: Response) {
|
||||
// File is in the set of requested files.
|
||||
await fs.remove(JobRelativeFilePath(jobid, file.name));
|
||||
await fs.remove(
|
||||
path.join(
|
||||
FolderPaths.Jobs,
|
||||
jobid,
|
||||
FolderPaths.ThumbsSubDir,
|
||||
file.name.replace(/\.[^/.]+$/, ".png")
|
||||
)
|
||||
path.join(FolderPaths.Jobs, jobid, FolderPaths.ThumbsSubDir, file.name.replace(/\.[^/.]+$/, ".png"))
|
||||
);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -22,12 +22,12 @@ export async function jobsDownloadMedia(req: Request, res: Response) {
|
||||
|
||||
const jobFileList: fs.Dirent[] = (
|
||||
await fs.readdir(PathToRoFolder(jobid), {
|
||||
withFileTypes: true,
|
||||
withFileTypes: true
|
||||
})
|
||||
).filter((f) => f.isFile() && ListableChecker(f));
|
||||
const billFileList: fs.Dirent[] = (
|
||||
await fs.readdir(PathToRoBillsFolder(jobid), {
|
||||
withFileTypes: true,
|
||||
withFileTypes: true
|
||||
})
|
||||
).filter((f) => f.isFile() && ListableChecker(f));
|
||||
|
||||
@@ -36,18 +36,14 @@ export async function jobsDownloadMedia(req: Request, res: Response) {
|
||||
await Promise.all(
|
||||
jobFileList.map(async (file) => {
|
||||
//Do something async
|
||||
const fileOnDisk: Buffer = await fs.readFile(
|
||||
JobRelativeFilePath(jobid, file.name)
|
||||
);
|
||||
const fileOnDisk: Buffer = await fs.readFile(JobRelativeFilePath(jobid, file.name));
|
||||
zip.file(path.parse(path.basename(file.name)).base, fileOnDisk);
|
||||
})
|
||||
);
|
||||
await Promise.all(
|
||||
billFileList.map(async (file) => {
|
||||
//Do something async
|
||||
const fileOnDisk: Buffer = await fs.readFile(
|
||||
BillsRelativeFilePath(jobid, file.name)
|
||||
);
|
||||
const fileOnDisk: Buffer = await fs.readFile(BillsRelativeFilePath(jobid, file.name));
|
||||
zip.file(path.parse(path.basename(file.name)).base, fileOnDisk);
|
||||
})
|
||||
);
|
||||
@@ -57,23 +53,19 @@ export async function jobsDownloadMedia(req: Request, res: Response) {
|
||||
jobFileList.map(async (file) => {
|
||||
if (files.includes(path.parse(path.basename(file.name)).base)) {
|
||||
// File is in the set of requested files.
|
||||
const fileOnDisk: Buffer = await fs.readFile(
|
||||
JobRelativeFilePath(jobid, file.name)
|
||||
);
|
||||
const fileOnDisk: Buffer = await fs.readFile(JobRelativeFilePath(jobid, file.name));
|
||||
zip.file(path.parse(path.basename(file.name)).base, fileOnDisk);
|
||||
}
|
||||
}),
|
||||
})
|
||||
);
|
||||
await Promise.all(
|
||||
billFileList.map(async (file) => {
|
||||
if (files.includes(path.parse(path.basename(file.name)).base)) {
|
||||
// File is in the set of requested files.
|
||||
const fileOnDisk: Buffer = await fs.readFile(
|
||||
BillsRelativeFilePath(jobid, file.name)
|
||||
);
|
||||
const fileOnDisk: Buffer = await fs.readFile(BillsRelativeFilePath(jobid, file.name));
|
||||
zip.file(path.parse(path.basename(file.name)).base, fileOnDisk);
|
||||
}
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
//Send it as a response to download it automatically.
|
||||
@@ -82,14 +74,14 @@ export async function jobsDownloadMedia(req: Request, res: Response) {
|
||||
zip
|
||||
.generateNodeStream({
|
||||
type: "nodebuffer",
|
||||
streamFiles: true,
|
||||
streamFiles: true
|
||||
//encodeFileName: (filename) => `${jobid}.zip`,
|
||||
})
|
||||
.pipe(res);
|
||||
} catch (error) {
|
||||
logger.error("Error downloading job media.", {
|
||||
jobid,
|
||||
error: (error as Error).message,
|
||||
error: (error as Error).message
|
||||
});
|
||||
res.status(500).json((error as Error).message);
|
||||
}
|
||||
|
||||
@@ -20,81 +20,47 @@ export async function JobsListMedia(req: Request, res: Response) {
|
||||
//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 relativeFilePath: string = JobRelativeFilePath(
|
||||
jobid,
|
||||
file.filename
|
||||
);
|
||||
const relativeFilePath: string = JobRelativeFilePath(jobid, file.filename);
|
||||
|
||||
const relativeThumbPath: string = await GenerateThumbnail(
|
||||
relativeFilePath
|
||||
);
|
||||
const relativeThumbPath: string = await GenerateThumbnail(relativeFilePath);
|
||||
|
||||
const type: core.FileTypeResult | undefined = await ft.fromFile(
|
||||
relativeFilePath
|
||||
);
|
||||
const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(relativeFilePath);
|
||||
|
||||
return {
|
||||
type,
|
||||
size: file.size,
|
||||
src: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
jobid,
|
||||
file.filename,
|
||||
]),
|
||||
thumbnail: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
jobid,
|
||||
relativeThumbPath,
|
||||
]),
|
||||
src: GenerateUrl([FolderPaths.StaticPath, FolderPaths.JobsFolder, jobid, file.filename]),
|
||||
thumbnail: GenerateUrl([FolderPaths.StaticPath, FolderPaths.JobsFolder, jobid, relativeThumbPath]),
|
||||
thumbnailHeight: 250,
|
||||
thumbnailWidth: 250,
|
||||
filename: file.filename,
|
||||
relativeFilePath,
|
||||
relativeFilePath
|
||||
};
|
||||
})
|
||||
);
|
||||
} else {
|
||||
const filesList: fs.Dirent[] = (
|
||||
await fs.readdir(PathToRoFolder(jobid), {
|
||||
withFileTypes: true,
|
||||
withFileTypes: true
|
||||
})
|
||||
).filter((f) => f.isFile() && ListableChecker(f));
|
||||
|
||||
ret = await Promise.all(
|
||||
filesList.map(async (file) => {
|
||||
const relativeFilePath: string = JobRelativeFilePath(
|
||||
jobid,
|
||||
file.name
|
||||
);
|
||||
const relativeFilePath: string = JobRelativeFilePath(jobid, file.name);
|
||||
|
||||
const relativeThumbPath: string = await GenerateThumbnail(
|
||||
relativeFilePath
|
||||
);
|
||||
const type: core.FileTypeResult | undefined = await ft.fromFile(
|
||||
relativeFilePath
|
||||
);
|
||||
const relativeThumbPath: string = await GenerateThumbnail(relativeFilePath);
|
||||
const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(relativeFilePath);
|
||||
const fileSize = await fs.stat(relativeFilePath);
|
||||
return {
|
||||
type,
|
||||
size: fileSize.size,
|
||||
src: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
jobid,
|
||||
file.name,
|
||||
]),
|
||||
thumbnail: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
jobid,
|
||||
relativeThumbPath,
|
||||
]),
|
||||
src: GenerateUrl([FolderPaths.StaticPath, FolderPaths.JobsFolder, jobid, file.name]),
|
||||
thumbnail: GenerateUrl([FolderPaths.StaticPath, FolderPaths.JobsFolder, jobid, relativeThumbPath]),
|
||||
thumbnailHeight: 250,
|
||||
thumbnailWidth: 250,
|
||||
filename: file.name,
|
||||
relativeFilePath,
|
||||
relativeFilePath
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
@@ -26,14 +26,14 @@ export async function JobsMoveMedia(req: Request, res: Response) {
|
||||
// Setup lists for both file locations
|
||||
const jobFileList: string[] = (
|
||||
await fs.readdir(PathToRoFolder(from_jobid), {
|
||||
withFileTypes: true,
|
||||
withFileTypes: true
|
||||
})
|
||||
)
|
||||
.filter((f) => f.isFile() && ListableChecker(f))
|
||||
.map((dirent) => dirent.name);
|
||||
const billFileList: string[] = (
|
||||
await fs.readdir(PathToRoBillsFolder(from_jobid), {
|
||||
withFileTypes: true,
|
||||
withFileTypes: true
|
||||
})
|
||||
)
|
||||
.filter((f) => f.isFile() && ListableChecker(f))
|
||||
@@ -47,38 +47,20 @@ export async function JobsMoveMedia(req: Request, res: Response) {
|
||||
files.forEach((file) => {
|
||||
if (jobFileList.includes(file)) {
|
||||
movingQueue.push(
|
||||
fs.move(
|
||||
path.join(FolderPaths.Jobs, from_jobid, file),
|
||||
path.join(FolderPaths.Jobs, jobid, file)
|
||||
)
|
||||
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.replace(/\.[^/.]+$/, ".png")
|
||||
),
|
||||
path.join(
|
||||
FolderPaths.Jobs,
|
||||
jobid,
|
||||
FolderPaths.ThumbsSubDir,
|
||||
file.replace(/\.[^/.]+$/, ".png")
|
||||
)
|
||||
path.join(FolderPaths.Jobs, from_jobid, FolderPaths.ThumbsSubDir, file.replace(/\.[^/.]+$/, ".png")),
|
||||
path.join(FolderPaths.Jobs, jobid, FolderPaths.ThumbsSubDir, file.replace(/\.[^/.]+$/, ".png"))
|
||||
)
|
||||
);
|
||||
}
|
||||
if (billFileList.includes(file)) {
|
||||
movingQueue.push(
|
||||
fs.move(
|
||||
path.join(
|
||||
FolderPaths.Jobs,
|
||||
from_jobid,
|
||||
FolderPaths.BillsSubDir,
|
||||
file
|
||||
),
|
||||
path.join(FolderPaths.Jobs, from_jobid, FolderPaths.BillsSubDir, file),
|
||||
path.join(FolderPaths.Jobs, jobid, FolderPaths.BillsSubDir, file)
|
||||
)
|
||||
);
|
||||
@@ -114,7 +96,7 @@ export async function JobsMoveMedia(req: Request, res: Response) {
|
||||
from_jobid,
|
||||
jobid,
|
||||
files,
|
||||
err,
|
||||
err
|
||||
});
|
||||
res.status(500).send(err);
|
||||
}
|
||||
|
||||
@@ -15,20 +15,15 @@ export const JobMediaUploadMulter = multer({
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
const DestinationFolder: string = PathToRoFolder(jobid);
|
||||
fs.ensureDirSync(DestinationFolder);
|
||||
cb(
|
||||
jobid === "" || jobid === null
|
||||
? new Error("Job ID not specified.")
|
||||
: null,
|
||||
DestinationFolder
|
||||
);
|
||||
cb(jobid === "" || jobid === null ? new Error("Job ID not specified.") : null, DestinationFolder);
|
||||
},
|
||||
filename: function (req, file, cb) {
|
||||
logger.debug("Uploading file: ", {
|
||||
file: path.basename(file.originalname),
|
||||
file: path.basename(file.originalname)
|
||||
});
|
||||
cb(null, generateUniqueFilename(file));
|
||||
},
|
||||
}),
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
export async function jobsUploadMedia(req: Request, res: Response) {
|
||||
@@ -39,7 +34,7 @@ export async function jobsUploadMedia(req: Request, res: Response) {
|
||||
logger.warning("Upload contained no files.");
|
||||
res.status(400).send({
|
||||
status: false,
|
||||
message: "No file uploaded",
|
||||
message: "No file uploaded"
|
||||
});
|
||||
} else {
|
||||
//If we want to skip waiting for everything, just send it back that we're good.
|
||||
@@ -69,7 +64,7 @@ export async function jobsUploadMedia(req: Request, res: Response) {
|
||||
} catch (error) {
|
||||
logger.error("Error uploading job media.", {
|
||||
jobid,
|
||||
error: (error as Error).message,
|
||||
error: (error as Error).message
|
||||
});
|
||||
res.status(500).json((error as Error).message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user