Package Updates

This commit is contained in:
Allan Carr
2024-07-23 09:49:47 -07:00
parent f295488195
commit 58055fd1b3
22 changed files with 1686 additions and 3807 deletions

18
.prettierrc.js Normal file
View File

@@ -0,0 +1,18 @@
const config = {
printWidth: 120,
useTabs: false,
tabWidth: 2,
trailingComma: "none",
semi: true,
singleQuote: false,
bracketSpacing: true,
arrowParens: "always",
jsxSingleQuote: false,
bracketSameLine: false,
endOfLine: "lf"
// importOrder: ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"],
// importOrderSeparation: true,
// importOrderSortSpecifiers: true
};
module.exports = config;

View File

@@ -1,4 +1,4 @@
FROM node:16
FROM node:20
# Create app directory
WORKDIR /usr/src/app
@@ -28,9 +28,9 @@ RUN apt install -y libwebp-dev
# Install HEIF support (libheic-dev Package does not exist on 16.04)
RUN apt-get -y install libde265-dev
RUN apt-get -y install pkg-config m4 libtool automake autoconf
RUN wget https://github.com/strukturag/libheif/archive/v1.14.1.tar.gz
RUN tar -xvf v1.14.1.tar.gz
WORKDIR /usr/src/app/libheif-1.14.1/
RUN wget https://github.com/strukturag/libheif/archive/v1.18.0.tar.gz
RUN tar -xvf v1.18.0.tar.gz
WORKDIR /usr/src/app/libheif-1.18.0/
RUN ./autogen.sh
RUN ./configure
RUN make
@@ -46,9 +46,9 @@ RUN apt-get -y install wget && apt-get install -y ruby-full && ruby -v
# RUN apt-get install imagemagick -y
# # Install ImageMagick with WEBP and HEIC support
RUN wget https://download.imagemagick.org/archive/releases/ImageMagick-7.1.1-13.tar.xz
RUN tar -xvf ImageMagick-7.1.1-13.tar.xz
WORKDIR /usr/src/app/ImageMagick-7.1.1-13/
RUN wget https://download.imagemagick.org/archive/releases/ImageMagick-7.1.1-35.tar.xz
RUN tar -xvf ImageMagick-7.1.1-35.tar.xz
WORKDIR /usr/src/app/ImageMagick-7.1.1-35/
RUN ./configure --with-heic=yes --with-webp=yes
RUN make
RUN make install

View File

