43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
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(PathToRoFolder(ro_number));
|
|
const filesList: fs.Dirent[] = (
|
|
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 relativeThumbPath: string = await GenerateThumbnail(
|
|
path.join(FolderPaths.Jobs, ro_number, file.name)
|
|
);
|
|
return {
|
|
src: GenerateUrl([
|
|
FolderPaths.StaticPath,
|
|
FolderPaths.JobsFolder,
|
|
ro_number,
|
|
file.name,
|
|
]),
|
|
thumb: GenerateUrl([
|
|
FolderPaths.StaticPath,
|
|
FolderPaths.JobsFolder,
|
|
ro_number,
|
|
relativeThumbPath,
|
|
]),
|
|
};
|
|
})
|
|
);
|
|
|
|
res.json(ret);
|
|
}
|