IO-2221 IO-2323 Correct Download/Delete/Move functions

This commit is contained in:
Allan Carr
2023-07-20 11:19:21 -07:00
parent a678383dee
commit aa3b567a5b
9 changed files with 415 additions and 334 deletions

View File

@@ -2,14 +2,10 @@ import { Request, Response } from "express";
import fs from "fs-extra";
import path from "path";
import { logger } from "../server";
import GenerateThumbnail from "../util/generateThumbnail";
import MediaFile from "../util/interfaces/MediaFile";
import ListableChecker from "../util/listableChecker";
import GenerateUrl from "../util/MediaUrlGen";
import { PathToRoFolder } from "../util/pathGenerators";
import { FolderPaths, JobRelativeFilePath } from "../util/serverInit";
import ft from "file-type";
import core from "file-type/core";
import { PathToRoBillsFolder, PathToRoFolder } from "../util/pathGenerators";
import { BillsRelativeFilePath, JobRelativeFilePath } from "../util/serverInit";
export async function JobsDeleteMedia(req: Request, res: Response) {
const jobid: string = (req.body.jobid || "").trim();
@@ -18,12 +14,33 @@ export async function JobsDeleteMedia(req: Request, res: Response) {
logger.debug("Deleteing media for job: " + PathToRoFolder(jobid));
let ret: MediaFile[];
try {
//We just uploaded files, we're going to send only those back.
await Promise.all(
files.map(async (filename) => {
const relativeFilePath: string = JobRelativeFilePath(jobid, filename);
// Setup lists for both file locations
const jobFileList: fs.Dirent[] = (
await fs.readdir(PathToRoFolder(jobid), {
withFileTypes: true,
})
).filter((f) => f.isFile() && ListableChecker(f));
const billFileList: fs.Dirent[] = (
await fs.readdir(PathToRoBillsFolder(jobid), {
withFileTypes: true,
})
).filter((f) => f.isFile() && ListableChecker(f));
await fs.remove(relativeFilePath);
// Check both list for the files that need to be deleted
await Promise.all(
jobFileList.map(async (file) => {
if (files.includes(path.parse(path.basename(file.name)).base)) {
// File is in the set of requested files.
await fs.remove(JobRelativeFilePath(jobid, file.name));
}
})
);
await Promise.all(
billFileList.map(async (file) => {
if (files.includes(path.parse(path.basename(file.name)).base)) {
// File is in the set of requested files.
await fs.remove(BillsRelativeFilePath(jobid, file.name));
}
})
);