This commit is contained in:
Allan Carr
2025-07-13 00:17:08 -07:00
parent 231130267f
commit 7f782d5a64
19 changed files with 2564 additions and 1416 deletions

View File

@@ -8,17 +8,21 @@ dotenv.config({
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
});
const RootDirectory = process.env.MEDIA_PATH!.replace("~", os.homedir);
// 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",
ThumbsSubDir: "thumbs",
BillsSubDir: "bills",
ConvertedOriginalSubDir: "ConvertedOriginal",
StaticPath: "/static",
JobsFolder,
VendorsFolder
@@ -28,19 +32,25 @@ 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());
}