@b2y/document-module
Version:
A flexible multi-provider storage adapter for file operations across S3, Azure Blob, Google Drive, and local storage
47 lines (40 loc) • 1.51 kB
JavaScript
const path = require('path');
const fs = require('fs');
const DOCUMENTS_BASE_PATH = process.env.DOCUMENTS_BASE_PATH;
// Define file path constants
const FILE_PATHS = (() => {
// Base documents directory from environment
const BASE_DOCUMENTS_DIR = DOCUMENTS_BASE_PATH;
// Validate BASE_DOCUMENTS_DIR
if (!BASE_DOCUMENTS_DIR) {
throw new Error("DOCUMENTS_BASE_PATH must be specified in the environment variables.");
}
try {
// Resolve to absolute path
const resolvedPath = path.resolve(BASE_DOCUMENTS_DIR);
// Ensure base directory exists
if (!fs.existsSync(resolvedPath)) {
fs.mkdirSync(resolvedPath, { recursive: true });
console.log(`Created base documents directory: ${resolvedPath}`);
}
return Object.freeze({
// Base directory name only (e.g., "documents")
BASE_DOCUMENTS_DIR: path.basename(resolvedPath),
// Specific subdirectory name
DOCUMENTS_DIR: 'UploadDocument',
LOGO_DIR: 'Logo',
IMAGE_DIR: 'Image',
PROFILE_DIR: 'Profile',
PROJECT_TYPE_DIR:'ProjectType',
HistoryDocuments_DIR:'HistoryDocuments',
INVENTORY_DIR:'Inventory',
// Construct and return only directory names
get DOCS_PATH() {
return this.DOCUMENTS_DIR; // Returns only "UploadDocument"
}
});
} catch (error) {
throw new Error(`Error setting up documents directory: ${error.message}`);
}
})();
module.exports = FILE_PATHS;