@@ -1,10 +1,6 @@
import { Request, Response, NextFunction } from "express";
export default function BillRequestValidator(
req: Request,
res: Response,
next: NextFunction
) {
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();

View File

@@ -22,17 +22,10 @@ export async function BillsListMedia(req: Request, res: Response) {
if (req.files) {
ret = await Promise.all(
(req.files as Express.Multer.File[]).map(async (file) => {
const relativeFilePath: string = path.join(
PathToRoBillsFolder(jobid),
file.filename
);
const relativeFilePath: string = path.join(PathToRoBillsFolder(jobid), file.filename);
const relativeThumbPath: string = await GenerateThumbnail(
relativeFilePath
);
const type: core.FileTypeResult | undefined = await ft.fromFile(
relativeFilePath
);
const relativeThumbPath: string = await GenerateThumbnail(relativeFilePath);
const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(relativeFilePath);
return {
type,
size: file.size,
@@ -41,72 +34,57 @@ export async function BillsListMedia(req: Request, res: Response) {
FolderPaths.JobsFolder,
jobid,
FolderPaths.BillsSubDir,
file.filename,
file.filename
]),
thumbnail: GenerateUrl([
FolderPaths.StaticPath,
FolderPaths.JobsFolder,
jobid,
FolderPaths.BillsSubDir,
relativeThumbPath,
relativeThumbPath
]),
thumbnailHeight: 250,
thumbnailWidth: 250,
filename: file.filename,
relativeFilePath,
relativeFilePath
};
})
);
} else {
let filesList: fs.Dirent[] = (
await fs.readdir(PathToRoBillsFolder(jobid), {
withFileTypes: true,
withFileTypes: true
})
).filter(
(f) =>
f.isFile() &&
!/(^|\/)\.[^\/\.]/g.test(f.name) &&
(invoice_number !== ""
? f.name.toLowerCase().includes(invoice_number.toLowerCase())
: true) &&
(invoice_number !== "" ? f.name.toLowerCase().includes(invoice_number.toLowerCase()) : true) &&
ListableChecker(f)
);
ret = await Promise.all(
filesList.map(async (file) => {
const relativeFilePath: string = path.join(
PathToRoBillsFolder(jobid),
file.name
);
const relativeFilePath: string = path.join(PathToRoBillsFolder(jobid), file.name);
const relativeThumbPath: string = await GenerateThumbnail(
relativeFilePath
);
const type: core.FileTypeResult | undefined = await ft.fromFile(
relativeFilePath
);
const relativeThumbPath: string = await GenerateThumbnail(relativeFilePath);
const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(relativeFilePath);
const fileSize = await fs.stat(relativeFilePath);
return {
type,
size: fileSize.size,
src: GenerateUrl([
FolderPaths.StaticPath,
FolderPaths.JobsFolder,
jobid,
FolderPaths.BillsSubDir,
file.name,
]),
src: GenerateUrl([FolderPaths.StaticPath, FolderPaths.JobsFolder, jobid, FolderPaths.BillsSubDir, file.name]),
thumbnail: GenerateUrl([
FolderPaths.StaticPath,
FolderPaths.JobsFolder,
jobid,
FolderPaths.BillsSubDir,
relativeThumbPath,
relativeThumbPath
]),
thumbnailHeight: 250,
thumbnailWidth: 250,
filename: file.name,
relativeFilePath,
relativeFilePath
};
})
);

View File

@@ -5,18 +5,13 @@ 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 generateUniqueFilename, { generateUniqueBillFilename } from "../util/generateUniqueFilename";
import { ConvertHeicFiles } from "../util/heicConverter";
import {
PathToRoBillsFolder,
PathToVendorBillsFile,
} from "../util/pathGenerators";
import { PathToRoBillsFolder, PathToVendorBillsFile } from "../util/pathGenerators";
import { BillsListMedia } from "./billsListMedia";
dotenv.config({
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`),
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
});
export const BillsMediaUploadMulter = multer({
@@ -25,27 +20,20 @@ export const BillsMediaUploadMulter = multer({
const jobid: string = (req.body.jobid || "").trim();
const DestinationFolder: string = PathToRoBillsFolder(jobid);
fs.ensureDirSync(DestinationFolder);
cb(
jobid === "" || jobid === null
? new Error("Job ID not specified.")
: null,
DestinationFolder
);
cb(jobid === "" || jobid === null ? new Error("Job ID not specified.") : null, DestinationFolder);
},
filename: function (req, file, cb) {
logger.info("Uploading file: ", {
file: path.basename(file.originalname),
file: path.basename(file.originalname)
});
const invoice_number: string = (req.body.invoice_number || "").trim();
cb(
invoice_number === "" || invoice_number === null
? new Error("Invoice number not specified.")
: null,
invoice_number === "" || invoice_number === null ? new Error("Invoice number not specified.") : null,
generateUniqueBillFilename(file, invoice_number)
);
},
}),
}
})
});
export async function BillsUploadMedia(req: Request, res: Response) {
@@ -53,7 +41,7 @@ export async function BillsUploadMedia(req: Request, res: Response) {
if (!req.files) {
res.send({
status: false,
message: "No file uploaded",
message: "No file uploaded"
});
} else {
await ConvertHeicFiles(req.files as Express.Multer.File[]);
@@ -76,10 +64,7 @@ export async function BillsUploadMedia(req: Request, res: Response) {
copyQueue.push(
(async () => {
const target: string = path.join(
PathToVendorBillsFile(vendorid),
file.filename
);
const target: string = path.join(PathToVendorBillsFile(vendorid), file.filename);
await fs.ensureDir(path.dirname(target));
await fs.copyFile(file.path, target);
})()
@@ -93,7 +78,7 @@ export async function BillsUploadMedia(req: Request, res: Response) {
} catch (error) {
logger.error("Error while uploading Bill Media", {
files: req.files,
error,
error
});
res.status(500).send(error);
}

View File

@@ -3,6 +3,6 @@ module.exports = [
script: "dist/server.js",
name: "MediaServer",
exec_mode: "cluster",
instances: 0,
},
instances: 0
}
];

View File

@@ -1,10 +1,6 @@
import { Request, Response, NextFunction } from "express";
export default function ValidateJobBasedRequest(
req: Request,
res: Response,
next: NextFunction
) {
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." });

View File

@@ -5,11 +5,7 @@ import { logger } from "../server";
import MediaFile from "../util/interfaces/MediaFile";
import ListableChecker from "../util/listableChecker";
import { PathToRoBillsFolder, PathToRoFolder } from "../util/pathGenerators";
import {
BillsRelativeFilePath,
FolderPaths,
JobRelativeFilePath,
} from "../util/serverInit";
import { BillsRelativeFilePath, FolderPaths, JobRelativeFilePath } from "../util/serverInit";
export async function JobsDeleteMedia(req: Request, res: Response) {
const jobid: string = (req.body.jobid || "").trim();
@@ -21,12 +17,12 @@ export async function JobsDeleteMedia(req: Request, res: Response) {
// Setup lists for both file locations
const jobFileList: fs.Dirent[] = (
await fs.readdir(PathToRoFolder(jobid), {
withFileTypes: true,
withFileTypes: true
})
).filter((f) => f.isFile() && ListableChecker(f));
const billFileList: fs.Dirent[] = (
await fs.readdir(PathToRoBillsFolder(jobid), {
withFileTypes: true,
withFileTypes: true
})
).filter((f) => f.isFile() && ListableChecker(f));
@@ -37,12 +33,7 @@ export async function JobsDeleteMedia(req: Request, res: Response) {
// File is in the set of requested files.
await fs.remove(JobRelativeFilePath(jobid, file.name));
await fs.remove(
path.join(
FolderPaths.Jobs,
jobid,
FolderPaths.ThumbsSubDir,
file.name.replace(/\.[^/.]+$/, ".png")
)
path.join(FolderPaths.Jobs, jobid, FolderPaths.ThumbsSubDir, file.name.replace(/\.[^/.]+$/, ".png"))
);
}
})

View File

@@ -22,12 +22,12 @@ export async function jobsDownloadMedia(req: Request, res: Response) {
const jobFileList: fs.Dirent[] = (
await fs.readdir(PathToRoFolder(jobid), {
withFileTypes: true,
withFileTypes: true
})
).filter((f) => f.isFile() && ListableChecker(f));
const billFileList: fs.Dirent[] = (
await fs.readdir(PathToRoBillsFolder(jobid), {
withFileTypes: true,
withFileTypes: true
})
).filter((f) => f.isFile() && ListableChecker(f));
@@ -36,18 +36,14 @@ export async function jobsDownloadMedia(req: Request, res: Response) {
await Promise.all(
jobFileList.map(async (file) => {
//Do something async
const fileOnDisk: Buffer = await fs.readFile(
JobRelativeFilePath(jobid, file.name)
);
const fileOnDisk: Buffer = await fs.readFile(JobRelativeFilePath(jobid, file.name));
zip.file(path.parse(path.basename(file.name)).base, fileOnDisk);
})
);
await Promise.all(
billFileList.map(async (file) => {
//Do something async
const fileOnDisk: Buffer = await fs.readFile(
BillsRelativeFilePath(jobid, file.name)
);
const fileOnDisk: Buffer = await fs.readFile(BillsRelativeFilePath(jobid, file.name));
zip.file(path.parse(path.basename(file.name)).base, fileOnDisk);
})
);
@@ -57,23 +53,19 @@ export async function jobsDownloadMedia(req: Request, res: Response) {
jobFileList.map(async (file) => {
if (files.includes(path.parse(path.basename(file.name)).base)) {
// File is in the set of requested files.
const fileOnDisk: Buffer = await fs.readFile(
JobRelativeFilePath(jobid, file.name)
);
const fileOnDisk: Buffer = await fs.readFile(JobRelativeFilePath(jobid, file.name));
zip.file(path.parse(path.basename(file.name)).base, fileOnDisk);
}
}),
})
);
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.
const fileOnDisk: Buffer = await fs.readFile(
BillsRelativeFilePath(jobid, file.name)
);
const fileOnDisk: Buffer = await fs.readFile(BillsRelativeFilePath(jobid, file.name));
zip.file(path.parse(path.basename(file.name)).base, fileOnDisk);
}
}),
})
);
}
//Send it as a response to download it automatically.
@@ -82,14 +74,14 @@ export async function jobsDownloadMedia(req: Request, res: Response) {
zip
.generateNodeStream({
type: "nodebuffer",
streamFiles: true,
streamFiles: true
//encodeFileName: (filename) => `${jobid}.zip`,
})
.pipe(res);
} catch (error) {
logger.error("Error downloading job media.", {
jobid,
error: (error as Error).message,
error: (error as Error).message
});
res.status(500).json((error as Error).message);
}

View File

@@ -20,81 +20,47 @@ export async function JobsListMedia(req: Request, res: Response) {
//We just uploaded files, we're going to send only those back.
ret = await Promise.all(
(req.files as Express.Multer.File[]).map(async (file) => {
const relativeFilePath: string = JobRelativeFilePath(
jobid,
file.filename
);
const relativeFilePath: string = JobRelativeFilePath(jobid, file.filename);
const relativeThumbPath: string = await GenerateThumbnail(
relativeFilePath
);
const relativeThumbPath: string = await GenerateThumbnail(relativeFilePath);
const type: core.FileTypeResult | undefined = await ft.fromFile(
relativeFilePath
);
const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(relativeFilePath);
return {
type,
size: file.size,
src: GenerateUrl([
FolderPaths.StaticPath,
FolderPaths.JobsFolder,
jobid,
file.filename,
]),
thumbnail: GenerateUrl([
FolderPaths.StaticPath,
FolderPaths.JobsFolder,
jobid,
relativeThumbPath,
]),
src: GenerateUrl([FolderPaths.StaticPath, FolderPaths.JobsFolder, jobid, file.filename]),
thumbnail: GenerateUrl([FolderPaths.StaticPath, FolderPaths.JobsFolder, jobid, relativeThumbPath]),
thumbnailHeight: 250,
thumbnailWidth: 250,
filename: file.filename,
relativeFilePath,
relativeFilePath
};
})
);
} else {
const filesList: fs.Dirent[] = (
await fs.readdir(PathToRoFolder(jobid), {
withFileTypes: true,
withFileTypes: true
})
).filter((f) => f.isFile() && ListableChecker(f));
ret = await Promise.all(
filesList.map(async (file) => {
const relativeFilePath: string = JobRelativeFilePath(
jobid,
file.name
);
const relativeFilePath: string = JobRelativeFilePath(jobid, file.name);
const relativeThumbPath: string = await GenerateThumbnail(
relativeFilePath
);
const type: core.FileTypeResult | undefined = await ft.fromFile(
relativeFilePath
);
const relativeThumbPath: string = await GenerateThumbnail(relativeFilePath);
const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(relativeFilePath);
const fileSize = await fs.stat(relativeFilePath);
return {
type,
size: fileSize.size,
src: GenerateUrl([
FolderPaths.StaticPath,
FolderPaths.JobsFolder,
jobid,
file.name,
]),
thumbnail: GenerateUrl([
FolderPaths.StaticPath,
FolderPaths.JobsFolder,
jobid,
relativeThumbPath,
]),
src: GenerateUrl([FolderPaths.StaticPath, FolderPaths.JobsFolder, jobid, file.name]),
thumbnail: GenerateUrl([FolderPaths.StaticPath, FolderPaths.JobsFolder, jobid, relativeThumbPath]),
thumbnailHeight: 250,
thumbnailWidth: 250,
filename: file.name,
relativeFilePath,
relativeFilePath
};
})
);

View File

@@ -26,14 +26,14 @@ export async function JobsMoveMedia(req: Request, res: Response) {
// Setup lists for both file locations
const jobFileList: string[] = (
await fs.readdir(PathToRoFolder(from_jobid), {
withFileTypes: true,
withFileTypes: true
})
)
.filter((f) => f.isFile() && ListableChecker(f))
.map((dirent) => dirent.name);
const billFileList: string[] = (
await fs.readdir(PathToRoBillsFolder(from_jobid), {
withFileTypes: true,
withFileTypes: true
})
)
.filter((f) => f.isFile() && ListableChecker(f))
@@ -47,38 +47,20 @@ export async function JobsMoveMedia(req: Request, res: Response) {
files.forEach((file) => {
if (jobFileList.includes(file)) {
movingQueue.push(
fs.move(
path.join(FolderPaths.Jobs, from_jobid, file),
path.join(FolderPaths.Jobs, jobid, file)
)
fs.move(path.join(FolderPaths.Jobs, from_jobid, file), path.join(FolderPaths.Jobs, jobid, file))
);
movingQueue.push(
fs.move(
path.join(
FolderPaths.Jobs,
from_jobid,
FolderPaths.ThumbsSubDir,
file.replace(/\.[^/.]+$/, ".png")
),
path.join(
FolderPaths.Jobs,
jobid,
FolderPaths.ThumbsSubDir,
file.replace(/\.[^/.]+$/, ".png")
)
path.join(FolderPaths.Jobs, from_jobid, FolderPaths.ThumbsSubDir, file.replace(/\.[^/.]+$/, ".png")),
path.join(FolderPaths.Jobs, jobid, FolderPaths.ThumbsSubDir, file.replace(/\.[^/.]+$/, ".png"))
)
);
}
if (billFileList.includes(file)) {
movingQueue.push(
fs.move(
path.join(
FolderPaths.Jobs,
from_jobid,
FolderPaths.BillsSubDir,
file
),
path.join(FolderPaths.Jobs, from_jobid, FolderPaths.BillsSubDir, file),
path.join(FolderPaths.Jobs, jobid, FolderPaths.BillsSubDir, file)
)
);
@@ -114,7 +96,7 @@ export async function JobsMoveMedia(req: Request, res: Response) {
from_jobid,
jobid,
files,
err,
err
});
res.status(500).send(err);
}

View File

@@ -15,20 +15,15 @@ export const JobMediaUploadMulter = multer({
const jobid: string = (req.body.jobid || "").trim();
const DestinationFolder: string = PathToRoFolder(jobid);
fs.ensureDirSync(DestinationFolder);
cb(
jobid === "" || jobid === null
? new Error("Job ID not specified.")
: null,
DestinationFolder
);
cb(jobid === "" || jobid === null ? new Error("Job ID not specified.") : null, DestinationFolder);
},
filename: function (req, file, cb) {
logger.debug("Uploading file: ", {
file: path.basename(file.originalname),
file: path.basename(file.originalname)
});
cb(null, generateUniqueFilename(file));
},
}),
}
})
});
export async function jobsUploadMedia(req: Request, res: Response) {
@@ -39,7 +34,7 @@ export async function jobsUploadMedia(req: Request, res: Response) {
logger.warning("Upload contained no files.");
res.status(400).send({
status: false,
message: "No file uploaded",
message: "No file uploaded"
});
} else {
//If we want to skip waiting for everything, just send it back that we're good.
@@ -69,7 +64,7 @@ export async function jobsUploadMedia(req: Request, res: Response) {
} catch (error) {
logger.error("Error uploading job media.", {
jobid,
error: (error as Error).message,
error: (error as Error).message
});
res.status(500).json((error as Error).message);
}

3556
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,48 +1,50 @@
{
"name": "bodyshop-media-server",
"version": "1.0.10",
"version": "1.0.12",
"license": "UNLICENSED",
"engines": {
"node": "^16.14.0"
"node": ">=18.0.0"
},
"scripts": {
"server": "nodemon server.ts",
"start": "node dist/server.js",
"build": "tsc -p ."
"build": "tsc -p .",
"makeitpretty": "prettier --write \"**/*.{css,js,json,jsx,scss,ts}\""
},
"dependencies": {
"axios": "^0.24.0",
"axios": "^1.7.2",
"bluebird": "^3.7.2",
"body-parser": "^1.20.0",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"dotenv": "10.0.0",
"express": "^4.17.3",
"file-type": "^16.5.3",
"fs-extra": "^10.1.0",
"gm": "^1.23.1",
"helmet": "^5.0.2",
"image-thumbnail": "^1.0.14",
"jszip": "^3.10.0",
"dotenv": "16.4.5",
"express": "^4.19.2",
"file-type": "^19.2.0",
"fs-extra": "^11.2.0",
"gm": "^1.25.0",
"helmet": "^7.1.0",
"image-thumbnail": "^1.0.15",
"jszip": "^3.10.1",
"morgan": "^1.10.0",
"multer": "^1.4.4",
"nocache": "^3.0.4",
"nocache": "^4.0.0",
"response-time": "^2.3.2",
"simple-thumbnail": "^1.6.5",
"winston": "^3.7.2",
"winston-daily-rotate-file": "^4.6.1"
"winston": "^3.13.1",
"winston-daily-rotate-file": "^5.0.0"
},
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/fs-extra": "^9.0.13",
"@types/gm": "^1.18.11",
"@types/image-thumbnail": "^1.0.1",
"@types/morgan": "^1.9.3",
"@types/multer": "^1.4.7",
"@types/node": "^16.11.32",
"@types/response-time": "^2.3.5",
"nodemon": "^2.0.15",
"ts-node": "^10.7.0",
"typescript": "^4.6.4"
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/fs-extra": "^11.0.4",
"@types/gm": "^1.25.4",
"@types/image-thumbnail": "^1.0.4",
"@types/morgan": "^1.9.9",
"@types/multer": "^1.4.11",
"@types/node": "^20.14.11",
"@types/response-time": "^2.3.8",
"nodemon": "^3.1.4",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"typescript": "^5.5.3"
}
}

View File

@@ -42,14 +42,13 @@ services:
command: # CLI arguments
- --global.checkNewVersion=true
- --global.sendAnonymousUsage=false
- --pilot.dashboard=false
- --entrypoints.https.address=:10443
- --entrypoints.https.forwardedHeaders.trustedIPs=173.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/12,172.64.0.0/13,131.0.72.0/22,2400:cb00::/32,2606:4700::/32,2803:f800::/32,2405:b500::/32,2405:8100::/32,2a06:98c0::/29,2c0f:f248::/32
- --log=true
- --log.level=ERROR # (Default: error) DEBUG, INFO, WARN, ERROR, FATAL, PANIC
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --providers.docker.network=t2_proxy
- --providers.docker.network=traefik_proxy
- --certificatesResolvers.dns-cloudflare.acme.email=cloudflare@thinkimex.com
- --certificatesResolvers.dns-cloudflare.acme.storage=/acme.json
- --certificatesResolvers.dns-cloudflare.acme.keyType=EC384
@@ -57,7 +56,7 @@ services:
- --certificatesresolvers.dns-cloudflare.acme.dnschallenge.resolvers=1.1.1.1:53,1.0.0.1:53,2606:4700:4700::1111:53,2606:4700:4700::1001:53
- --certificatesResolvers.dns-cloudflare.acme.dnsChallenge.delayBeforeCheck=90 # To delay DNS check and reduce LE hitrate
networks:
t2_proxy:
traefik_proxy:
ipv4_address: 192.168.90.254
ports:
- target: 10443
@@ -77,7 +76,7 @@ services:
container_name: cf-ddns
image: oznu/cloudflare-ddns:latest
networks:
- t2_proxy
- traefik_proxy
restart: always
environment:
- API_KEY=b8BWRbkJckVK0IG6600Iq5AYx4HYZ7dLzDWUOZ2D
@@ -92,7 +91,7 @@ services:
ims:
container_name: ims
networks:
- t2_proxy
- traefik_proxy
volumes:
- /mnt/ims:/media
environment:
@@ -117,7 +116,7 @@ services:
image: amir20/dozzle:latest
restart: always
networks:
- t2_proxy
- traefik_proxy
ports:
- "8080:8080"
security_opt:
@@ -135,7 +134,7 @@ services:
container_name: watchtower-ims
image: containrrr/watchtower
networks:
- t2_proxy
- traefik_proxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
@@ -154,8 +153,8 @@ services:
- "traefik.enable=false"
networks:
t2_proxy:
name: t2_proxy
traefik_proxy:
name: traefik_proxy
driver: bridge
ipam:
config:

View File

@@ -16,24 +16,17 @@ import cors from "cors";
import helmet from "helmet";
import responseTime from "response-time";
import nocache from "nocache";
import {
BillsMediaUploadMulter,
BillsUploadMedia,
} from "./bills/billsUploadMedia";
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"}`),
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
});
export const logger = winston.createLogger({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json(),
winston.format.prettyPrint()
),
format: winston.format.combine(winston.format.timestamp(), winston.format.json(), winston.format.prettyPrint()),
level: "http",
levels: { ...winston.config.syslog.levels, http: 8 },
exceptionHandlers: [
@@ -42,14 +35,11 @@ export const logger = winston.createLogger({
datePattern: "YYYY-MM-DD-HH",
zippedArchive: true,
maxSize: "20m",
maxFiles: "14d",
maxFiles: "14d"
}),
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
),
}),
format: winston.format.combine(winston.format.colorize(), winston.format.simple())
})
],
rejectionHandlers: [
new DailyRotateFile({
@@ -57,14 +47,11 @@ export const logger = winston.createLogger({
datePattern: "YYYY-MM-DD-HH",
zippedArchive: true,
maxSize: "20m",
maxFiles: "14d",
maxFiles: "14d"
}),
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
),
}),
format: winston.format.combine(winston.format.colorize(), winston.format.simple())
})
],
transports: [
new DailyRotateFile({
@@ -73,7 +60,7 @@ export const logger = winston.createLogger({
zippedArchive: true,
maxSize: "20m",
maxFiles: "14d",
level: "error",
level: "error"
}),
new DailyRotateFile({
@@ -82,25 +69,22 @@ export const logger = winston.createLogger({
zippedArchive: true,
maxSize: "20m",
maxFiles: "14d",
level: "debug",
level: "debug"
}),
new DailyRotateFile({
filename: path.join(FolderPaths.Root, "logs", "ALL-%DATE%.log"),
datePattern: "YYYY-MM-DD-HH",
zippedArchive: true,
maxSize: "20m",
maxFiles: "14d",
}),
],
maxFiles: "14d"
})
]
});
if (process.env.NODE_ENV !== "production") {
logger.add(
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
),
format: winston.format.combine(winston.format.colorize(), winston.format.simple())
})
);
}
@@ -118,27 +102,16 @@ const morganMiddleware = morgan(
"combined", //":method :url :status :res[content-length] - :response-time ms"
{
stream: {
write: (message) => logger.http(message.trim()),
},
write: (message) => logger.http(message.trim())
}
}
);
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/upload", ValidateImsToken, JobMediaUploadMulter.array("file"), JobRequestValidator, jobsUploadMedia);
app.post("/jobs/download", ValidateImsToken, JobRequestValidator, jobsDownloadMedia);
app.post(
"/jobs/move", //JobRequestValidator,
ValidateImsToken,
@@ -159,23 +132,13 @@ app.post(
BillsUploadMedia
);
app.get(
"/",
ValidateImsToken,
(req: express.Request, res: express.Response) => {
app.get("/", ValidateImsToken, (req: express.Request, res: express.Response) => {
res.send("IMS running.");
}
);
});
InitServer();
app.use(
FolderPaths.StaticPath,
express.static(FolderPaths.Root, { etag: false, maxAge: 30 * 1000 })
);
app.use(
"/assets",
express.static("./assets", { etag: false, maxAge: 30 * 1000 })
);
app.use(FolderPaths.StaticPath, express.static(FolderPaths.Root, { etag: false, maxAge: 30 * 1000 }));
app.use("/assets", express.static("./assets", { etag: false, maxAge: 30 * 1000 }));
app.listen(port, () => {
logger.info(`ImEX Media Server is running at http://localhost:${port}`);
});

View File

@@ -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);
}

View 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, "");
}

View File

@@ -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)}`);
}
}
}

View File

@@ -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) {

View File

@@ -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();

1406
yarn.lock

File diff suppressed because it is too large Load Diff