Added bills upload & list
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import GenerateUrl from "../util/MediaUrlGen";
|
||||
import { FolderPaths } from "../util/serverInit";
|
||||
import multer from "multer";
|
||||
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();
|
||||
@@ -23,7 +24,7 @@ export async function JobsMoveMedia(req: Request, res: Response) {
|
||||
return;
|
||||
}
|
||||
//Make sure the destination RO directory exists.
|
||||
await fs.ensureDir(path.join(FolderPaths.Jobs, ro_number));
|
||||
await fs.ensureDir(PathToRoFolder(ro_number));
|
||||
|
||||
const movingQueue: Promise<void>[] = [];
|
||||
|
||||
|
||||
@@ -3,24 +3,22 @@ import multer from "multer";
|
||||
import path from "path";
|
||||
import { logger } from "../server";
|
||||
import GenerateThumbnail from "../util/generateThumbnail";
|
||||
import { FolderPaths } from "../util/serverInit";
|
||||
import generateUniqueFilename from "../util/generateUniqueFilename";
|
||||
import { PathToRoFolder } from "../util/pathGenerators";
|
||||
import { JobsListMedia } from "./jobsListMedia";
|
||||
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 = path.join(FolderPaths.Jobs, ro_number);
|
||||
const DestinationFolder: string = PathToRoFolder(ro_number);
|
||||
fs.ensureDirSync(DestinationFolder);
|
||||
cb(null, DestinationFolder);
|
||||
},
|
||||
filename: function (req, file, cb) {
|
||||
logger.info("Uploading file: ", path.basename(file.originalname));
|
||||
cb(
|
||||
null,
|
||||
`${file.originalname}-${Math.floor(Date.now() / 1000)}.${path.extname(
|
||||
file.originalname
|
||||
)}`
|
||||
);
|
||||
cb(null, generateUniqueFilename(file));
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user