Update media file interface and how bills are returned.
This commit is contained in:
@@ -10,43 +10,80 @@ 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 jobid: string = (req.body.jobid || "").trim();
|
||||
const vendor: string = (req.body.vendor || "").trim();
|
||||
//const vendorid: string = (req.body.vendorid || "").trim();
|
||||
const invoice_number: string = (req.body.invoice_number || "").trim();
|
||||
|
||||
let ret: MediaFile[];
|
||||
//Ensure all directories exist.
|
||||
await fs.ensureDir(PathToRoBillsFolder(jobid));
|
||||
|
||||
const filesList: fs.Dirent[] = (
|
||||
await fs.readdir(PathToRoBillsFolder(jobid), {
|
||||
withFileTypes: true,
|
||||
})
|
||||
).filter((f) => f.isFile() && !/(^|\/)\.[^\/\.]/g.test(f.name));
|
||||
if (req.files) {
|
||||
ret = await Promise.all(
|
||||
(req.files as Express.Multer.File[]).map(async (file) => {
|
||||
const relativeThumbPath: string = await GenerateThumbnail(
|
||||
path.join(PathToRoBillsFolder(jobid), file.filename)
|
||||
);
|
||||
return {
|
||||
src: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
jobid,
|
||||
FolderPaths.BillsSubDir,
|
||||
file.filename,
|
||||
]),
|
||||
thumbnail: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
jobid,
|
||||
FolderPaths.BillsSubDir,
|
||||
relativeThumbPath,
|
||||
]),
|
||||
thumbnailHeight: 250,
|
||||
thumbnailWidth: 250,
|
||||
filename: file.filename,
|
||||
};
|
||||
})
|
||||
);
|
||||
} else {
|
||||
let filesList: fs.Dirent[] = (
|
||||
await fs.readdir(PathToRoBillsFolder(jobid), {
|
||||
withFileTypes: true,
|
||||
})
|
||||
).filter(
|
||||
(f) =>
|
||||
f.isFile() &&
|
||||
!/(^|\/)\.[^\/\.]/g.test(f.name) &&
|
||||
(invoice_number !== ""
|
||||
? f.name.toLowerCase().includes(invoice_number.toLowerCase())
|
||||
: true)
|
||||
);
|
||||
|
||||
const ret: MediaFile[] = await Promise.all(
|
||||
filesList.map(async (file) => {
|
||||
const relativeThumbPath: string = await GenerateThumbnail(
|
||||
path.join(PathToRoBillsFolder(jobid), file.name)
|
||||
);
|
||||
return {
|
||||
src: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
jobid,
|
||||
FolderPaths.BillsSubDir,
|
||||
file.name,
|
||||
]),
|
||||
thumbnail: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
jobid,
|
||||
FolderPaths.BillsSubDir,
|
||||
relativeThumbPath,
|
||||
]),
|
||||
thumbnailHeight: 250,
|
||||
thumbnailWidth: 250,
|
||||
};
|
||||
})
|
||||
);
|
||||
ret = await Promise.all(
|
||||
filesList.map(async (file) => {
|
||||
const relativeThumbPath: string = await GenerateThumbnail(
|
||||
path.join(PathToRoBillsFolder(jobid), file.name)
|
||||
);
|
||||
return {
|
||||
src: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
jobid,
|
||||
FolderPaths.BillsSubDir,
|
||||
file.name,
|
||||
]),
|
||||
thumbnail: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
jobid,
|
||||
FolderPaths.BillsSubDir,
|
||||
relativeThumbPath,
|
||||
]),
|
||||
thumbnailHeight: 250,
|
||||
thumbnailWidth: 250,
|
||||
filename: file.name,
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
res.json(ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user