UNPKG

kura-s3

Version:

The FileSystem API abstraction library, AWS S3 Plugin

101 lines 3.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.S3DirectoryEntry = void 0; const kura_1 = require("kura"); const S3FileEntry_1 = require("./S3FileEntry"); class S3DirectoryEntry extends kura_1.AbstractDirectoryEntry { constructor(params) { super(params); } getDirectory(path, options, successCallback, errorCallback) { const fullPath = kura_1.resolveToFullPath(this.fullPath, path); this.params.accessor .getObject(fullPath, false) .then((obj) => { if (fullPath === kura_1.DIR_SEPARATOR) { successCallback(this.filesystem.root); return; } if (!options) { options = {}; } if (!successCallback) { successCallback = () => { }; } if (obj.size != null && 0 < obj.size) { kura_1.onError(new kura_1.PathExistsError(this.filesystem.name, fullPath, `${fullPath} is not a directory`), errorCallback); return; } successCallback(this.toDirectoryEntry(obj)); }) .catch((err) => { const name = fullPath.split(kura_1.DIR_SEPARATOR).pop(); const accessor = this.params.accessor; if (err instanceof kura_1.NotFoundError) { const entry = new S3DirectoryEntry({ accessor: accessor, name: name, fullPath: fullPath, }); if (accessor.options.index) { const obj = { name: name, fullPath: fullPath, }; accessor .getRecord(fullPath) .then(() => { successCallback(entry); }) .catch(async (e) => { if (e instanceof kura_1.NotFoundError) { try { const record = await accessor.createRecord(obj); await accessor.saveRecord(obj.fullPath, record); successCallback(entry); } catch (e) { kura_1.onError(e, errorCallback); } } else { kura_1.onError(e, errorCallback); } }); } else { successCallback(entry); } } else { kura_1.onError(err, errorCallback); } }); } createEntry(obj) { return obj.size != null ? new S3FileEntry_1.S3FileEntry({ accessor: this.params.accessor, ...obj, }) : new S3DirectoryEntry({ accessor: this.params.accessor, ...obj, }); } toDirectoryEntry(obj) { return new S3DirectoryEntry({ accessor: this.params.accessor, ...obj, }); } toFileEntry(obj) { return new S3FileEntry_1.S3FileEntry({ accessor: this.params.accessor, ...obj, }); } } exports.S3DirectoryEntry = S3DirectoryEntry; //# sourceMappingURL=S3DirectoryEntry.js.map