@safient/core
Version:
JavaScript SDK to manage safes and interact with Safient protocol.
54 lines (53 loc) • 2.2 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Storage = void 0;
const ipfs_1 = require("../utils/ipfs");
class Storage {
constructor(storage) {
this.add = (data, fileName) => __awaiter(this, void 0, void 0, function* () {
try {
if (this.storageType === 'IPFS') {
const result = yield (0, ipfs_1.ipfsPublish)(fileName, data);
return result;
}
}
catch (err) {
console.log(err);
throw new Error("Error while publishing data");
}
});
this.create = (data) => __awaiter(this, void 0, void 0, function* () {
try {
if (this.storageType === 'IPFS') {
const result = yield (0, ipfs_1.ipfsAdd)(data);
return result;
}
}
catch (err) {
throw new Error(`Error while publishing data, ${err}`);
}
});
this.get = (cidHash) => __awaiter(this, void 0, void 0, function* () {
try {
if (this.storageType === 'IPFS') {
const result = yield (0, ipfs_1.ipfsGet)(cidHash);
return result;
}
}
catch (err) {
throw new Error("Error while getting data");
}
});
this.storageType = storage;
}
}
exports.Storage = Storage;