58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import dotenv from "dotenv";
|
|
import { ensureDirSync } from "fs-extra";
|
|
import os from "os";
|
|
import path, { resolve } from "path";
|
|
import { logger } from "../server.js";
|
|
|
|
dotenv.config({
|
|
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
|
});
|
|
|
|
// Resolve root directory, supporting ~ for home
|
|
const RootDirectory = (process.env.MEDIA_PATH || "").replace("~", os.homedir);
|
|
|
|
// Folder names
|
|
const JobsFolder = "Jobs";
|
|
const VendorsFolder = "Vendors";
|
|
|
|
// Folder paths object
|
|
export const FolderPaths = {
|
|
Root: RootDirectory,
|
|
Jobs: path.join(RootDirectory, JobsFolder),
|
|
Vendors: path.join(RootDirectory, VendorsFolder),
|
|
ThumbsSubDir: "thumbs",
|
|
BillsSubDir: "bills",
|
|
ConvertedOriginalSubDir: "ConvertedOriginal",
|
|
DamagedSubDir: "DamagedOriginal",
|
|
StaticPath: "/static",
|
|
JobsFolder,
|
|
VendorsFolder
|
|
};
|
|
|
|
export const AssetPaths = {
|
|
File: "/assets/file.png"
|
|
};
|
|
|
|
// Utility functions for relative file paths
|
|
export function JobRelativeFilePath(jobid: string, filename: string) {
|
|
return path.join(FolderPaths.Jobs, jobid, filename);
|
|
}
|
|
export function BillsRelativeFilePath(jobid: string, filename: string) {
|
|
return path.join(FolderPaths.Jobs, jobid, FolderPaths.BillsSubDir, filename);
|
|
}
|
|
|
|
// Ensure all required directories exist at startup
|
|
export default function InitServer() {
|
|
logger.info(`Ensuring Root media path exists: ${FolderPaths.Root}`);
|
|
ensureDirSync(FolderPaths.Root);
|
|
|
|
logger.info(`Ensuring Jobs media path exists: ${FolderPaths.Jobs}`);
|
|
ensureDirSync(FolderPaths.Jobs);
|
|
|
|
logger.info(`Ensuring Vendors media path exists: ${FolderPaths.Vendors}`);
|
|
ensureDirSync(FolderPaths.Vendors);
|
|
|
|
logger.info("Folder Paths", FolderPaths);
|
|
logger.info("IMS Token set to: " + (process.env.IMS_TOKEN || "").trim());
|
|
}
|