Added bills upload & list

This commit is contained in:
Patrick Fic
2022-05-03 17:30:24 -07:00
parent 8d851c52b2
commit b7be304520
14 changed files with 226 additions and 6081 deletions

View File

@@ -2,21 +2,23 @@ import { Request, Response } from "express";
import fs from "fs-extra";
import path from "path";
import GenerateThumbnail from "../util/generateThumbnail";
import MediaFile from "../util/interfaces/MediaFile";
import GenerateUrl from "../util/MediaUrlGen";
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(path.join(FolderPaths.Jobs, ro_number));
await fs.ensureDir(PathToRoFolder(ro_number));
const filesList: fs.Dirent[] = (
await fs.readdir(path.join(FolderPaths.Jobs, ro_number), {
await fs.readdir(PathToRoFolder(ro_number), {
withFileTypes: true,
})
).filter((f) => f.isFile() && !/(^|\/)\.[^\/\.]/g.test(f.name));
const ret: MediaFile[] = await Promise.all(
filesList.map(async (file) => {
const thumbPath: string = await GenerateThumbnail(
const relativeThumbPath: string = await GenerateThumbnail(
path.join(FolderPaths.Jobs, ro_number, file.name)
);
return {
@@ -30,7 +32,7 @@ export async function JobsListMedia(req: Request, res: Response) {
FolderPaths.StaticPath,
FolderPaths.JobsFolder,
ro_number,
thumbPath,
relativeThumbPath,
]),
};
})
@@ -38,8 +40,3 @@ export async function JobsListMedia(req: Request, res: Response) {
res.json(ret);
}
interface MediaFile {
src: string;
thumb: string;
}