Change RO number to jobid.

This commit is contained in:
Patrick Fic
2022-05-04 18:13:21 -07:00
parent 05a8c90f03
commit 7754dc4653
10 changed files with 40 additions and 36 deletions

View File

@@ -7,7 +7,7 @@ export default function BillRequestValidator(
) { ) {
const vendor: string = (req.body.vendor || "").trim(); const vendor: string = (req.body.vendor || "").trim();
const invoice_number: string = (req.body.invoice_number || "").trim(); const invoice_number: string = (req.body.invoice_number || "").trim();
const ro_number: string = (req.body.ro_number || "").trim(); const jobid: string = (req.body.jobid || "").trim();
// if (vendor === "") { // if (vendor === "") {
// res.status(400).json({ error: "No vendor name has been specified." }); // res.status(400).json({ error: "No vendor name has been specified." });
@@ -17,7 +17,7 @@ export default function BillRequestValidator(
// res.status(400).json({ error: "No invoice number has been specified." }); // res.status(400).json({ error: "No invoice number has been specified." });
// return; // return;
// } // }
if (ro_number === "") { if (jobid === "") {
res.status(400).json({ error: "No RO Number has been specified." }); res.status(400).json({ error: "No RO Number has been specified." });
return; return;
} else { } else {

View File

@@ -9,15 +9,15 @@ import { FolderPaths } from "../util/serverInit";
/** @description Bills will use the hierarchy of PDFs stored under the Job first, and then the Bills folder. */ /** @description Bills will use the hierarchy of PDFs stored under the Job first, and then the Bills folder. */
export async function BillsListMedia(req: Request, res: Response) { export async function BillsListMedia(req: Request, res: Response) {
const ro_number: string = (req.body.ro_number || "").trim(); const jobid: string = (req.body.jobid || "").trim();
const vendor: string = (req.body.vendor || "").trim(); const vendor: string = (req.body.vendor || "").trim();
const invoice_number: string = (req.body.invoice_number || "").trim(); const invoice_number: string = (req.body.invoice_number || "").trim();
//Ensure all directories exist. //Ensure all directories exist.
await fs.ensureDir(PathToRoBillsFolder(ro_number)); await fs.ensureDir(PathToRoBillsFolder(jobid));
const filesList: fs.Dirent[] = ( const filesList: fs.Dirent[] = (
await fs.readdir(PathToRoBillsFolder(ro_number), { await fs.readdir(PathToRoBillsFolder(jobid), {
withFileTypes: true, withFileTypes: true,
}) })
).filter((f) => f.isFile() && !/(^|\/)\.[^\/\.]/g.test(f.name)); ).filter((f) => f.isFile() && !/(^|\/)\.[^\/\.]/g.test(f.name));
@@ -25,20 +25,20 @@ export async function BillsListMedia(req: Request, res: Response) {
const ret: MediaFile[] = await Promise.all( const ret: MediaFile[] = await Promise.all(
filesList.map(async (file) => { filesList.map(async (file) => {
const relativeThumbPath: string = await GenerateThumbnail( const relativeThumbPath: string = await GenerateThumbnail(
path.join(PathToRoBillsFolder(ro_number), file.name) path.join(PathToRoBillsFolder(jobid), file.name)
); );
return { return {
src: GenerateUrl([ src: GenerateUrl([
FolderPaths.StaticPath, FolderPaths.StaticPath,
FolderPaths.JobsFolder, FolderPaths.JobsFolder,
ro_number, jobid,
FolderPaths.BillsSubDir, FolderPaths.BillsSubDir,
file.name, file.name,
]), ]),
thumbnail: GenerateUrl([ thumbnail: GenerateUrl([
FolderPaths.StaticPath, FolderPaths.StaticPath,
FolderPaths.JobsFolder, FolderPaths.JobsFolder,
ro_number, jobid,
FolderPaths.BillsSubDir, FolderPaths.BillsSubDir,
relativeThumbPath, relativeThumbPath,
]), ]),

View File

@@ -21,8 +21,8 @@ dotenv.config({
export const BillsMediaUploadMulter = multer({ export const BillsMediaUploadMulter = multer({
storage: multer.diskStorage({ storage: multer.diskStorage({
destination: function (req, file, cb) { destination: function (req, file, cb) {
const ro_number: string = (req.body.ro_number || "").trim(); const jobid: string = (req.body.jobid || "").trim();
const DestinationFolder: string = PathToRoBillsFolder(ro_number); const DestinationFolder: string = PathToRoBillsFolder(jobid);
fs.ensureDirSync(DestinationFolder); fs.ensureDirSync(DestinationFolder);
cb(null, DestinationFolder); cb(null, DestinationFolder);
}, },

View File

@@ -5,8 +5,8 @@ export default function ValidateJobBasedRequest(
res: Response, res: Response,
next: NextFunction next: NextFunction
) { ) {
const ro_number: string = (req.body.ro_number || "").trim(); const jobid: string = (req.body.jobid || "").trim();
if (ro_number === "") { if (jobid === "") {
res.status(400).json({ error: "No RO Number has been specified." }); res.status(400).json({ error: "No RO Number has been specified." });
return; return;
} else { } else {

View File

@@ -8,27 +8,27 @@ import { PathToRoFolder } from "../util/pathGenerators";
import { FolderPaths } from "../util/serverInit"; import { FolderPaths } from "../util/serverInit";
export async function JobsListMedia(req: Request, res: Response) { export async function JobsListMedia(req: Request, res: Response) {
const ro_number: string = (req.body.ro_number || "").trim(); const jobid: string = (req.body.jobid || "").trim();
await fs.ensureDir(PathToRoFolder(ro_number)); await fs.ensureDir(PathToRoFolder(jobid));
let ret: MediaFile[]; let ret: MediaFile[];
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(
(req.files as Express.Multer.File[]).map(async (file) => { (req.files as Express.Multer.File[]).map(async (file) => {
const relativeThumbPath: string = await GenerateThumbnail( const relativeThumbPath: string = await GenerateThumbnail(
path.join(FolderPaths.Jobs, ro_number, file.filename) path.join(FolderPaths.Jobs, jobid, file.filename)
); );
return { return {
src: GenerateUrl([ src: GenerateUrl([
FolderPaths.StaticPath, FolderPaths.StaticPath,
FolderPaths.JobsFolder, FolderPaths.JobsFolder,
ro_number, jobid,
file.filename, file.filename,
]), ]),
thumbnail: GenerateUrl([ thumbnail: GenerateUrl([
FolderPaths.StaticPath, FolderPaths.StaticPath,
FolderPaths.JobsFolder, FolderPaths.JobsFolder,
ro_number, jobid,
relativeThumbPath, relativeThumbPath,
]), ]),
thumbnailHeight: 250, thumbnailHeight: 250,
@@ -38,7 +38,7 @@ export async function JobsListMedia(req: Request, res: Response) {
); );
} else { } else {
const filesList: fs.Dirent[] = ( const filesList: fs.Dirent[] = (
await fs.readdir(PathToRoFolder(ro_number), { await fs.readdir(PathToRoFolder(jobid), {
withFileTypes: true, withFileTypes: true,
}) })
).filter((f) => f.isFile() && !/(^|\/)\.[^\/\.]/g.test(f.name)); ).filter((f) => f.isFile() && !/(^|\/)\.[^\/\.]/g.test(f.name));
@@ -46,19 +46,19 @@ export async function JobsListMedia(req: Request, res: Response) {
ret = await Promise.all( ret = await Promise.all(
filesList.map(async (file) => { filesList.map(async (file) => {
const relativeThumbPath: string = await GenerateThumbnail( const relativeThumbPath: string = await GenerateThumbnail(
path.join(FolderPaths.Jobs, ro_number, file.name) path.join(FolderPaths.Jobs, jobid, file.name)
); );
return { return {
src: GenerateUrl([ src: GenerateUrl([
FolderPaths.StaticPath, FolderPaths.StaticPath,
FolderPaths.JobsFolder, FolderPaths.JobsFolder,
ro_number, jobid,
file.name, file.name,
]), ]),
thumbnail: GenerateUrl([ thumbnail: GenerateUrl([
FolderPaths.StaticPath, FolderPaths.StaticPath,
FolderPaths.JobsFolder, FolderPaths.JobsFolder,
ro_number, jobid,
relativeThumbPath, relativeThumbPath,
]), ]),
thumbnailHeight: 250, thumbnailHeight: 250,

View File

@@ -9,7 +9,7 @@ import { JobsListMedia } from "./jobsListMedia";
import { PathToRoFolder } from "../util/pathGenerators"; import { PathToRoFolder } from "../util/pathGenerators";
export async function JobsMoveMedia(req: Request, res: Response) { 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 from_ro: string = (req.body.from_ro || "").trim();
const files: string[] = req.body.files; //Just file names. const files: string[] = req.body.files; //Just file names.
@@ -24,7 +24,7 @@ export async function JobsMoveMedia(req: Request, res: Response) {
return; return;
} }
//Make sure the destination RO directory exists. //Make sure the destination RO directory exists.
await fs.ensureDir(PathToRoFolder(ro_number)); await fs.ensureDir(PathToRoFolder(jobid));
const movingQueue: Promise<void>[] = []; const movingQueue: Promise<void>[] = [];
@@ -32,14 +32,14 @@ export async function JobsMoveMedia(req: Request, res: Response) {
movingQueue.push( movingQueue.push(
fs.move( fs.move(
path.join(FolderPaths.Jobs, from_ro, file), path.join(FolderPaths.Jobs, from_ro, file),
path.join(FolderPaths.Jobs, ro_number, file) path.join(FolderPaths.Jobs, jobid, file)
) )
); );
movingQueue.push( movingQueue.push(
fs.move( fs.move(
path.join(FolderPaths.Jobs, from_ro, FolderPaths.ThumbsSubDir, file), 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)
) )
); );
}); });

View File

@@ -11,8 +11,8 @@ import fs from "fs-extra";
export const JobMediaUploadMulter = multer({ export const JobMediaUploadMulter = multer({
storage: multer.diskStorage({ storage: multer.diskStorage({
destination: function (req, file, cb) { destination: function (req, file, cb) {
const ro_number: string = (req.body.ro_number || "").trim(); const jobid: string = (req.body.jobid || "").trim();
const DestinationFolder: string = PathToRoFolder(ro_number); const DestinationFolder: string = PathToRoFolder(jobid);
fs.ensureDirSync(DestinationFolder); fs.ensureDirSync(DestinationFolder);
cb(null, DestinationFolder); cb(null, DestinationFolder);
}, },
@@ -24,7 +24,7 @@ export const JobMediaUploadMulter = multer({
}); });
export async function jobsUploadMedia(req: Request, res: Response) { 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 { try {
if (!req.files) { if (!req.files) {
@@ -39,8 +39,10 @@ export async function jobsUploadMedia(req: Request, res: Response) {
(req.files as Express.Multer.File[]).forEach((file) => { (req.files as Express.Multer.File[]).forEach((file) => {
thumbnailGenerationQueue.push(GenerateThumbnail(file.path)); 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); JobsListMedia(req, res);
} }
} catch (err) { } catch (err) {

View File

@@ -87,7 +87,7 @@ const app: Express = express();
const port = process.env.PORT; const port = process.env.PORT;
app.use(bodyParser.json({ limit: "50mb" })); app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true })); app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
app.use(FolderPaths.StaticPath, express.static(FolderPaths.Root));
app.use(cors()); app.use(cors());
const morganMiddleware = morgan( const morganMiddleware = morgan(
"combined", //":method :url :status :res[content-length] - :response-time ms" "combined", //":method :url :status :res[content-length] - :response-time ms"
@@ -121,7 +121,7 @@ app.post(
); );
InitServer(); InitServer();
app.use(FolderPaths.StaticPath, express.static(FolderPaths.Root, {}));
app.listen(port, () => { app.listen(port, () => {
logger.info(`ImEX Media Server is running at http://localhost:${port}`); logger.info(`ImEX Media Server is running at http://localhost:${port}`);
}); });

View File

@@ -7,6 +7,7 @@ import ft from "file-type";
import core from "file-type/core"; import core from "file-type/core";
import GenerateUrl from "./MediaUrlGen"; import GenerateUrl from "./MediaUrlGen";
import { FolderPaths } from "./serverInit"; import { FolderPaths } from "./serverInit";
import { logger } from "../server";
var Bluebird = require("bluebird"); var Bluebird = require("bluebird");
Bluebird.promisifyAll(gm.prototype); Bluebird.promisifyAll(gm.prototype);
@@ -23,13 +24,13 @@ export default async function GenerateThumbnail(
FolderPaths.ThumbsSubDir, FolderPaths.ThumbsSubDir,
path.parse(path.basename(file)).name + thumbnailExtension path.parse(path.basename(file)).name + thumbnailExtension
); );
try { try {
//Ensure the thumbs directory exists. //Ensure the thumbs directory exists.
await fs.ensureDir(path.dirname(thumbPath)); await fs.ensureDir(path.dirname(thumbPath));
try { try {
await access(thumbPath); await access(thumbPath);
logger.debug("Thumbnail already exists for : " + thumbPath);
return path.relative(path.dirname(file), thumbPath); return path.relative(path.dirname(file), thumbPath);
} catch {} } catch {}
@@ -39,6 +40,7 @@ export default async function GenerateThumbnail(
const fileOnDisk: Buffer = await fs.readFile(file); const fileOnDisk: Buffer = await fs.readFile(file);
await GeneratePdfThumbnail(file, thumbPath); await GeneratePdfThumbnail(file, thumbPath);
} else { } else {
logger.debug("Thumbnail being created for : " + thumbPath);
const thumbnail = await imageThumbnail(file, { const thumbnail = await imageThumbnail(file, {
responseType: "buffer", responseType: "buffer",
height: 250, height: 250,

View File

@@ -1,12 +1,12 @@
import path from "path"; import path from "path";
import { FolderPaths } from "./serverInit"; import { FolderPaths } from "./serverInit";
export function PathToRoFolder(ro_number: string) { export function PathToRoFolder(jobid: string) {
return path.join(FolderPaths.Jobs, ro_number); return path.join(FolderPaths.Jobs, jobid);
} }
export function PathToRoBillsFolder(ro_number: string) { export function PathToRoBillsFolder(jobid: string) {
return path.join(FolderPaths.Jobs, ro_number, FolderPaths.BillsSubDir); return path.join(FolderPaths.Jobs, jobid, FolderPaths.BillsSubDir);
} }
export function PathToVendorBillsFile(vendor: string) { export function PathToVendorBillsFile(vendor: string) {
return path.join(FolderPaths.Vendors, vendor); return path.join(FolderPaths.Vendors, vendor);