UNPKG

axiodb

Version:

A blazing-fast, lightweight, and scalable nodejs package based DBMS for modern application. Supports schemas, encryption, and advanced query capabilities.

163 lines 6.41 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const promises_1 = __importDefault(require("fs/promises")); const fs_1 = __importDefault(require("fs")); const worker_process_1 = __importDefault(require("../cli/worker_process")); // Import Helpers const response_helper_1 = __importDefault(require("../../Helper/response.helper")); class FolderManager { constructor() { this.fileSystem = promises_1.default; this.fileSystemSync = fs_1.default; this.responseHelper = new response_helper_1.default(); this.WorkerProcess = new worker_process_1.default(); } /** * Creates a new directory at the specified path. */ CreateDirectory(path) { return __awaiter(this, void 0, void 0, function* () { try { yield this.fileSystem.mkdir(path, { recursive: true }); return this.responseHelper.Success(`Directory created at: ${path}`); } catch (error) { return this.responseHelper.Error(`Failed to create directory: ${error}`); } }); } /** * Deletes a directory at the specified path. */ DeleteDirectory(path) { return __awaiter(this, void 0, void 0, function* () { try { yield this.fileSystem.rm(path, { recursive: true, force: true }); return this.responseHelper.Success(`Directory deleted: ${path}`); } catch (error) { return this.responseHelper.Error(`Failed to delete directory: ${error}`); } }); } /** * Checks if a directory exists at the specified path. */ DirectoryExists(path) { return __awaiter(this, void 0, void 0, function* () { try { yield this.fileSystem.access(path); return this.responseHelper.Success(false); } catch (_a) { return this.responseHelper.Error(true); } }); } /** * Lists the contents of a directory at the specified path. */ ListDirectory(path) { return __awaiter(this, void 0, void 0, function* () { try { const contents = yield this.fileSystem.readdir(path); return this.responseHelper.Success(contents); } catch (error) { return this.responseHelper.Error(`Failed to list directory: ${error}`); } }); } /** * Moves a directory from the old path to the new path. */ MoveDirectory(oldPath, newPath) { return __awaiter(this, void 0, void 0, function* () { try { yield this.fileSystem.rename(oldPath, newPath); return this.responseHelper.Success(`Moved directory to: ${newPath}`); } catch (error) { return this.responseHelper.Error(`Failed to move directory: ${error}`); } }); } /** * Locks a directory at the specified path. */ LockDirectory(path) { return __awaiter(this, void 0, void 0, function* () { try { yield this.fileSystem.chmod(path, 0o000); return this.responseHelper.Success(`Directory locked: ${path}`); } catch (error) { return this.responseHelper.Error(`Failed to lock directory: ${error}`); } }); } /** * Unlocks a directory at the specified path. */ UnlockDirectory(path) { return __awaiter(this, void 0, void 0, function* () { try { yield this.fileSystem.chmod(path, 0o777); return this.responseHelper.Success(`Directory unlocked: ${path}`); } catch (error) { return this.responseHelper.Error(`Failed to unlock directory: ${error}`); } }); } /** * Checks if a directory is locked at the specified path. */ IsDirectoryLocked(path) { return __awaiter(this, void 0, void 0, function* () { try { const stats = yield this.fileSystem.stat(path); const isLocked = (stats.mode & 0o200) === 0; // Check if the directory is locked (no write permission for owner) return this.responseHelper.Success(isLocked); } catch (error) { return this.responseHelper.Error(`Failed to check lock status: ${error}`); } }); } /** * get the size of a directory at the specified path. */ GetDirectorySize(path) { return __awaiter(this, void 0, void 0, function* () { try { const osType = worker_process_1.default.getOS(); if (osType === "windows") { const stdout = yield this.WorkerProcess.execCommand(`powershell -command "(Get-Item '${path}').length"`); const size = parseInt(stdout, 10); return this.responseHelper.Success(size); } const stdout = yield this.WorkerProcess.execCommand(`du -sb ${path}`); const size = parseInt(stdout.split("\t")[0], 10); return this.responseHelper.Success(size); } catch (err) { return this.responseHelper.Error(`Failed to get directory size: ${err}`); } }); } } exports.default = FolderManager; //# sourceMappingURL=FolderManager.js.map