Change RO number to jobid.
This commit is contained in:
@@ -7,7 +7,7 @@ export default function BillRequestValidator(
|
||||
) {
|
||||
const vendor: string = (req.body.vendor || "").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 === "") {
|
||||
// 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." });
|
||||
// return;
|
||||
// }
|
||||
if (ro_number === "") {
|
||||
if (jobid === "") {
|
||||
res.status(400).json({ error: "No RO Number has been specified." });
|
||||
return;
|
||||
} else {
|
||||
|
||||
@@ -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. */
|
||||
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 invoice_number: string = (req.body.invoice_number || "").trim();
|
||||
|
||||
//Ensure all directories exist.
|
||||
await fs.ensureDir(PathToRoBillsFolder(ro_number));
|
||||
await fs.ensureDir(PathToRoBillsFolder(jobid));
|
||||
|
||||
const filesList: fs.Dirent[] = (
|
||||
await fs.readdir(PathToRoBillsFolder(ro_number), {
|
||||
await fs.readdir(PathToRoBillsFolder(jobid), {
|
||||
withFileTypes: true,
|
||||
})
|
||||
).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(
|
||||
filesList.map(async (file) => {
|
||||
const relativeThumbPath: string = await GenerateThumbnail(
|
||||
path.join(PathToRoBillsFolder(ro_number), file.name)
|
||||
path.join(PathToRoBillsFolder(jobid), file.name)
|
||||
);
|
||||
return {
|
||||
src: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
ro_number,
|
||||
jobid,
|
||||
FolderPaths.BillsSubDir,
|
||||
file.name,
|
||||
]),
|
||||
thumbnail: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
ro_number,
|
||||
jobid,
|
||||
FolderPaths.BillsSubDir,
|
||||
relativeThumbPath,
|
||||
]),
|
||||
|
||||
@@ -21,8 +21,8 @@ dotenv.config({
|
||||
export const BillsMediaUploadMulter = multer({
|
||||
storage: multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
const ro_number: string = (req.body.ro_number || "").trim();
|
||||
const DestinationFolder: string = PathToRoBillsFolder(ro_number);
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
const DestinationFolder: string = PathToRoBillsFolder(jobid);
|
||||
fs.ensureDirSync(DestinationFolder);
|
||||
cb(null, DestinationFolder);
|
||||
},
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -87,7 +87,7 @@ const app: Express = express();
|
||||
const port = process.env.PORT;
|
||||
app.use(bodyParser.json({ limit: "50mb" }));
|
||||
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
|
||||
app.use(FolderPaths.StaticPath, express.static(FolderPaths.Root));
|
||||
|
||||
app.use(cors());
|
||||
const morganMiddleware = morgan(
|
||||
"combined", //":method :url :status :res[content-length] - :response-time ms"
|
||||
@@ -121,7 +121,7 @@ app.post(
|
||||
);
|
||||
|
||||
InitServer();
|
||||
|
||||
app.use(FolderPaths.StaticPath, express.static(FolderPaths.Root, {}));
|
||||
app.listen(port, () => {
|
||||
logger.info(`ImEX Media Server is running at http://localhost:${port}`);
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import ft from "file-type";
|
||||
import core from "file-type/core";
|
||||
import GenerateUrl from "./MediaUrlGen";
|
||||
import { FolderPaths } from "./serverInit";
|
||||
import { logger } from "../server";
|
||||
var Bluebird = require("bluebird");
|
||||
|
||||
Bluebird.promisifyAll(gm.prototype);
|
||||
@@ -23,13 +24,13 @@ export default async function GenerateThumbnail(
|
||||
FolderPaths.ThumbsSubDir,
|
||||
path.parse(path.basename(file)).name + thumbnailExtension
|
||||
);
|
||||
|
||||
try {
|
||||
//Ensure the thumbs directory exists.
|
||||
await fs.ensureDir(path.dirname(thumbPath));
|
||||
|
||||
try {
|
||||
await access(thumbPath);
|
||||
logger.debug("Thumbnail already exists for : " + thumbPath);
|
||||
return path.relative(path.dirname(file), thumbPath);
|
||||
} catch {}
|
||||
|
||||
@@ -39,6 +40,7 @@ export default async function GenerateThumbnail(
|
||||
const fileOnDisk: Buffer = await fs.readFile(file);
|
||||
await GeneratePdfThumbnail(file, thumbPath);
|
||||
} else {
|
||||
logger.debug("Thumbnail being created for : " + thumbPath);
|
||||
const thumbnail = await imageThumbnail(file, {
|
||||
responseType: "buffer",
|
||||
height: 250,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import path from "path";
|
||||
import { FolderPaths } from "./serverInit";
|
||||
|
||||
export function PathToRoFolder(ro_number: string) {
|
||||
return path.join(FolderPaths.Jobs, ro_number);
|
||||
export function PathToRoFolder(jobid: string) {
|
||||
return path.join(FolderPaths.Jobs, jobid);
|
||||
}
|
||||
|
||||
export function PathToRoBillsFolder(ro_number: string) {
|
||||
return path.join(FolderPaths.Jobs, ro_number, FolderPaths.BillsSubDir);
|
||||
export function PathToRoBillsFolder(jobid: string) {
|
||||
return path.join(FolderPaths.Jobs, jobid, FolderPaths.BillsSubDir);
|
||||
}
|
||||
export function PathToVendorBillsFile(vendor: string) {
|
||||
return path.join(FolderPaths.Vendors, vendor);
|
||||
|
||||
Reference in New Issue
Block a user