Jobs Media List functional
This commit is contained in:
15
jobs/jobRequestValidator.ts
Normal file
15
jobs/jobRequestValidator.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
|
||||
export default function ValidateJobBasedRequest(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const ro_number: string = (req.body.ro_number || "").trim();
|
||||
if (ro_number === "") {
|
||||
res.status(400).json({ error: "No RO Number has been specified." });
|
||||
return;
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import fs from "fs-extra";
|
||||
//import { FolderPaths } from "../util/serverInit.js";
|
||||
import express, { Express, Request, Response } from "express";
|
||||
|
||||
export async function JobsListMedia(req: Request, res: Response) {
|
||||
//const { ro_number } = req.body;
|
||||
|
||||
res.send();
|
||||
}
|
||||
55
jobs/jobsListMedia.ts
Normal file
55
jobs/jobsListMedia.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { Request, Response } from "express";
|
||||
import fs from "fs-extra";
|
||||
import path from "path";
|
||||
import GenerateThumbnail from "../util/generateThumbnail";
|
||||
import GenerateUrl from "../util/MediaUrlGen";
|
||||
import { FolderPaths } from "../util/serverInit";
|
||||
|
||||
export async function JobsListMedia(req: Request, res: Response) {
|
||||
const ro_number: string = (req.body.ro_number || "").trim();
|
||||
|
||||
const filesList: fs.Dirent[] = (
|
||||
await fs.readdir(path.join(FolderPaths.Jobs, ro_number), {
|
||||
withFileTypes: true,
|
||||
})
|
||||
).filter((f) => f.isFile() && !/(^|\/)\.[^\/\.]/g.test(f.name));
|
||||
|
||||
const thumbnailGenerationQueue: Promise<void>[] = [];
|
||||
|
||||
const ret: MediaFile[] = filesList.map((file) => {
|
||||
thumbnailGenerationQueue.push(
|
||||
GenerateThumbnail(
|
||||
path.join(FolderPaths.Jobs, ro_number, file.name),
|
||||
path.join(
|
||||
FolderPaths.Jobs,
|
||||
ro_number,
|
||||
FolderPaths.ThumbsSubDir,
|
||||
file.name
|
||||
)
|
||||
)
|
||||
);
|
||||
return {
|
||||
src: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
ro_number,
|
||||
file.name,
|
||||
]),
|
||||
thumb: GenerateUrl([
|
||||
FolderPaths.StaticPath,
|
||||
FolderPaths.JobsFolder,
|
||||
ro_number,
|
||||
FolderPaths.ThumbsSubDir,
|
||||
file.name,
|
||||
]),
|
||||
};
|
||||
});
|
||||
await Promise.all(thumbnailGenerationQueue);
|
||||
|
||||
res.json(ret);
|
||||
}
|
||||
|
||||
interface MediaFile {
|
||||
src: string;
|
||||
thumb: string;
|
||||
}
|
||||
Reference in New Issue
Block a user