47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import fs = require("fs-extra");
|
|
import dotenv from "dotenv";
|
|
import os from "os";
|
|
import path, { resolve } from "path";
|
|
import { logger } from "../server";
|
|
|
|
dotenv.config({
|
|
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
|
});
|
|
|
|
const RootDirectory = process.env.MEDIA_PATH!.replace("~", os.homedir);
|
|
const JobsFolder = "Jobs";
|
|
const VendorsFolder = "Vendors";
|
|
|
|
export const FolderPaths = {
|
|
Root: RootDirectory,
|
|
Jobs: path.join(RootDirectory, JobsFolder),
|
|
Vendors: path.join(RootDirectory, VendorsFolder),
|
|
ThumbsSubDir: "/thumbs",
|
|
BillsSubDir: "/bills",
|
|
ConvertedOriginalSubDir: "/ConvertedOriginal",
|
|
StaticPath: "/static",
|
|
JobsFolder,
|
|
VendorsFolder
|
|
};
|
|
|
|
export const AssetPaths = {
|
|
File: "/assets/file.png"
|
|
};
|
|
|
|
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);
|
|
}
|
|
export default function InitServer() {
|
|
logger.info(`Ensuring Root media path exists: ${FolderPaths.Root}`);
|
|
fs.ensureDirSync(FolderPaths.Root);
|
|
logger.info(`Ensuring Jobs media path exists: ${FolderPaths.Jobs}`);
|
|
fs.ensureDirSync(FolderPaths.Jobs);
|
|
logger.info(`Ensuring Vendors media path exists: ${FolderPaths.Vendors}`);
|
|
fs.ensureDirSync(FolderPaths.Vendors);
|
|
logger.info("Folder Paths", FolderPaths);
|
|
logger.info("IMS Token set to: " + (process.env.IMS_TOKEN || "").trim());
|
|
}
|