UNPKG

alapa

Version:

A cutting-edge web development framework designed to revolutionize the way developers build modern web applications.

67 lines (66 loc) 2.56 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LocalStorageDriver = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const utils_1 = require("../../utils"); const globals_1 = require("../../shared/globals"); class LocalStorageDriver { name; absolutePathPath; absoluteURL; config; staticFilePath; constructor(absolutePathPath, absoluteURL) { this.name = "local"; this.config = globals_1.GlobalConfig?.storage; this.staticFilePath = globals_1.GlobalConfig?.view?.staticFilesPath || "static"; this.absolutePathPath = this.config?.local?.path || "uploads"; this.absolutePathPath = absolutePathPath || path.join(this.staticFilePath, this.absolutePathPath); this.absoluteURL = absoluteURL || this.config?.local?.url || "http://localhost:3000"; } absolutePath; error = null; async saveFile(filePath, key) { try { const targetPath = path.join(this.absolutePathPath, key); const fileData = fs.readFileSync(filePath); const dir = path.dirname(targetPath); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } fs.writeFileSync(targetPath, fileData); return key; } catch (err) { utils_1.Logger.error(err); return false; } } } exports.LocalStorageDriver = LocalStorageDriver;