UNPKG

@apillon/cli

Version:
95 lines 4.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deleteDirectory = exports.deleteFile = exports.getFile = exports.uploadFromFolder = exports.listFiles = exports.listObjects = exports.listBuckets = exports.createBucket = void 0; const sdk_1 = require("@apillon/sdk"); const options_1 = require("../../lib/options"); const utils_1 = require("../../lib/utils"); async function createBucket(optsWithGlobals) { await (0, utils_1.withErrorHandler)(async () => { const bucket = await new sdk_1.Storage(optsWithGlobals).createBucket({ name: optsWithGlobals.name, description: optsWithGlobals.description, }); console.log('Bucket created successfully'); console.log(bucket.serialize()); }); } exports.createBucket = createBucket; async function listBuckets(optsWithGlobals) { await (0, utils_1.withErrorHandler)(async () => { const data = await new sdk_1.Storage(optsWithGlobals).listBuckets((0, options_1.paginate)(optsWithGlobals)); data.items = data.items.map((w) => w.serialize()); console.log(data); }); } exports.listBuckets = listBuckets; async function listObjects(optsWithGlobals) { await (0, utils_1.withErrorHandler)(async () => { const data = await new sdk_1.Storage(optsWithGlobals) .bucket(optsWithGlobals.bucketUuid) .listObjects(Object.assign(Object.assign({}, (0, options_1.paginate)(optsWithGlobals)), { directoryUuid: optsWithGlobals.directoryUuid, markedForDeletion: !!optsWithGlobals.deleted })); data.items = data.items.map((w) => w.serialize()); console.log(data); }); } exports.listObjects = listObjects; async function listFiles(optsWithGlobals) { await (0, utils_1.withErrorHandler)(async () => { const data = await new sdk_1.Storage(optsWithGlobals) .bucket(optsWithGlobals.bucketUuid) .listFiles(Object.assign(Object.assign({}, (0, options_1.paginate)(optsWithGlobals)), { fileStatus: (0, sdk_1.toInteger)(optsWithGlobals.fileStatus) })); data.items = data.items.map((w) => w.serialize()); console.log(data); }); } exports.listFiles = listFiles; async function uploadFromFolder(path, optsWithGlobals) { if (!!optsWithGlobals.wrap && !optsWithGlobals.path) { console.error('Error: path option (-p, --path) is required when --wrap option is supplied'); return; } await (0, utils_1.withErrorHandler)(async () => { console.log(`Uploading files from folder: ${path}`); const files = await new sdk_1.Storage(optsWithGlobals) .bucket(optsWithGlobals.bucketUuid) .uploadFromFolder(path, { wrapWithDirectory: !!optsWithGlobals.wrap, directoryPath: optsWithGlobals.path, awaitCid: !!optsWithGlobals.await, ignoreFiles: !!optsWithGlobals.ignore, }); console.log(files); }); } exports.uploadFromFolder = uploadFromFolder; async function getFile(optsWithGlobals) { await (0, utils_1.withErrorHandler)(async () => { const file = await new sdk_1.Storage(optsWithGlobals) .bucket(optsWithGlobals.bucketUuid) .file(optsWithGlobals.fileUuid) .get(); console.log(file.serialize()); }); } exports.getFile = getFile; async function deleteFile(optsWithGlobals) { await (0, utils_1.withErrorHandler)(async () => { await new sdk_1.Storage(optsWithGlobals) .bucket(optsWithGlobals.bucketUuid) .file(optsWithGlobals.fileUuid) .delete(); console.log('File deleted successfully'); }); } exports.deleteFile = deleteFile; async function deleteDirectory(optsWithGlobals) { await (0, utils_1.withErrorHandler)(async () => { await new sdk_1.Storage(optsWithGlobals) .bucket(optsWithGlobals.bucketUuid) .directory(optsWithGlobals.directoryUuid) .delete(); console.log('Directory deleted successfully'); }); } exports.deleteDirectory = deleteDirectory; //# sourceMappingURL=storage.service.js.map