Files
Autonomous-Bug-Explorer/dist/shared/infrastructure/StorageProvider.js
2026-03-04 16:26:32 -05:00

49 lines
1.5 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalStorageProvider = void 0;
const promises_1 = __importDefault(require("fs/promises"));
const path_1 = __importDefault(require("path"));
class LocalStorageProvider {
constructor(basePath) {
this.basePath = basePath;
}
resolve(relativePath) {
return path_1.default.join(this.basePath, relativePath);
}
async save(relativePath, data) {
const fullPath = this.resolve(relativePath);
await promises_1.default.mkdir(path_1.default.dirname(fullPath), { recursive: true });
await promises_1.default.writeFile(fullPath, data);
return fullPath;
}
async get(relativePath) {
try {
return await promises_1.default.readFile(this.resolve(relativePath));
}
catch {
return null;
}
}
async delete(relativePath) {
try {
await promises_1.default.unlink(this.resolve(relativePath));
}
catch {
// ignore missing file
}
}
async exists(relativePath) {
try {
await promises_1.default.access(this.resolve(relativePath));
return true;
}
catch {
return false;
}
}
}
exports.LocalStorageProvider = LocalStorageProvider;