blockfrost-js-ratelimited
Version:
A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API
108 lines (107 loc) • 3.26 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.pinRemove = exports.listByPath = exports.list = exports.pin = exports.gateway = exports.add = void 0;
const utils_1 = require("../../utils");
const form_data_1 = __importDefault(require("form-data"));
const fs_1 = __importDefault(require("fs"));
async function add(path) {
const stream = fs_1.default.createReadStream(path);
const data = new form_data_1.default();
data.append('file', stream);
return new Promise((resolve, reject) => {
this.axiosInstance
.post(`${this.apiUrl}/ipfs/add`, data, {
headers: {
'Content-Type': `multipart/form-data; boundary=${data.getBoundary()}`,
},
maxContentLength: 100000000,
maxBodyLength: 100000000,
})
.then(resp => {
resolve(resp.data);
})
.catch(err => {
reject(utils_1.handleError(err));
});
});
}
exports.add = add;
async function gateway(path) {
return new Promise((resolve, reject) => {
this.axiosInstance
.get(`${this.apiUrl}/ipfs/gateway`, {
params: { path },
})
.then(resp => {
resolve(resp.data);
})
.catch(err => {
reject(utils_1.handleError(err));
});
});
}
exports.gateway = gateway;
async function pin(path) {
return new Promise((resolve, reject) => {
this.axiosInstance
.post(`${this.apiUrl}/ipfs/pin/add/${path}`)
.then(resp => {
resolve(resp.data);
})
.catch(err => {
reject(utils_1.handleError(err));
});
});
}
exports.pin = pin;
async function list(pagination) {
const paginationOptions = utils_1.getPaginationOptions(pagination);
return new Promise((resolve, reject) => {
this.axiosInstance
.get(`${this.apiUrl}/ipfs/pin/list`, {
params: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
})
.then(resp => {
resolve(resp.data);
})
.catch(err => {
reject(utils_1.handleError(err));
});
});
}
exports.list = list;
async function listByPath(path) {
return new Promise((resolve, reject) => {
this.axiosInstance
.get(`${this.apiUrl}/ipfs/pin/list/${path}`)
.then(resp => {
resolve(resp.data);
})
.catch(err => {
reject(utils_1.handleError(err));
});
});
}
exports.listByPath = listByPath;
async function pinRemove(path) {
return new Promise((resolve, reject) => {
this.axiosInstance
.post(`${this.apiUrl}/ipfs/pin/remove`, {
params: { path },
})
.then(resp => {
resolve(resp.data);
})
.catch(err => {
reject(utils_1.handleError(err));
});
});
}
exports.pinRemove = pinRemove;