From e793402a79107660dacdccf745a32dd5d2f7d357 Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Wed, 24 Jul 2024 08:54:29 -0700 Subject: [PATCH] Start of ESM update --- bills/billRequestValidator.ts | 13 +---- bills/billsListMedia.ts | 10 ++-- bills/billsUploadMedia.ts | 2 +- jobs/jobRequestValidator.ts | 14 ++--- jobs/jobsListMedia.ts | 8 +-- package-lock.json | 45 ++++++++++----- package.json | 3 +- server.ts | 32 +++++------ tsconfig.json | 100 ++++------------------------------ util/generateThumbnail.ts | 10 ++-- util/heicConverter.ts | 6 +- util/serverInit.ts | 8 +-- util/validateToken.ts | 4 +- yarn.lock | 23 +++++--- 14 files changed, 107 insertions(+), 171 deletions(-) diff --git a/bills/billRequestValidator.ts b/bills/billRequestValidator.ts index 9f42bb1..e5d1f2b 100644 --- a/bills/billRequestValidator.ts +++ b/bills/billRequestValidator.ts @@ -1,18 +1,7 @@ -import { Request, Response, NextFunction } from "express"; +import { NextFunction, Request, Response } from "express"; export default function BillRequestValidator(req: Request, res: Response, next: NextFunction) { - const vendorid: string = (req.body.vendorid || "").trim(); - const invoice_number: string = (req.body.invoice_number || "").trim(); const jobid: string = (req.body.jobid || "").trim(); - - // if (vendor === "") { - // res.status(400).json({ error: "No vendor name has been specified." }); - // return; - // } - // if (invoice_number === "") { - // res.status(400).json({ error: "No invoice number has been specified." }); - // return; - // } if (jobid === "") { res.status(400).json({ error: "No RO Number has been specified." }); return; diff --git a/bills/billsListMedia.ts b/bills/billsListMedia.ts index 30006aa..bc4cbe7 100644 --- a/bills/billsListMedia.ts +++ b/bills/billsListMedia.ts @@ -1,8 +1,8 @@ import { Request, Response } from "express"; -import ft from "file-type"; -import core from "file-type/core"; +import { fileTypeFromFile } from "file-type"; +import { FileTypeResult } from "file-type/core"; import fs from "fs-extra"; -import path, { relative } from "path"; +import path from "path"; import GenerateUrl from "../util/MediaUrlGen"; import GenerateThumbnail from "../util/generateThumbnail"; import MediaFile from "../util/interfaces/MediaFile"; @@ -25,7 +25,7 @@ export async function BillsListMedia(req: Request, res: Response) { const relativeFilePath: string = path.join(PathToRoBillsFolder(jobid), file.filename); const relativeThumbPath: string = await GenerateThumbnail(relativeFilePath); - const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(relativeFilePath); + const type: FileTypeResult | undefined = await fileTypeFromFile(relativeFilePath); return { type, size: file.size, @@ -68,7 +68,7 @@ export async function BillsListMedia(req: Request, res: Response) { const relativeFilePath: string = path.join(PathToRoBillsFolder(jobid), file.name); const relativeThumbPath: string = await GenerateThumbnail(relativeFilePath); - const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(relativeFilePath); + const type: FileTypeResult | undefined = await fileTypeFromFile(relativeFilePath); const fileSize = await fs.stat(relativeFilePath); return { type, diff --git a/bills/billsUploadMedia.ts b/bills/billsUploadMedia.ts index 5f01c2f..5a86d63 100644 --- a/bills/billsUploadMedia.ts +++ b/bills/billsUploadMedia.ts @@ -5,7 +5,7 @@ import multer from "multer"; import path, { resolve } from "path"; import { logger } from "../server"; import GenerateThumbnail from "../util/generateThumbnail"; -import generateUniqueFilename, { generateUniqueBillFilename } from "../util/generateUniqueFilename"; +import { generateUniqueBillFilename } from "../util/generateUniqueFilename"; import { ConvertHeicFiles } from "../util/heicConverter"; import { PathToRoBillsFolder, PathToVendorBillsFile } from "../util/pathGenerators"; import { BillsListMedia } from "./billsListMedia"; diff --git a/jobs/jobRequestValidator.ts b/jobs/jobRequestValidator.ts index 74c4320..3573fe1 100644 --- a/jobs/jobRequestValidator.ts +++ b/jobs/jobRequestValidator.ts @@ -1,11 +1,9 @@ -import { Request, Response, NextFunction } from "express"; +import { NextFunction, Request, Response } from "express"; -export default function ValidateJobBasedRequest(req: Request, res: Response, next: NextFunction) { - const jobid: string = (req.body.jobid || "").trim(); - if (jobid === "") { - res.status(400).json({ error: "No RO Number has been specified." }); - return; - } else { - next(); +export default function validateJobRequest(req: Request, res: Response, next: NextFunction) { + const jobId: string = (req.body.jobid || "").trim(); + if (jobId === "") { + return res.status(400).json({ error: "No RO Number has been specified." }); } + next(); } diff --git a/jobs/jobsListMedia.ts b/jobs/jobsListMedia.ts index a8e4e38..2f75cb0 100644 --- a/jobs/jobsListMedia.ts +++ b/jobs/jobsListMedia.ts @@ -1,6 +1,6 @@ import { Request, Response } from "express"; -import ft from "file-type"; -import core from "file-type/core"; +import { fileTypeFromFile } from "file-type"; +import { FileTypeResult } from "file-type/core"; import fs from "fs-extra"; import { logger } from "../server"; import GenerateUrl from "../util/MediaUrlGen"; @@ -24,7 +24,7 @@ export async function JobsListMedia(req: Request, res: Response) { const relativeThumbPath: string = await GenerateThumbnail(relativeFilePath); - const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(relativeFilePath); + const type: FileTypeResult | undefined = await fileTypeFromFile(relativeFilePath); return { type, @@ -50,7 +50,7 @@ export async function JobsListMedia(req: Request, res: Response) { const relativeFilePath: string = JobRelativeFilePath(jobid, file.name); const relativeThumbPath: string = await GenerateThumbnail(relativeFilePath); - const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(relativeFilePath); + const type: FileTypeResult | undefined = await fileTypeFromFile(relativeFilePath); const fileSize = await fs.stat(relativeFilePath); return { type, diff --git a/package-lock.json b/package-lock.json index ceb3f3e..c1d8e4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "nocache": "^4.0.0", "response-time": "^2.3.2", "simple-thumbnail": "^1.6.5", + "simple-thumbnail-ts": "^1.0.2", "winston": "^3.13.1", "winston-daily-rotate-file": "^5.0.0" }, @@ -983,14 +984,14 @@ } }, "node_modules/duplexify": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-4.1.2.tgz", - "integrity": "sha512-fz3OjcNCHmRP12MJoZMPglx8m4rrFP8rovnk4vT8Fs+aonZoCwGg10dSsQsfP/E62eZcPTMSMP6686fu9Qlqtw==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-4.1.3.tgz", + "integrity": "sha512-M3BmBhwJRZsSx38lZyhE53Csddgzl5R7xGJNk7CVddZD6CcmwMCH8J+7AprIrQKH7TonKxaCjcv27Qmf+sQ+oA==", "dependencies": { "end-of-stream": "^1.4.1", "inherits": "^2.0.3", "readable-stream": "^3.1.1", - "stream-shift": "^1.0.0" + "stream-shift": "^1.0.2" } }, "node_modules/ee-first": { @@ -2500,6 +2501,14 @@ "duplexify": "^4.0.0" } }, + "node_modules/simple-thumbnail-ts": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/simple-thumbnail-ts/-/simple-thumbnail-ts-1.0.2.tgz", + "integrity": "sha512-4t9h/d3Lg4q3H2H7mOADpCk8tc0WQKCtKsLz5bnAFUu0mA9n8EC+EYdIbusBO6s7wCNSIYcL/vAKJ7qMquJqwQ==", + "dependencies": { + "duplexify": "^4.0.0" + } + }, "node_modules/simple-update-notifier": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", @@ -2531,9 +2540,9 @@ } }, "node_modules/stream-shift": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz", - "integrity": "sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==" + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.3.tgz", + "integrity": "sha512-76ORR0DO1o1hlKwTbi/DM3EXWGf3ZJYO8cXX5RJwnul2DEg2oyoZyjLNoQM8WsvZiFKCRfC1O0J7iCvie3RZmQ==" }, "node_modules/streamsearch": { "version": "0.1.2", @@ -3677,14 +3686,14 @@ "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==" }, "duplexify": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-4.1.2.tgz", - "integrity": "sha512-fz3OjcNCHmRP12MJoZMPglx8m4rrFP8rovnk4vT8Fs+aonZoCwGg10dSsQsfP/E62eZcPTMSMP6686fu9Qlqtw==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-4.1.3.tgz", + "integrity": "sha512-M3BmBhwJRZsSx38lZyhE53Csddgzl5R7xGJNk7CVddZD6CcmwMCH8J+7AprIrQKH7TonKxaCjcv27Qmf+sQ+oA==", "requires": { "end-of-stream": "^1.4.1", "inherits": "^2.0.3", "readable-stream": "^3.1.1", - "stream-shift": "^1.0.0" + "stream-shift": "^1.0.2" } }, "ee-first": { @@ -4747,6 +4756,14 @@ "duplexify": "^4.0.0" } }, + "simple-thumbnail-ts": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/simple-thumbnail-ts/-/simple-thumbnail-ts-1.0.2.tgz", + "integrity": "sha512-4t9h/d3Lg4q3H2H7mOADpCk8tc0WQKCtKsLz5bnAFUu0mA9n8EC+EYdIbusBO6s7wCNSIYcL/vAKJ7qMquJqwQ==", + "requires": { + "duplexify": "^4.0.0" + } + }, "simple-update-notifier": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", @@ -4767,9 +4784,9 @@ "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" }, "stream-shift": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz", - "integrity": "sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==" + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.3.tgz", + "integrity": "sha512-76ORR0DO1o1hlKwTbi/DM3EXWGf3ZJYO8cXX5RJwnul2DEg2oyoZyjLNoQM8WsvZiFKCRfC1O0J7iCvie3RZmQ==" }, "streamsearch": { "version": "0.1.2", diff --git a/package.json b/package.json index b314e2c..439c7d0 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,9 @@ "engines": { "node": ">=18.0.0" }, + "type": "module", "scripts": { - "server": "nodemon server.ts", + "server": "nodemon server", "start": "node dist/server.js", "build": "tsc -p .", "makeitpretty": "prettier --write \"**/*.{css,js,json,jsx,scss,ts}\"" diff --git a/server.ts b/server.ts index d05b15c..485b623 100644 --- a/server.ts +++ b/server.ts @@ -1,25 +1,25 @@ import bodyParser from "body-parser"; +import cors from "cors"; import dotenv from "dotenv"; import express, { Express } from "express"; -import winston from "winston"; +import helmet from "helmet"; +import morgan from "morgan"; +import nocache from "nocache"; import path, { resolve } from "path"; -import JobRequestValidator from "./jobs/jobRequestValidator"; +import responseTime from "response-time"; +import winston from "winston"; +import DailyRotateFile from "winston-daily-rotate-file"; +import BillRequestValidator from "./bills/billRequestValidator"; +import { BillsListMedia } from "./bills/billsListMedia"; +import { BillsMediaUploadMulter, BillsUploadMedia } from "./bills/billsUploadMedia"; +import validateJobRequest from "./jobs/jobRequestValidator"; +import { JobsDeleteMedia } from "./jobs/jobsDeleteMedia"; +import { jobsDownloadMedia } from "./jobs/jobsDownloadMedia"; import { JobsListMedia } from "./jobs/jobsListMedia"; import { JobsMoveMedia } from "./jobs/jobsMoveMedia"; import { JobMediaUploadMulter, jobsUploadMedia } from "./jobs/jobsUploadMedia"; import InitServer, { FolderPaths } from "./util/serverInit"; -import DailyRotateFile from "winston-daily-rotate-file"; -import morgan from "morgan"; -import { BillsListMedia } from "./bills/billsListMedia"; -import BillRequestValidator from "./bills/billRequestValidator"; -import cors from "cors"; -import helmet from "helmet"; -import responseTime from "response-time"; -import nocache from "nocache"; -import { BillsMediaUploadMulter, BillsUploadMedia } from "./bills/billsUploadMedia"; import ValidateImsToken from "./util/validateToken"; -import { jobsDownloadMedia } from "./jobs/jobsDownloadMedia"; -import { JobsDeleteMedia } from "./jobs/jobsDeleteMedia"; dotenv.config({ path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`) @@ -109,9 +109,9 @@ const morganMiddleware = morgan( app.use(morganMiddleware); app.use(helmet({ crossOriginResourcePolicy: { policy: "cross-origin" } })); -app.post("/jobs/list", ValidateImsToken, JobRequestValidator, JobsListMedia); -app.post("/jobs/upload", ValidateImsToken, JobMediaUploadMulter.array("file"), JobRequestValidator, jobsUploadMedia); -app.post("/jobs/download", ValidateImsToken, JobRequestValidator, jobsDownloadMedia); +app.post("/jobs/list", ValidateImsToken, validateJobRequest, JobsListMedia); +app.post("/jobs/upload", ValidateImsToken, JobMediaUploadMulter.array("file"), validateJobRequest, jobsUploadMedia); +app.post("/jobs/download", ValidateImsToken, validateJobRequest, jobsDownloadMedia); app.post( "/jobs/move", //JobRequestValidator, ValidateImsToken, diff --git a/tsconfig.json b/tsconfig.json index 086055e..ca33ded 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,101 +1,25 @@ { "compilerOptions": { - /* Visit https://aka.ms/tsconfig.json to read more about this file */ - - /* Projects */ - // "incremental": true, /* Enable incremental compilation */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - /* Language and Environment */ - "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ - // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - + "target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + // "lib": [ + // "ESNext", + // "DOM" + // ] /* Modules */ - "module": "commonjs" /* Specify what module code is generated. */, - // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "resolveJsonModule": true, /* Enable importing .json files */ - // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ - - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ - - /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "module": "ESNext" /* Specify what module code is generated. */, + "moduleResolution": "Node", + "resolveJsonModule": true /* Enable importing .json files */, "outDir": "./dist" /* Specify an output folder for all emitted files. */, - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - // "newLine": "crlf", /* Set the newline character for emitting files. */ - // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */, "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, - /* Type Checking */ "strict": true /* Enable all strict type-checking options. */, - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ - // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ - // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "include": ["*.ts"], + "exclude": [] } diff --git a/util/generateThumbnail.ts b/util/generateThumbnail.ts index f8622bf..d315b27 100644 --- a/util/generateThumbnail.ts +++ b/util/generateThumbnail.ts @@ -1,12 +1,11 @@ -import ft from "file-type"; -import core from "file-type/core"; +import { fileTypeFromFile } from "file-type"; +import { FileTypeResult } 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"; const simpleThumb = require("simple-thumbnail"); //const ffmpeg = require("ffmpeg-static"); @@ -20,7 +19,8 @@ export default async function GenerateThumbnail( file: string //thumbPath: string ) { - const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(file); + // const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(file); + const type: FileTypeResult | undefined = await fileTypeFromFile(file); let thumbnailExtension: string = GetThumbnailExtension(type); let thumbPath: string = path.join( path.dirname(file), @@ -85,7 +85,7 @@ async function GeneratePdfThumbnail(file: string, thumbPath: string) { }); } -function GetThumbnailExtension(file: core.FileTypeResult | undefined) { +function GetThumbnailExtension(file: FileTypeResult | undefined) { if (file === undefined) return ".png"; return ".png"; } diff --git a/util/heicConverter.ts b/util/heicConverter.ts index 1999685..b30f07f 100644 --- a/util/heicConverter.ts +++ b/util/heicConverter.ts @@ -1,8 +1,8 @@ import fs from "fs-extra"; import dotenv from "dotenv"; -import ft from "file-type"; -import core from "file-type/core"; +import { fileTypeFromFile } from "file-type"; +import { FileTypeResult } from "file-type/core"; import gm from "gm"; import path, { resolve } from "path"; import { logger } from "../server"; @@ -18,7 +18,7 @@ dotenv.config({ export async function ConvertHeicFiles(files: Express.Multer.File[]) { for (const file of files) { - const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(file.path); + const type: FileTypeResult | undefined = await fileTypeFromFile(file.path); if (type?.mime === "image/heic") { logger.log("debug", `Converting ${file.filename} image to JPEG from HEIC.`); const convertedFileName = `${ diff --git a/util/serverInit.ts b/util/serverInit.ts index bee903f..c0bdf26 100644 --- a/util/serverInit.ts +++ b/util/serverInit.ts @@ -1,5 +1,5 @@ -import fs = require("fs-extra"); import dotenv from "dotenv"; +import { ensureDirSync } from "fs-extra"; import os from "os"; import path, { resolve } from "path"; import { logger } from "../server"; @@ -36,11 +36,11 @@ export function BillsRelativeFilePath(jobid: string, filename: string) { } export default function InitServer() { logger.info(`Ensuring Root media path exists: ${FolderPaths.Root}`); - fs.ensureDirSync(FolderPaths.Root); + ensureDirSync(FolderPaths.Root); logger.info(`Ensuring Jobs media path exists: ${FolderPaths.Jobs}`); - fs.ensureDirSync(FolderPaths.Jobs); + ensureDirSync(FolderPaths.Jobs); logger.info(`Ensuring Vendors media path exists: ${FolderPaths.Vendors}`); - fs.ensureDirSync(FolderPaths.Vendors); + ensureDirSync(FolderPaths.Vendors); logger.info("Folder Paths", FolderPaths); logger.info("IMS Token set to: " + (process.env.IMS_TOKEN || "").trim()); } diff --git a/util/validateToken.ts b/util/validateToken.ts index 7904e87..69f68cb 100644 --- a/util/validateToken.ts +++ b/util/validateToken.ts @@ -1,7 +1,7 @@ -import { Request, Response, NextFunction } from "express"; import dotenv from "dotenv"; +import { NextFunction, Request, Response } from "express"; import { resolve } from "path"; -import { logger } from "../server"; +//import { logger } from "../server.ts"; dotenv.config({ path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`) diff --git a/yarn.lock b/yarn.lock index 4de2056..960541f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -622,14 +622,14 @@ dotenv@16.4.5: integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg== duplexify@^4.0.0: - version "4.1.2" - resolved "https://registry.npmjs.org/duplexify/-/duplexify-4.1.2.tgz" - integrity sha512-fz3OjcNCHmRP12MJoZMPglx8m4rrFP8rovnk4vT8Fs+aonZoCwGg10dSsQsfP/E62eZcPTMSMP6686fu9Qlqtw== + version "4.1.3" + resolved "https://registry.npmjs.org/duplexify/-/duplexify-4.1.3.tgz" + integrity sha512-M3BmBhwJRZsSx38lZyhE53Csddgzl5R7xGJNk7CVddZD6CcmwMCH8J+7AprIrQKH7TonKxaCjcv27Qmf+sQ+oA== dependencies: end-of-stream "^1.4.1" inherits "^2.0.3" readable-stream "^3.1.1" - stream-shift "^1.0.0" + stream-shift "^1.0.2" ee-first@1.1.1: version "1.1.1" @@ -1568,6 +1568,13 @@ simple-swizzle@^0.2.2: dependencies: is-arrayish "^0.3.1" +simple-thumbnail-ts@^1.0.2: + version "1.0.2" + resolved "https://registry.npmjs.org/simple-thumbnail-ts/-/simple-thumbnail-ts-1.0.2.tgz" + integrity sha512-4t9h/d3Lg4q3H2H7mOADpCk8tc0WQKCtKsLz5bnAFUu0mA9n8EC+EYdIbusBO6s7wCNSIYcL/vAKJ7qMquJqwQ== + dependencies: + duplexify "^4.0.0" + simple-thumbnail@^1.6.5: version "1.6.5" resolved "https://registry.npmjs.org/simple-thumbnail/-/simple-thumbnail-1.6.5.tgz" @@ -1592,10 +1599,10 @@ statuses@2.0.1: resolved "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz" integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ== -stream-shift@^1.0.0: - version "1.0.1" - resolved "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz" - integrity sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ== +stream-shift@^1.0.2: + version "1.0.3" + resolved "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.3.tgz" + integrity sha512-76ORR0DO1o1hlKwTbi/DM3EXWGf3ZJYO8cXX5RJwnul2DEg2oyoZyjLNoQM8WsvZiFKCRfC1O0J7iCvie3RZmQ== streamsearch@0.1.2: version "0.1.2"