Package Updates
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import fs from "fs-extra";
|
||||
import { access } from "fs/promises";
|
||||
import imageThumbnail from "image-thumbnail";
|
||||
import path from "path";
|
||||
import gm from "gm";
|
||||
import ft from "file-type";
|
||||
import core from "file-type/core";
|
||||
import fs from "fs-extra";
|
||||
import { access } from "fs/promises";
|
||||
import gm from "gm";
|
||||
import imageThumbnail from "image-thumbnail";
|
||||
import path from "path";
|
||||
import { logger } from "../server";
|
||||
import GenerateUrl from "./MediaUrlGen";
|
||||
import { AssetPaths, FolderPaths } from "./serverInit";
|
||||
import { logger } from "../server";
|
||||
const simpleThumb = require("simple-thumbnail");
|
||||
//const ffmpeg = require("ffmpeg-static");
|
||||
|
||||
@@ -20,7 +20,7 @@ export default async function GenerateThumbnail(
|
||||
file: string
|
||||
//thumbPath: string
|
||||
) {
|
||||
const type: core.FileTypeResult | undefined = await ft.fromFile(file);
|
||||
const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(file);
|
||||
let thumbnailExtension: string = GetThumbnailExtension(type);
|
||||
let thumbPath: string = path.join(
|
||||
path.dirname(file),
|
||||
@@ -54,7 +54,7 @@ export default async function GenerateThumbnail(
|
||||
responseType: "buffer",
|
||||
height: 250,
|
||||
width: 250,
|
||||
failOnError: false,
|
||||
failOnError: false
|
||||
});
|
||||
console.log("Image success.");
|
||||
await fs.writeFile(thumbPath, thumbnail);
|
||||
@@ -64,7 +64,7 @@ export default async function GenerateThumbnail(
|
||||
logger.error("Error when genenerating thumbnail:", {
|
||||
thumbPath,
|
||||
err,
|
||||
message: (err as Error).message,
|
||||
message: (err as Error).message
|
||||
});
|
||||
return path.relative(path.dirname(file), AssetPaths.File);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import path from "path";
|
||||
|
||||
export default function (file: Express.Multer.File) {
|
||||
return `${path.parse(path.basename(file.originalname)).name}-${Math.floor(
|
||||
Date.now() / 1000
|
||||
)}${path.extname(file.originalname)}`;
|
||||
return `${path.parse(sanitizeFileName(path.basename(file.originalname))).name}-${Math.floor(Date.now() / 1000)}${path.extname(file.originalname)}`;
|
||||
}
|
||||
|
||||
export function generateUniqueBillFilename(
|
||||
file: Express.Multer.File,
|
||||
invoice_number: string
|
||||
) {
|
||||
return `${invoice_number}-${Math.floor(Date.now() / 1000)}${path.extname(
|
||||
file.originalname
|
||||
)}`;
|
||||
export function generateUniqueBillFilename(file: Express.Multer.File, invoice_number: string) {
|
||||
return `${sanitizeFileName(invoice_number)}-${Math.floor(Date.now() / 1000)}${path.extname(file.originalname)}`;
|
||||
}
|
||||
|
||||
function sanitizeFileName(fileName: string): string {
|
||||
const restrictedChars = /[<>:"/\\|?*\x00-\x1F]/g;
|
||||
return fileName.replace(restrictedChars, "");
|
||||
}
|
||||
|
||||
@@ -13,36 +13,25 @@ var imageMagick = gm.subClass({ imageMagick: true });
|
||||
|
||||
//gm.subClass();
|
||||
dotenv.config({
|
||||
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`),
|
||||
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
export async function ConvertHeicFiles(files: Express.Multer.File[]) {
|
||||
for (const file of files) {
|
||||
const type: core.FileTypeResult | undefined = await ft.fromFile(file.path);
|
||||
const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(file.path);
|
||||
if (type?.mime === "image/heic") {
|
||||
logger.log(
|
||||
"debug",
|
||||
`Converting ${file.filename} image to JPEG from HEIC.`
|
||||
);
|
||||
logger.log("debug", `Converting ${file.filename} image to JPEG from HEIC.`);
|
||||
const convertedFileName = `${
|
||||
path.parse(path.basename(file.originalname)).name
|
||||
}-${Math.floor(Date.now() / 1000)}.jpeg`;
|
||||
try {
|
||||
await ConvertToJpeg(
|
||||
file.path,
|
||||
`${file.destination}/${convertedFileName}`
|
||||
);
|
||||
await ConvertToJpeg(file.path, `${file.destination}/${convertedFileName}`);
|
||||
//Move the HEIC.
|
||||
if (process.env.KEEP_CONVERTED_ORIGINALS) {
|
||||
await fs.ensureDir(
|
||||
path.join(file.destination, FolderPaths.ConvertedOriginalSubDir)
|
||||
);
|
||||
await fs.ensureDir(path.join(file.destination, FolderPaths.ConvertedOriginalSubDir));
|
||||
await fs.move(
|
||||
file.path,
|
||||
`${path.join(
|
||||
file.destination,
|
||||
FolderPaths.ConvertedOriginalSubDir
|
||||
)}/${file.filename}`
|
||||
`${path.join(file.destination, FolderPaths.ConvertedOriginalSubDir)}/${file.filename}`
|
||||
);
|
||||
} else {
|
||||
await fs.unlink(file.destination);
|
||||
@@ -53,12 +42,7 @@ export async function ConvertHeicFiles(files: Express.Multer.File[]) {
|
||||
file.mimetype = "image/jpeg";
|
||||
file.path = `${file.destination}/${convertedFileName}`;
|
||||
} catch (error) {
|
||||
logger.log(
|
||||
"error",
|
||||
`Error converting ${
|
||||
file.filename
|
||||
} image to JPEG from HEIC. ${JSON.stringify(error)}`
|
||||
);
|
||||
logger.log("error", `Error converting ${file.filename} image to JPEG from HEIC. ${JSON.stringify(error)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import path, { resolve } from "path";
|
||||
import { logger } from "../server";
|
||||
|
||||
dotenv.config({
|
||||
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`),
|
||||
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
const RootDirectory = process.env.MEDIA_PATH!.replace("~", os.homedir);
|
||||
@@ -21,11 +21,11 @@ export const FolderPaths = {
|
||||
ConvertedOriginalSubDir: "/ConvertedOriginal",
|
||||
StaticPath: "/static",
|
||||
JobsFolder,
|
||||
VendorsFolder,
|
||||
VendorsFolder
|
||||
};
|
||||
|
||||
export const AssetPaths = {
|
||||
File: "/assets/file.png",
|
||||
File: "/assets/file.png"
|
||||
};
|
||||
|
||||
export function JobRelativeFilePath(jobid: string, filename: string) {
|
||||
|
||||
@@ -4,14 +4,10 @@ import { resolve } from "path";
|
||||
import { logger } from "../server";
|
||||
|
||||
dotenv.config({
|
||||
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`),
|
||||
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
export default function ValidateImsToken(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
export default function ValidateImsToken(req: Request, res: Response, next: NextFunction) {
|
||||
const jobid: string = (req.body.jobid || "").trim();
|
||||
|
||||
const IMS_TOKEN: string = (process.env.IMS_TOKEN || "").trim();
|
||||
|
||||
Reference in New Issue
Block a user