IO-2008 Include mime type for listed media.

This commit is contained in:
Patrick Fic
2022-08-03 13:27:17 -07:00
parent 3d0791f633
commit 92e7e3ebda
4 changed files with 41 additions and 6 deletions

View File

@@ -1,12 +1,14 @@
import { Request, Response } from "express";
import fs from "fs-extra";
import path from "path";
import path, { relative } from "path";
import GenerateThumbnail from "../util/generateThumbnail";
import MediaFile from "../util/interfaces/MediaFile";
import ListableChecker from "../util/listableChecker";
import GenerateUrl from "../util/MediaUrlGen";
import { PathToRoBillsFolder, PathToRoFolder } from "../util/pathGenerators";
import { FolderPaths } from "../util/serverInit";
import core from "file-type/core";
import ft from "file-type";
/** @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) {
@@ -20,10 +22,19 @@ export async function BillsListMedia(req: Request, res: Response) {
if (req.files) {
ret = await Promise.all(
(req.files as Express.Multer.File[]).map(async (file) => {
const relativeFilePath: string = path.join(
PathToRoBillsFolder(jobid),
file.filename
);
const relativeThumbPath: string = await GenerateThumbnail(
path.join(PathToRoBillsFolder(jobid), file.filename)
relativeFilePath
);
const type: core.FileTypeResult | undefined = await ft.fromFile(
relativeFilePath
);
return {
type,
src: GenerateUrl([
FolderPaths.StaticPath,
FolderPaths.JobsFolder,
@@ -61,10 +72,20 @@ export async function BillsListMedia(req: Request, res: Response) {
ret = await Promise.all(
filesList.map(async (file) => {
const relativeThumbPath: string = await GenerateThumbnail(
path.join(PathToRoBillsFolder(jobid), file.name)
const relativeFilePath: string = path.join(
PathToRoBillsFolder(jobid),
file.name
);
const relativeThumbPath: string = await GenerateThumbnail(
relativeFilePath
);
const type: core.FileTypeResult | undefined = await ft.fromFile(
relativeFilePath
);
return {
type,
src: GenerateUrl([
FolderPaths.StaticPath,
FolderPaths.JobsFolder,